From c08464bb5bf9ee464bee4da55445fcfabff2a711 Mon Sep 17 00:00:00 2001 From: Ignacio Aldama Vicente Date: Fri, 19 Jan 2024 00:23:13 +0100 Subject: [PATCH] test: add more tests --- network/agent/agent.spec.ts | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/network/agent/agent.spec.ts b/network/agent/agent.spec.ts index eda7278..4ab2e8a 100644 --- a/network/agent/agent.spec.ts +++ b/network/agent/agent.spec.ts @@ -131,3 +131,75 @@ test('should not return client certificates for a different host', () => { __type: 'https', }) }) + +test('scoped certificates override global certificates', () => { + const agent = getAgent('https://foo.com/bar', { + ca: 'global-ca', + key: 'global-key', + cert: 'global-cert', + clientCertificates: { + '//foo.com/': { + ca: 'scoped-ca', + cert: 'scoped-cert', + key: 'scoped-key', + }, + }, + }) + + expect(agent).toEqual({ + ca: 'scoped-ca', + cert: 'scoped-cert', + key: 'scoped-key', + localAddress: undefined, + maxSockets: 50, + rejectUnauthorized: undefined, + timeout: 0, + __type: 'https', + }) +}) + +test('select correct client certificates when host has a port', () => { + const agent = getAgent('https://foo.com:1234/bar', { + clientCertificates: { + '//foo.com:1234/': { + ca: 'ca', + cert: 'cert', + key: 'key', + }, + }, + }) + + expect(agent).toEqual({ + ca: 'ca', + cert: 'cert', + key: 'key', + localAddress: undefined, + maxSockets: 50, + rejectUnauthorized: undefined, + timeout: 0, + __type: 'https', + }) +}) + +test('select correct client certificates when host has a path', () => { + const agent = getAgent('https://foo.com/bar/baz', { + clientCertificates: { + '//foo.com/bar/': { + ca: 'ca', + cert: 'cert', + key: 'key', + }, + }, + }) + + expect(agent).toEqual({ + ca: 'ca', + cert: 'cert', + key: 'key', + localAddress: undefined, + maxSockets: 50, + rejectUnauthorized: undefined, + timeout: 0, + __type: 'https', + }) +}) \ No newline at end of file