@@ -11,6 +11,7 @@ import * as tls from 'tls';
1111import * as errors from '@/errors' ;
1212import { fc } from '@fast-check/jest' ;
1313import * as tlsUtils from './tlsUtils' ;
14+ import * as certFixtures from './fixtures/certFixtures' ;
1415
1516
1617const privKeyPem = `
@@ -65,11 +66,8 @@ jti9iwz2QT6q1s+PjS/gbflIO3j4FP4XOEQGtWm9iqPbVhoUIB9PBED3
6566-----END CERTIFICATE-----
6667`
6768
68- // const tlsArb = fc.constant({
69- // certChainFromPemFile: './tmp/localhost.crt',
70- // privKeyFromPemFile: './tmp/localhost.key',
71- // });
72- const tlsArb = tlsUtils . tlsConfigArb ( tlsUtils . keyPairsArb ( 1 ) ) ;
69+ const tlsArb = fc . constant ( certFixtures . tlsConfigFileRSA1 ) ;
70+ // const tlsArb = tlsUtils.tlsConfigArb(tlsUtils.keyPairsArb(1));
7371// const tlsArb = fc.constant({
7472// certChainPem,
7573// privKeyPem,
@@ -207,8 +205,6 @@ describe(QUICClient.name, () => {
207205 await server . stop ( ) ;
208206 } ) ;
209207 } ) ;
210-
211-
212208 test ( 'times out when there is no server' , async ( ) => {
213209 // QUICClient repeatedly dials until the connection timesout
214210 await expect ( QUICClient . createQUICClient ( {
@@ -222,7 +218,85 @@ describe(QUICClient.name, () => {
222218 }
223219 } ) ) . rejects . toThrow ( errors . ErrorQUICConnectionTimeout ) ;
224220 } ) ;
225-
221+ describe ( 'TLS rotation' , ( ) => {
222+ let connectionEventP ;
223+ let resolveConnectionEventP ;
224+ let handleConnectionEventP ;
225+ beforeEach ( async ( ) => {
226+ const {
227+ p,
228+ resolveP
229+ } = utils . promise < events . QUICServerConnectionEvent > ( ) ;
230+ connectionEventP = p ;
231+ resolveConnectionEventP = resolveP ;
232+ handleConnectionEventP = ( e : events . QUICServerConnectionEvent ) => {
233+ resolveConnectionEventP ( e ) ;
234+ } ;
235+ } ) ;
236+ test . todo ( 'existing connections still function' ) ;
237+ test ( 'existing connections config is unchanged and still function' , async ( ) => {
238+ const server = new QUICServer ( {
239+ crypto,
240+ logger : logger . getChild ( QUICServer . name ) ,
241+ config : {
242+ tlsConfig : certFixtures . tlsConfigFileRSA1
243+ }
244+ } ) ;
245+ server . addEventListener ( 'connection' , handleConnectionEventP ) ;
246+ await server . start ( {
247+ host : '127.0.0.1' as Host ,
248+ } ) ;
249+ const client1 = await QUICClient . createQUICClient ( {
250+ host : '::ffff:127.0.0.1' as Host ,
251+ port : server . port ,
252+ localHost : '::' as Host ,
253+ crypto,
254+ logger : logger . getChild ( QUICClient . name ) ,
255+ } ) ;
256+ const peerCertChainInitial = client1 . connection . conn . peerCertChain ( )
257+ server . setTLSConfig ( certFixtures . tlsConfigFileRSA2 )
258+ // The existing connection's certs should be unchanged
259+ const peerCertChainNew = client1 . connection . conn . peerCertChain ( )
260+ expect ( peerCertChainNew ! [ 0 ] . toString ( ) ) . toStrictEqual ( peerCertChainInitial ! [ 0 ] . toString ( ) ) ;
261+ await client1 . destroy ( ) ;
262+ await server . stop ( ) ;
263+ } ) ;
264+ test ( 'new connections use new config' , async ( ) => {
265+ const server = new QUICServer ( {
266+ crypto,
267+ logger : logger . getChild ( QUICServer . name ) ,
268+ config : {
269+ tlsConfig : certFixtures . tlsConfigFileRSA1
270+ }
271+ } ) ;
272+ server . addEventListener ( 'connection' , handleConnectionEventP ) ;
273+ await server . start ( {
274+ host : '127.0.0.1' as Host ,
275+ } ) ;
276+ const client1 = await QUICClient . createQUICClient ( {
277+ host : '::ffff:127.0.0.1' as Host ,
278+ port : server . port ,
279+ localHost : '::' as Host ,
280+ crypto,
281+ logger : logger . getChild ( QUICClient . name ) ,
282+ } ) ;
283+ const peerCertChainInitial = client1 . connection . conn . peerCertChain ( )
284+ server . setTLSConfig ( certFixtures . tlsConfigFileRSA2 )
285+ // Starting a new connection has a different peerCertChain
286+ const client2 = await QUICClient . createQUICClient ( {
287+ host : '::ffff:127.0.0.1' as Host ,
288+ port : server . port ,
289+ localHost : '::' as Host ,
290+ crypto,
291+ logger : logger . getChild ( QUICClient . name ) ,
292+ } ) ;
293+ const peerCertChainNew = client2 . connection . conn . peerCertChain ( )
294+ expect ( peerCertChainNew ! [ 0 ] . toString ( ) ) . not . toStrictEqual ( peerCertChainInitial ! [ 0 ] . toString ( ) ) ;
295+ await client1 . destroy ( ) ;
296+ await client2 . destroy ( ) ;
297+ await server . stop ( ) ;
298+ } ) ;
299+ } )
226300
227301 // test('dual stack to dual stack', async () => {
228302
0 commit comments