Skip to content

Commit 80180ec

Browse files
committed
wip: tests with sending random data during usage
* Related #4 [ci skip]
1 parent 0a2af5c commit 80180ec

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/QUICServer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ class QUICServer extends EventTarget {
371371
this.addEventListener('connection', handleEstablished);
372372
try {
373373
while (!established && !timedOut) {
374-
await this.socket.send('hello!', remoteInfo.port, remoteInfo.host);
374+
const message = new ArrayBuffer(32);
375+
await this.crypto.ops.randomBytes(message);
376+
await this.socket.send(Buffer.from(message), remoteInfo.port, remoteInfo.host);
375377
sleepProm = promise<void>();
376378
delayTimer = setTimeout(() => sleepProm!.resolveP(), delay);
377379
delay *= 2;

tests/QUICClient.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { promise } from '@/utils';
99
import * as testsUtils from './utils';
1010
import { tlsConfigWithCaArb } from './tlsUtils';
1111
import { sleep } from './utils';
12+
import QUICSocket from '@/QUICSocket';
1213

1314
describe(QUICClient.name, () => {
14-
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.WARN, [
15+
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.DEBUG, [
1516
new StreamHandler(
1617
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
1718
),
@@ -673,4 +674,57 @@ describe(QUICClient.name, () => {
673674
{ numRuns: 1 },
674675
);
675676
});
677+
describe('handles random packets', () => {
678+
testProp(
679+
'client handles random noise from server',
680+
[tlsConfigWithCaArb],
681+
async (tlsConfigProm) => {
682+
const tlsConfig = await tlsConfigProm;
683+
const socket = new QUICSocket({
684+
crypto,
685+
logger: logger.getChild('socket'),
686+
})
687+
await socket.start({
688+
host: '127.0.0.1' as Host,
689+
port: 55555 as Port,
690+
})
691+
const server = new QUICServer({
692+
crypto,
693+
logger: logger.getChild(QUICServer.name),
694+
config: {
695+
tlsConfig: tlsConfig.tlsConfig,
696+
verifyPeer: false,
697+
},
698+
socket,
699+
});
700+
await server.start({
701+
host: '127.0.0.1' as Host,
702+
});
703+
const client = await QUICClient.createQUICClient({
704+
host: '::ffff:127.0.0.1' as Host,
705+
port: server.port,
706+
localHost: '::' as Host,
707+
crypto,
708+
logger: logger.getChild(QUICClient.name),
709+
config: {
710+
verifyPeer: false,
711+
logKeys: "./tmp/key.log",
712+
},
713+
});
714+
// Sending random data to client from the perspective of the server
715+
const message = new ArrayBuffer(512);
716+
const header = Buffer.from('HELLO!');
717+
console.log('sending random data');
718+
for (let i = 0; i < 10; i++) {
719+
await testsUtils.randomBytes(message);
720+
await socket.send(Buffer.concat([header, Buffer.from(message)]), client.port, '127.0.0.1');
721+
}
722+
console.log('done waiting');
723+
await client.destroy({ force: true });
724+
await server.stop();
725+
await socket.stop();
726+
},
727+
{ numRuns: 1 },
728+
);
729+
})
676730
});

0 commit comments

Comments
 (0)