Skip to content

Commit

Permalink
fix: made setTls more generic, updateConfig can modify all config…
Browse files Browse the repository at this point in the history
… options

* Fixes #3

[ci skip]
  • Loading branch information
tegefaulkes committed Apr 19, 2023
1 parent bd31172 commit 2a583fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/QUICServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,15 @@ class QUICServer extends EventTarget {
}

/**
* This updates the `tlsConfig` used when new connections are established.
* It will not affect existing connections, they will keep using the old `tlsconfig`
* @param tlsConfig
* This updates the `QUICConfig` used when new connections are established.
* Only the parameters that are provided are updated.
* It will not affect existing connections, they will keep using the old `QUICConfig`
*/
public setTLSConfig(tlsConfig: TlsConfig): void {
// tlsConfig is an object, spread to copy and avoid object mutation
this.config.tlsConfig = { ...tlsConfig };
public updateConfig(config: Partial<QUICConfig>): void {
this.config = {
...this.config,
...config,
};
};

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/QUICClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ describe(QUICClient.name, () => {
logger: logger.getChild(QUICClient.name),
});
const peerCertChainInitial = client1.connection.conn.peerCertChain()
server.setTLSConfig(certFixtures.tlsConfigFileRSA2)
server.updateConfig({
tlsConfig: certFixtures.tlsConfigFileRSA2
})
// The existing connection's certs should be unchanged
const peerCertChainNew = client1.connection.conn.peerCertChain()
expect(peerCertChainNew![0].toString()).toStrictEqual(peerCertChainInitial![0].toString());
Expand All @@ -281,7 +283,9 @@ describe(QUICClient.name, () => {
logger: logger.getChild(QUICClient.name),
});
const peerCertChainInitial = client1.connection.conn.peerCertChain()
server.setTLSConfig(certFixtures.tlsConfigFileRSA2)
server.updateConfig({
tlsConfig: certFixtures.tlsConfigFileRSA2
})
// Starting a new connection has a different peerCertChain
const client2 = await QUICClient.createQUICClient({
host: '::ffff:127.0.0.1' as Host,
Expand Down

0 comments on commit 2a583fb

Please sign in to comment.