Skip to content

Commit 85b0375

Browse files
committed
tests: fixing up tests to match changes
- fixed up `QUICServer.test.ts` - fixed up `QUICSocket.test.ts` - fixed up `concurrency.test.ts` [ci skip]
1 parent 968ae89 commit 85b0375

File tree

3 files changed

+215
-181
lines changed

3 files changed

+215
-181
lines changed

tests/QUICServer.test.ts

+144-110
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { X509Certificate } from '@peculiar/x509';
2-
import type { QUICConfig, Crypto, Host, Hostname, Port } from '@/types';
2+
import type {
3+
QUICConfig,
4+
Host,
5+
Hostname,
6+
Port,
7+
ClientCrypto,
8+
ServerCrypto,
9+
} from '@/types';
310
import dgram from 'dgram';
411
import Logger, { LogLevel, StreamHandler, formatting } from '@matrixai/logger';
512
import QUICServer from '@/QUICServer';
@@ -77,24 +84,26 @@ describe(QUICServer.name, () => {
7784
certEd25519PEM = testsUtils.certToPEM(certEd25519);
7885
});
7986
// This has to be setup asynchronously due to key generation
80-
let crypto: {
81-
key: ArrayBuffer;
82-
ops: Crypto;
83-
};
87+
let clientCrypto: ClientCrypto;
88+
let serverCrypto: ServerCrypto;
89+
let key: ArrayBuffer;
8490
beforeEach(async () => {
85-
crypto = {
86-
key: await testsUtils.generateKeyHMAC(),
87-
ops: {
88-
sign: testsUtils.signHMAC,
89-
verify: testsUtils.verifyHMAC,
90-
randomBytes: testsUtils.randomBytes,
91-
},
91+
key = await testsUtils.generateKeyHMAC();
92+
clientCrypto = {
93+
randomBytes: testsUtils.randomBytes,
94+
};
95+
serverCrypto = {
96+
sign: testsUtils.signHMAC,
97+
verify: testsUtils.verifyHMAC,
9298
};
9399
});
94100
describe('start and stop', () => {
95101
test('with RSA', async () => {
96102
const quicServer = new QUICServer({
97-
crypto,
103+
crypto: {
104+
key,
105+
ops: serverCrypto,
106+
},
98107
config: {
99108
key: keyPairRSAPEM.privateKey,
100109
cert: certRSAPEM,
@@ -109,7 +118,10 @@ describe(QUICServer.name, () => {
109118
});
110119
test('with ECDSA', async () => {
111120
const quicServer = new QUICServer({
112-
crypto,
121+
crypto: {
122+
key,
123+
ops: serverCrypto,
124+
},
113125
config: {
114126
key: keyPairECDSAPEM.privateKey,
115127
cert: certECDSAPEM,
@@ -124,7 +136,10 @@ describe(QUICServer.name, () => {
124136
});
125137
test('with Ed25519', async () => {
126138
const quicServer = new QUICServer({
127-
crypto,
139+
crypto: {
140+
key,
141+
ops: serverCrypto,
142+
},
128143
config: {
129144
key: keyPairEd25519PEM.privateKey,
130145
cert: certEd25519PEM,
@@ -141,7 +156,10 @@ describe(QUICServer.name, () => {
141156
describe('binding to host and port', () => {
142157
test('listen on IPv4', async () => {
143158
const quicServer = new QUICServer({
144-
crypto,
159+
crypto: {
160+
key,
161+
ops: serverCrypto,
162+
},
145163
config: {
146164
key: keyPairEd25519PEM.privateKey,
147165
cert: certEd25519PEM,
@@ -157,7 +175,10 @@ describe(QUICServer.name, () => {
157175
});
158176
test('listen on IPv6', async () => {
159177
const quicServer = new QUICServer({
160-
crypto,
178+
crypto: {
179+
key,
180+
ops: serverCrypto,
181+
},
161182
config: {
162183
key: keyPairEd25519PEM.privateKey,
163184
cert: certEd25519PEM,
@@ -173,7 +194,10 @@ describe(QUICServer.name, () => {
173194
});
174195
test('listen on dual stack', async () => {
175196
const quicServer = new QUICServer({
176-
crypto,
197+
crypto: {
198+
key,
199+
ops: serverCrypto,
200+
},
177201
config: {
178202
key: keyPairEd25519PEM.privateKey,
179203
cert: certEd25519PEM,
@@ -191,7 +215,10 @@ describe(QUICServer.name, () => {
191215
// NOT RECOMMENDED, because send addresses will have to be mapped
192216
// addresses, which means you can ONLY connect to mapped addresses
193217
const quicServer = new QUICServer({
194-
crypto,
218+
crypto: {
219+
key,
220+
ops: serverCrypto,
221+
},
195222
config: {
196223
key: keyPairEd25519PEM.privateKey,
197224
cert: certEd25519PEM,
@@ -214,7 +241,10 @@ describe(QUICServer.name, () => {
214241
});
215242
test('listen on hostname', async () => {
216243
const quicServer = new QUICServer({
217-
crypto,
244+
crypto: {
245+
key,
246+
ops: serverCrypto,
247+
},
218248
config: {
219249
key: keyPairEd25519PEM.privateKey,
220250
cert: certEd25519PEM,
@@ -232,7 +262,10 @@ describe(QUICServer.name, () => {
232262
});
233263
test('listen on hostname and custom resolver', async () => {
234264
const quicServer = new QUICServer({
235-
crypto,
265+
crypto: {
266+
key,
267+
ops: serverCrypto,
268+
},
236269
config: {
237270
key: keyPairEd25519PEM.privateKey,
238271
cert: certEd25519PEM,
@@ -248,83 +281,84 @@ describe(QUICServer.name, () => {
248281
await quicServer.stop();
249282
});
250283
});
251-
describe.only('connection bootstrap', () => {
252-
// Test without peer verification
253-
test.only('', async () => {
254-
const quicServer = new QUICServer({
255-
crypto,
256-
config: {
257-
// Key: keyPairRSAPEM.privateKey,
258-
// cert: certRSAPEM,
259-
key: keyPairECDSAPEM.privateKey,
260-
cert: certECDSAPEM,
261-
verifyPeer: false,
262-
},
263-
logger: logger.getChild('QUICServer'),
264-
});
265-
await quicServer.start({
266-
host: '127.0.0.1' as Host,
267-
});
268-
269-
const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
270-
await crypto.ops.randomBytes(scidBuffer);
271-
const scid = new QUICConnectionId(scidBuffer);
272-
273-
// Verify peer
274-
// Note that you cannot send to IPv4 from dual stack socket
275-
// It must be sent as IPv4 mapped IPv6
276-
277-
const socket = new QUICSocket({
278-
crypto,
279-
logger: logger.getChild(QUICSocket.name),
280-
});
281-
await socket.start({
282-
host: '127.0.0.1' as Host,
283-
});
284-
285-
// ???
286-
const clientConfig: QUICConfig = {
287-
...clientDefault,
288-
verifyPeer: false,
289-
};
290-
291-
// This creates a connection state
292-
// We now need to trigger it
293-
const connection = await QUICConnection.connectQUICConnection({
294-
scid,
295-
socket,
296-
remoteInfo: {
297-
host: quicServer.host,
298-
port: quicServer.port,
299-
},
300-
config: clientConfig,
301-
logger: logger.getChild(QUICConnection.name),
302-
});
303-
304-
connection.addEventListener('error', (e) => {
305-
console.log('error', e);
306-
});
307-
308-
// Trigger the connection
309-
await connection.send();
310-
311-
// Wait till it is established
312-
console.log('BEFORE ESTABLISHED P');
313-
await connection.establishedP;
314-
console.log('AFTER ESTABLISHED P');
315-
316-
// You must destroy the connection
317-
console.log('DESTROY CONNECTION');
318-
await connection.destroy();
319-
console.log('DESTROYED CONNECTION');
320-
321-
console.log('STOP SOCKET');
322-
await socket.stop();
323-
console.time('STOPPED SOCKET');
324-
await quicServer.stop();
325-
console.timeEnd('STOPPED SOCKET');
326-
});
327-
});
284+
// Describe.only('connection bootstrap', () => {
285+
// // Test without peer verification
286+
// test.only('', async () => {
287+
// const quicServer = new QUICServer({
288+
// crypto: {
289+
// key,
290+
// ops: serverCrypto,
291+
// },
292+
// config: {
293+
// key: keyPairECDSAPEM.privateKey,
294+
// cert: certECDSAPEM,
295+
// verifyPeer: false,
296+
// },
297+
// logger: logger.getChild('QUICServer'),
298+
// });
299+
// await quicServer.start({
300+
// host: '127.0.0.1' as Host,
301+
// });
302+
//
303+
// const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
304+
// await clientCrypto.randomBytes(scidBuffer);
305+
// const scid = new QUICConnectionId(scidBuffer);
306+
//
307+
// // Verify peer
308+
// // Note that you cannot send to IPv4 from dual stack socket
309+
// // It must be sent as IPv4 mapped IPv6
310+
//
311+
// const socket = new QUICSocket({
312+
// logger: logger.getChild(QUICSocket.name),
313+
// });
314+
// await socket.start({
315+
// host: '127.0.0.1' as Host,
316+
// });
317+
//
318+
// // ???
319+
// const clientConfig: QUICConfig = {
320+
// ...clientDefault,
321+
// verifyPeer: false,
322+
// };
323+
//
324+
// // This creates a connection state
325+
// // We now need to trigger it
326+
// const connection = await QUICConnection.createQUICConnection({
327+
// type: 'client',
328+
// scid,
329+
// socket,
330+
// remoteInfo: {
331+
// host: quicServer.host,
332+
// port: quicServer.port,
333+
// },
334+
// config: clientConfig,
335+
// logger: logger.getChild(QUICConnection.name),
336+
// });
337+
//
338+
// connection.addEventListener('error', (e) => {
339+
// console.log('error', e);
340+
// });
341+
//
342+
// // Trigger the connection
343+
// await connection.send();
344+
//
345+
// // Wait till it is established
346+
// console.log('BEFORE ESTABLISHED P');
347+
// await connection.establishedP;
348+
// console.log('AFTER ESTABLISHED P');
349+
//
350+
// // You must destroy the connection
351+
// console.log('DESTROY CONNECTION');
352+
// await connection.stop();
353+
// console.log('DESTROYED CONNECTION');
354+
//
355+
// console.log('STOP SOCKET');
356+
// await socket.stop();
357+
// console.time('STOPPED SOCKET');
358+
// await quicServer.stop();
359+
// console.timeEnd('STOPPED SOCKET');
360+
// });
361+
// });
328362
// Test('bootstrapping a new connection', async () => {
329363
// const quicServer = new QUICServer({
330364
// crypto,
@@ -335,50 +369,50 @@ describe(QUICServer.name, () => {
335369
// logger: logger.getChild('QUICServer'),
336370
// });
337371
// await quicServer.start();
338-
372+
//
339373
// const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
340374
// await crypto.ops.randomBytes(scidBuffer);
341375
// const scid = new QUICConnectionId(scidBuffer);
342-
376+
//
343377
// const socket = new QUICSocket({
344378
// crypto,
345379
// resolveHostname: utils.resolveHostname,
346380
// logger: logger.getChild(QUICSocket.name),
347381
// });
348382
// await socket.start();
349-
383+
//
350384
// // Const config = buildQuicheConfig({
351385
// // ...clientDefault
352386
// // });
353387
// // Here we want to VERIFY the peer
354388
// // If we use the same certificate
355389
// // then it should be consider as if it is trusted!
356-
390+
//
357391
// const quicConfig: QUICConfig = {
358392
// ...clientDefault,
359393
// verifyPeer: true,
360394
// };
361-
395+
//
362396
// const connection = await QUICConnection.connectQUICConnection({
363397
// scid,
364398
// socket,
365-
399+
//
366400
// remoteInfo: {
367401
// host: utils.resolvesZeroIP(quicServer.host),
368402
// port: quicServer.port,
369403
// },
370-
404+
//
371405
// config: quicConfig,
372406
// });
373-
407+
//
374408
// await socket.stop();
375409
// await quicServer.stop();
376-
410+
//
377411
// // We can run with several rsa keypairs and certificates
378412
// });
379-
describe('updating configuration', () => {
380-
// We want to test changing the configuration over time
381-
});
413+
// describe('updating configuration', () => {
414+
// // We want to test changing the configuration over time
415+
// });
382416
// Test hole punching, there's an initiation function
383417
// We can make it start doing this, but technically it's the socket's duty to do this
384418
// not just the server side

0 commit comments

Comments
 (0)