Skip to content

Commit

Permalink
wip: tests with sending random data during usage
Browse files Browse the repository at this point in the history
* Related #4

[ci skip]
  • Loading branch information
tegefaulkes committed May 4, 2023
1 parent 0a2af5c commit 80180ec
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/QUICServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ class QUICServer extends EventTarget {
this.addEventListener('connection', handleEstablished);
try {
while (!established && !timedOut) {
await this.socket.send('hello!', remoteInfo.port, remoteInfo.host);
const message = new ArrayBuffer(32);
await this.crypto.ops.randomBytes(message);
await this.socket.send(Buffer.from(message), remoteInfo.port, remoteInfo.host);
sleepProm = promise<void>();
delayTimer = setTimeout(() => sleepProm!.resolveP(), delay);
delay *= 2;
Expand Down
56 changes: 55 additions & 1 deletion tests/QUICClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { promise } from '@/utils';
import * as testsUtils from './utils';
import { tlsConfigWithCaArb } from './tlsUtils';
import { sleep } from './utils';
import QUICSocket from '@/QUICSocket';

describe(QUICClient.name, () => {
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.WARN, [
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.DEBUG, [
new StreamHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
),
Expand Down Expand Up @@ -673,4 +674,57 @@ describe(QUICClient.name, () => {
{ numRuns: 1 },
);
});
describe('handles random packets', () => {
testProp(
'client handles random noise from server',
[tlsConfigWithCaArb],
async (tlsConfigProm) => {
const tlsConfig = await tlsConfigProm;
const socket = new QUICSocket({
crypto,
logger: logger.getChild('socket'),
})
await socket.start({
host: '127.0.0.1' as Host,
port: 55555 as Port,
})
const server = new QUICServer({
crypto,
logger: logger.getChild(QUICServer.name),
config: {
tlsConfig: tlsConfig.tlsConfig,
verifyPeer: false,
},
socket,
});
await server.start({
host: '127.0.0.1' as Host,
});
const client = await QUICClient.createQUICClient({
host: '::ffff:127.0.0.1' as Host,
port: server.port,
localHost: '::' as Host,
crypto,
logger: logger.getChild(QUICClient.name),
config: {
verifyPeer: false,
logKeys: "./tmp/key.log",
},
});
// Sending random data to client from the perspective of the server
const message = new ArrayBuffer(512);
const header = Buffer.from('HELLO!');
console.log('sending random data');
for (let i = 0; i < 10; i++) {
await testsUtils.randomBytes(message);
await socket.send(Buffer.concat([header, Buffer.from(message)]), client.port, '127.0.0.1');
}
console.log('done waiting');
await client.destroy({ force: true });
await server.stop();
await socket.stop();
},
{ numRuns: 1 },
);
})
});

0 comments on commit 80180ec

Please sign in to comment.