@api-client/core 0.18.12 → 0.18.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +0 -3
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +0 -3
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +2 -5
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -5
- package/build/src/index.js.map +1 -1
- package/build/src/lib/logging/DefaultLogger.d.ts +14 -0
- package/build/src/lib/logging/DefaultLogger.d.ts.map +1 -1
- package/build/src/lib/logging/DefaultLogger.js +27 -0
- package/build/src/lib/logging/DefaultLogger.js.map +1 -1
- package/build/src/lib/logging/index.d.ts +4 -0
- package/build/src/lib/logging/index.d.ts.map +1 -0
- package/build/src/lib/logging/index.js +10 -0
- package/build/src/lib/logging/index.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +1 -1
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +1 -1
- package/build/src/models/RequestConfig.js.map +1 -1
- package/build/src/models/SerializableError.d.ts +1 -1
- package/build/src/models/SerializableError.d.ts.map +1 -1
- package/build/src/models/SerializableError.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts.map +1 -1
- package/build/src/proxy/RequestProxy.js +2 -2
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.d.ts +218 -139
- package/build/src/runtime/http-engine/CoreEngine.d.ts.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.js +716 -870
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.d.ts.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.js +2 -1
- package/build/src/runtime/http-engine/PayloadSupport.js.map +1 -1
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts +73 -0
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js +186 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js.map +1 -0
- package/build/src/runtime/http-engine/auth/index.d.ts +2 -0
- package/build/src/runtime/http-engine/auth/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/index.js +2 -0
- package/build/src/runtime/http-engine/auth/index.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts +11 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js +76 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts +2 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.js +2 -0
- package/build/src/runtime/http-engine/certificates/index.js.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts +25 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js +89 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js.map +1 -0
- package/build/src/runtime/http-engine/compression/index.d.ts +2 -0
- package/build/src/runtime/http-engine/compression/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/index.js +2 -0
- package/build/src/runtime/http-engine/compression/index.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts +57 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js +78 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts +70 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js +184 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts +22 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js +105 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts +60 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js +138 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts +14 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js +47 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts +13 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js +175 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/index.d.ts +7 -0
- package/build/src/runtime/http-engine/connections/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/index.js +7 -0
- package/build/src/runtime/http-engine/connections/index.js.map +1 -0
- package/build/src/runtime/http-engine/constants.d.ts +69 -0
- package/build/src/runtime/http-engine/constants.d.ts.map +1 -0
- package/build/src/runtime/http-engine/constants.js +90 -0
- package/build/src/runtime/http-engine/constants.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts +5 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js +20 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts +2 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.js +2 -0
- package/build/src/runtime/http-engine/cookies/index.js.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts +156 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js +227 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js.map +1 -0
- package/build/src/runtime/http-engine/errors/index.d.ts +2 -0
- package/build/src/runtime/http-engine/errors/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/index.js +2 -0
- package/build/src/runtime/http-engine/errors/index.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts +66 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js +161 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts +27 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js +51 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/message/index.d.ts +3 -0
- package/build/src/runtime/http-engine/message/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/index.js +3 -0
- package/build/src/runtime/http-engine/message/index.js.map +1 -0
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts +2 -8
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js +11 -5
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js +6 -6
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js.map +1 -1
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts +39 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js +145 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts +29 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js +88 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts +91 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js +236 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts +20 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js +51 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts +5 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.js +5 -0
- package/build/src/runtime/http-engine/parsers/index.js.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts +22 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js +25 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/response/index.d.ts +2 -0
- package/build/src/runtime/http-engine/response/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/index.js +2 -0
- package/build/src/runtime/http-engine/response/index.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts +7 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js +40 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts +2 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.js +2 -0
- package/build/src/runtime/http-engine/statistics/index.js.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts +24 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js +50 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/url/index.d.ts +2 -0
- package/build/src/runtime/http-engine/url/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/index.js +2 -0
- package/build/src/runtime/http-engine/url/index.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +3 -3
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +3 -3
- package/build/src/runtime/node/InteropInterfaces.d.ts.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +2 -2
- package/build/src/runtime/node/ProjectRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRunner.js +2 -2
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/package.json +2 -2
- package/src/lib/logging/DefaultLogger.ts +32 -0
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/RequestConfig.ts +1 -1
- package/src/models/SerializableError.ts +1 -1
- package/src/proxy/RequestProxy.ts +2 -2
- package/src/runtime/http-engine/CoreEngine.ts +858 -893
- package/src/runtime/http-engine/PayloadSupport.ts +2 -1
- package/src/runtime/http-engine/auth/AuthManager.ts +242 -0
- package/src/runtime/http-engine/certificates/CertificateManager.ts +74 -0
- package/src/runtime/http-engine/compression/CompressionManager.ts +99 -0
- package/src/runtime/http-engine/connections/ConnectionManager.ts +123 -0
- package/src/runtime/http-engine/connections/DigestAuthHandler.ts +238 -0
- package/src/runtime/http-engine/connections/DirectConnection.ts +134 -0
- package/src/runtime/http-engine/connections/ProxyAuthHandler.ts +179 -0
- package/src/runtime/http-engine/connections/ProxyConnection.ts +55 -0
- package/src/runtime/http-engine/connections/TunnelConnection.ts +192 -0
- package/src/runtime/http-engine/constants.ts +103 -0
- package/src/runtime/http-engine/cookies/CookieProcessor.ts +25 -0
- package/src/runtime/http-engine/errors/HttpEngineErrors.ts +319 -0
- package/src/runtime/http-engine/message/MessageBuilder.ts +201 -0
- package/src/runtime/http-engine/message/MessageProcessor.ts +73 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +16 -13
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +6 -6
- package/src/runtime/http-engine/parsers/BodyParser.ts +171 -0
- package/src/runtime/http-engine/parsers/HeadersParser.ts +103 -0
- package/src/runtime/http-engine/parsers/HttpResponseParser.ts +280 -0
- package/src/runtime/http-engine/parsers/StatusParser.ts +69 -0
- package/src/runtime/http-engine/response/ResponseProcessor.ts +46 -0
- package/src/runtime/http-engine/statistics/StatisticsProcessor.ts +52 -0
- package/src/runtime/http-engine/url/UrlProcessor.ts +55 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +3 -3
- package/src/runtime/node/InteropInterfaces.ts +3 -3
- package/src/runtime/node/ProjectRequestRunner.ts +2 -2
- package/src/runtime/node/ProjectRunner.ts +2 -2
- package/tests/servers/ProxyServer.ts +32 -19
- package/tests/servers/express-routes/ApiEndpoint.ts +24 -0
- package/tests/servers/express-routes/BasicAuthRoute.ts +36 -0
- package/tests/servers/express-routes/BearerAuthRoute.ts +35 -0
- package/tests/servers/express-routes/NTLMRoute.ts +2 -3
- package/tests/servers/express-routes/PostApi.ts +15 -2
- package/tests/servers/express-routes/RedirectsApi.ts +12 -1
- package/tests/servers/express-routes/ResponsesApi.ts +1 -1
- package/tests/servers/express-routes/StreamApi.ts +19 -0
- package/tests/servers/oauth2mock/ServerMock.js +1 -1
- package/tests/unit/runtime/http-engine/HttpResponseParser.spec.ts +337 -0
- package/tests/unit/runtime/http-engine/abort.spec.ts +4 -5
- package/tests/unit/runtime/http-engine/auth.spec.ts +7 -58
- package/tests/unit/runtime/http-engine/certificates/CertificateManager.spec.ts +482 -0
- package/tests/unit/runtime/http-engine/certificates.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/compression/CompressionManager.spec.ts +498 -0
- package/tests/unit/runtime/http-engine/compression.spec.ts +3 -72
- package/tests/unit/runtime/http-engine/connections/ConnectionManager.spec.ts +379 -0
- package/tests/unit/runtime/http-engine/connections/DigestAuthHandler.spec.ts +164 -0
- package/tests/unit/runtime/http-engine/core_engine.spec.ts +561 -0
- package/tests/unit/runtime/http-engine/engine_statuses.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/events.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/headers.spec.ts +2 -88
- package/tests/unit/runtime/http-engine/hosts.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-get.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-post.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/logger.spec.ts +0 -8
- package/tests/unit/runtime/http-engine/message.spec.ts +2 -194
- package/tests/unit/runtime/http-engine/params.spec.ts +4 -4
- package/tests/unit/runtime/http-engine/proxy.spec.ts +15 -14
- package/tests/unit/runtime/http-engine/redirects.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/responses.spec.ts +170 -277
- package/tests/unit/runtime/http-engine/timeout.spec.ts +3 -3
- package/tests/unit/runtime/http-engine/timings.spec.ts +2 -2
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +25 -28
- package/tests/unit/runtime/runners/project_runner.spec.ts +2 -2
- package/tests/unit/runtime/runners/request_runner.spec.ts +2 -2
- package/build/src/runtime/http-engine/HttpEngine.d.ts +0 -311
- package/build/src/runtime/http-engine/HttpEngine.d.ts.map +0 -1
- package/build/src/runtime/http-engine/HttpEngine.js +0 -802
- package/build/src/runtime/http-engine/HttpEngine.js.map +0 -1
- package/src/runtime/http-engine/HttpEngine.ts +0 -952
- package/tests/unit/runtime/http-engine/connecting.spec.ts +0 -140
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import tls from 'tls'
|
|
3
|
+
import sinon from 'sinon'
|
|
4
|
+
import {
|
|
5
|
+
addClientCertificate,
|
|
6
|
+
checkServerIdentity,
|
|
7
|
+
} from '../../../../../src/runtime/http-engine/certificates/CertificateManager.js'
|
|
8
|
+
import { HttpCertificate, IPemCertificate, IP12Certificate } from '../../../../../src/models/ClientCertificate.js'
|
|
9
|
+
|
|
10
|
+
test.group('addClientCertificate()', (group) => {
|
|
11
|
+
let options: tls.ConnectionOptions
|
|
12
|
+
|
|
13
|
+
group.each.setup(() => {
|
|
14
|
+
options = {}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('returns early when certificate is null', ({ assert }) => {
|
|
18
|
+
const originalOptions = { ...options }
|
|
19
|
+
addClientCertificate(null as unknown as HttpCertificate, options)
|
|
20
|
+
assert.deepEqual(options, originalOptions, 'options should not be modified')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('returns early when certificate is undefined', ({ assert }) => {
|
|
24
|
+
const originalOptions = { ...options }
|
|
25
|
+
addClientCertificate(undefined as unknown as HttpCertificate, options)
|
|
26
|
+
assert.deepEqual(options, originalOptions, 'options should not be modified')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('adds p12 certificate to empty pfx array', ({ assert }) => {
|
|
30
|
+
const cert: IP12Certificate = {
|
|
31
|
+
kind: 'Core#Certificate',
|
|
32
|
+
key: 'test-key',
|
|
33
|
+
name: 'Test P12',
|
|
34
|
+
type: 'p12',
|
|
35
|
+
cert: {
|
|
36
|
+
data: Buffer.from('test-cert-data'),
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
addClientCertificate(cert, options)
|
|
41
|
+
|
|
42
|
+
assert.isArray(options.pfx, 'pfx should be an array')
|
|
43
|
+
assert.lengthOf(options.pfx as tls.PxfObject[], 1, 'pfx should contain one certificate')
|
|
44
|
+
|
|
45
|
+
const pfxEntry = (options.pfx as tls.PxfObject[])[0]
|
|
46
|
+
assert.deepEqual(pfxEntry.buf, Buffer.from('test-cert-data'), 'certificate data should match')
|
|
47
|
+
assert.isUndefined(pfxEntry.passphrase, 'passphrase should not be set when not provided')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('adds p12 certificate with passphrase', ({ assert }) => {
|
|
51
|
+
const cert: IP12Certificate = {
|
|
52
|
+
kind: 'Core#Certificate',
|
|
53
|
+
key: 'test-key',
|
|
54
|
+
name: 'Test P12 with passphrase',
|
|
55
|
+
type: 'p12',
|
|
56
|
+
cert: {
|
|
57
|
+
data: Buffer.from('test-cert-data'),
|
|
58
|
+
passphrase: 'secret-passphrase',
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
addClientCertificate(cert, options)
|
|
63
|
+
|
|
64
|
+
const pfxEntry = (options.pfx as tls.PxfObject[])[0]
|
|
65
|
+
assert.equal(pfxEntry.passphrase, 'secret-passphrase', 'passphrase should be set')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('converts existing pfx non-array to array and adds new certificate', ({ assert }) => {
|
|
69
|
+
const existingPfx: tls.PxfObject = {
|
|
70
|
+
buf: Buffer.from('existing-cert'),
|
|
71
|
+
}
|
|
72
|
+
options.pfx = existingPfx as unknown as (string | Buffer | tls.PxfObject)[]
|
|
73
|
+
|
|
74
|
+
const cert: IP12Certificate = {
|
|
75
|
+
kind: 'Core#Certificate',
|
|
76
|
+
key: 'test-key',
|
|
77
|
+
name: 'Test P12',
|
|
78
|
+
type: 'p12',
|
|
79
|
+
cert: {
|
|
80
|
+
data: Buffer.from('new-cert-data'),
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
addClientCertificate(cert, options)
|
|
85
|
+
|
|
86
|
+
assert.isArray(options.pfx, 'pfx should be converted to array')
|
|
87
|
+
assert.lengthOf(options.pfx as tls.PxfObject[], 2, 'pfx should contain both certificates')
|
|
88
|
+
assert.deepEqual((options.pfx as tls.PxfObject[])[0], existingPfx, 'existing certificate should be preserved')
|
|
89
|
+
assert.deepEqual(
|
|
90
|
+
(options.pfx as tls.PxfObject[])[1].buf,
|
|
91
|
+
Buffer.from('new-cert-data'),
|
|
92
|
+
'new certificate should be added'
|
|
93
|
+
)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('converts existing pfx non-array to array and adds new certificate', ({ assert }) => {
|
|
97
|
+
const existingPfx: tls.PxfObject = {
|
|
98
|
+
buf: Buffer.from('existing-cert'),
|
|
99
|
+
}
|
|
100
|
+
options.pfx = existingPfx as unknown as (string | Buffer | tls.PxfObject)[]
|
|
101
|
+
|
|
102
|
+
const cert: IP12Certificate = {
|
|
103
|
+
kind: 'Core#Certificate',
|
|
104
|
+
key: 'test-key',
|
|
105
|
+
name: 'Test P12',
|
|
106
|
+
type: 'p12',
|
|
107
|
+
cert: {
|
|
108
|
+
data: Buffer.from('new-cert-data'),
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addClientCertificate(cert, options)
|
|
113
|
+
|
|
114
|
+
assert.isArray(options.pfx, 'pfx should be converted to array')
|
|
115
|
+
assert.lengthOf(options.pfx as tls.PxfObject[], 2, 'pfx should contain both certificates')
|
|
116
|
+
assert.deepEqual((options.pfx as tls.PxfObject[])[0], existingPfx, 'existing certificate should be preserved')
|
|
117
|
+
assert.deepEqual(
|
|
118
|
+
(options.pfx as tls.PxfObject[])[1].buf,
|
|
119
|
+
Buffer.from('new-cert-data'),
|
|
120
|
+
'new certificate should be added'
|
|
121
|
+
)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('adds certificate to existing pfx array', ({ assert }) => {
|
|
125
|
+
const existingPfx: tls.PxfObject = {
|
|
126
|
+
buf: Buffer.from('existing-cert'),
|
|
127
|
+
}
|
|
128
|
+
options.pfx = [existingPfx]
|
|
129
|
+
|
|
130
|
+
const cert: IP12Certificate = {
|
|
131
|
+
kind: 'Core#Certificate',
|
|
132
|
+
key: 'test-key',
|
|
133
|
+
name: 'Test P12',
|
|
134
|
+
type: 'p12',
|
|
135
|
+
cert: {
|
|
136
|
+
data: Buffer.from('new-cert-data'),
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
addClientCertificate(cert, options)
|
|
141
|
+
|
|
142
|
+
assert.lengthOf(options.pfx as tls.PxfObject[], 2, 'pfx should contain both certificates')
|
|
143
|
+
assert.deepEqual((options.pfx as tls.PxfObject[])[0], existingPfx, 'existing certificate should be preserved')
|
|
144
|
+
assert.deepEqual(
|
|
145
|
+
(options.pfx as tls.PxfObject[])[1].buf,
|
|
146
|
+
Buffer.from('new-cert-data'),
|
|
147
|
+
'new certificate should be added'
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('handles Buffer data correctly for p12', ({ assert }) => {
|
|
152
|
+
const certData = Buffer.from('test-buffer-data')
|
|
153
|
+
const cert: IP12Certificate = {
|
|
154
|
+
kind: 'Core#Certificate',
|
|
155
|
+
key: 'test-key',
|
|
156
|
+
name: 'Test P12 Buffer',
|
|
157
|
+
type: 'p12',
|
|
158
|
+
cert: {
|
|
159
|
+
data: certData,
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
addClientCertificate(cert, options)
|
|
164
|
+
|
|
165
|
+
const pfxEntry = (options.pfx as tls.PxfObject[])[0]
|
|
166
|
+
assert.deepEqual(pfxEntry.buf, certData, 'buffer data should be preserved')
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('adds pem certificate without key to empty cert array', ({ assert }) => {
|
|
170
|
+
const cert: IPemCertificate = {
|
|
171
|
+
kind: 'Core#Certificate',
|
|
172
|
+
key: 'test-key',
|
|
173
|
+
name: 'Test PEM',
|
|
174
|
+
type: 'pem',
|
|
175
|
+
cert: {
|
|
176
|
+
data: Buffer.from('test-cert-data'),
|
|
177
|
+
},
|
|
178
|
+
certKey: {
|
|
179
|
+
data: Buffer.from('test-key-data'),
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
addClientCertificate(cert, options)
|
|
184
|
+
|
|
185
|
+
assert.isArray(options.cert, 'cert should be an array')
|
|
186
|
+
assert.lengthOf(options.cert as Buffer[], 1, 'cert should contain one certificate')
|
|
187
|
+
assert.deepEqual((options.cert as Buffer[])[0], Buffer.from('test-cert-data'), 'certificate data should match')
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
test('adds pem certificate with key', ({ assert }) => {
|
|
191
|
+
const cert: IPemCertificate = {
|
|
192
|
+
kind: 'Core#Certificate',
|
|
193
|
+
key: 'test-key',
|
|
194
|
+
name: 'Test PEM with key',
|
|
195
|
+
type: 'pem',
|
|
196
|
+
cert: {
|
|
197
|
+
data: Buffer.from('test-cert-data'),
|
|
198
|
+
},
|
|
199
|
+
certKey: {
|
|
200
|
+
data: Buffer.from('test-key-data'),
|
|
201
|
+
},
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
addClientCertificate(cert, options)
|
|
205
|
+
|
|
206
|
+
assert.isArray(options.cert, 'cert should be an array')
|
|
207
|
+
assert.isArray(options.key, 'key should be an array')
|
|
208
|
+
assert.lengthOf(options.cert as Buffer[], 1, 'cert should contain one certificate')
|
|
209
|
+
assert.lengthOf(options.key as tls.KeyObject[], 1, 'key should contain one key')
|
|
210
|
+
|
|
211
|
+
assert.deepEqual((options.cert as Buffer[])[0], Buffer.from('test-cert-data'), 'certificate data should match')
|
|
212
|
+
|
|
213
|
+
const keyEntry = (options.key as tls.KeyObject[])[0]
|
|
214
|
+
assert.deepEqual(keyEntry.pem, Buffer.from('test-key-data'), 'key data should match')
|
|
215
|
+
assert.isUndefined(keyEntry.passphrase, 'passphrase should not be set when not provided')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('adds pem certificate with key and passphrase', ({ assert }) => {
|
|
219
|
+
const cert: IPemCertificate = {
|
|
220
|
+
kind: 'Core#Certificate',
|
|
221
|
+
key: 'test-key',
|
|
222
|
+
name: 'Test PEM with key and passphrase',
|
|
223
|
+
type: 'pem',
|
|
224
|
+
cert: {
|
|
225
|
+
data: Buffer.from('test-cert-data'),
|
|
226
|
+
},
|
|
227
|
+
certKey: {
|
|
228
|
+
data: Buffer.from('test-key-data'),
|
|
229
|
+
passphrase: 'key-passphrase',
|
|
230
|
+
},
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
addClientCertificate(cert, options)
|
|
234
|
+
|
|
235
|
+
const keyEntry = (options.key as tls.KeyObject[])[0]
|
|
236
|
+
assert.equal(keyEntry.passphrase, 'key-passphrase', 'key passphrase should be set')
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('converts existing cert non-array to array and adds new certificate', ({ assert }) => {
|
|
240
|
+
const existingCert = Buffer.from('existing-cert')
|
|
241
|
+
options.cert = existingCert as string | Buffer | (string | Buffer)[]
|
|
242
|
+
|
|
243
|
+
const cert: IPemCertificate = {
|
|
244
|
+
kind: 'Core#Certificate',
|
|
245
|
+
key: 'test-key',
|
|
246
|
+
name: 'Test PEM',
|
|
247
|
+
type: 'pem',
|
|
248
|
+
cert: {
|
|
249
|
+
data: Buffer.from('new-cert-data'),
|
|
250
|
+
},
|
|
251
|
+
certKey: {
|
|
252
|
+
data: Buffer.from('new-key-data'),
|
|
253
|
+
},
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
addClientCertificate(cert, options)
|
|
257
|
+
|
|
258
|
+
assert.isArray(options.cert, 'cert should be converted to array')
|
|
259
|
+
assert.lengthOf(options.cert as Buffer[], 2, 'cert should contain both certificates')
|
|
260
|
+
assert.deepEqual((options.cert as Buffer[])[0], existingCert, 'existing certificate should be preserved')
|
|
261
|
+
assert.deepEqual((options.cert as Buffer[])[1], Buffer.from('new-cert-data'), 'new certificate should be added')
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
test('converts existing key non-array to array and adds new key', ({ assert }) => {
|
|
265
|
+
const existingKey: tls.KeyObject = {
|
|
266
|
+
pem: Buffer.from('existing-key'),
|
|
267
|
+
}
|
|
268
|
+
options.key = existingKey as unknown as (string | Buffer | tls.KeyObject)[]
|
|
269
|
+
|
|
270
|
+
const cert: IPemCertificate = {
|
|
271
|
+
kind: 'Core#Certificate',
|
|
272
|
+
key: 'test-key',
|
|
273
|
+
name: 'Test PEM',
|
|
274
|
+
type: 'pem',
|
|
275
|
+
cert: {
|
|
276
|
+
data: Buffer.from('new-cert-data'),
|
|
277
|
+
},
|
|
278
|
+
certKey: {
|
|
279
|
+
data: Buffer.from('new-key-data'),
|
|
280
|
+
},
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
addClientCertificate(cert, options)
|
|
284
|
+
|
|
285
|
+
assert.isArray(options.key, 'key should be converted to array')
|
|
286
|
+
assert.lengthOf(options.key as tls.KeyObject[], 2, 'key should contain both keys')
|
|
287
|
+
assert.deepEqual((options.key as tls.KeyObject[])[0], existingKey, 'existing key should be preserved')
|
|
288
|
+
assert.deepEqual((options.key as tls.KeyObject[])[1].pem, Buffer.from('new-key-data'), 'new key should be added')
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
test('adds certificate to existing cert array', ({ assert }) => {
|
|
292
|
+
const existingCert = Buffer.from('existing-cert')
|
|
293
|
+
options.cert = [existingCert]
|
|
294
|
+
|
|
295
|
+
const cert: IPemCertificate = {
|
|
296
|
+
kind: 'Core#Certificate',
|
|
297
|
+
key: 'test-key',
|
|
298
|
+
name: 'Test PEM',
|
|
299
|
+
type: 'pem',
|
|
300
|
+
cert: {
|
|
301
|
+
data: Buffer.from('new-cert-data'),
|
|
302
|
+
},
|
|
303
|
+
certKey: {
|
|
304
|
+
data: Buffer.from('new-key-data'),
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
addClientCertificate(cert, options)
|
|
309
|
+
|
|
310
|
+
assert.lengthOf(options.cert as Buffer[], 2, 'cert should contain both certificates')
|
|
311
|
+
assert.deepEqual((options.cert as Buffer[])[0], existingCert, 'existing certificate should be preserved')
|
|
312
|
+
assert.deepEqual((options.cert as Buffer[])[1], Buffer.from('new-cert-data'), 'new certificate should be added')
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('handles Uint8Array data correctly', ({ assert }) => {
|
|
316
|
+
const certData = new Uint8Array([1, 2, 3, 4, 5])
|
|
317
|
+
const keyData = new Uint8Array([6, 7, 8, 9, 10])
|
|
318
|
+
|
|
319
|
+
const cert: IPemCertificate = {
|
|
320
|
+
kind: 'Core#Certificate',
|
|
321
|
+
key: 'test-key',
|
|
322
|
+
name: 'Test PEM Uint8Array',
|
|
323
|
+
type: 'pem',
|
|
324
|
+
cert: {
|
|
325
|
+
data: certData,
|
|
326
|
+
},
|
|
327
|
+
certKey: {
|
|
328
|
+
data: keyData,
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
addClientCertificate(cert, options)
|
|
333
|
+
|
|
334
|
+
assert.deepEqual(
|
|
335
|
+
(options.cert as Buffer[])[0],
|
|
336
|
+
Buffer.from(certData),
|
|
337
|
+
'Uint8Array cert data should be converted to Buffer'
|
|
338
|
+
)
|
|
339
|
+
assert.deepEqual(
|
|
340
|
+
(options.key as tls.KeyObject[])[0].pem,
|
|
341
|
+
Buffer.from(keyData),
|
|
342
|
+
'Uint8Array key data should be converted to Buffer'
|
|
343
|
+
)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
test('adds pem certificate without certKey', ({ assert }) => {
|
|
347
|
+
const cert: HttpCertificate = {
|
|
348
|
+
kind: 'Core#Certificate',
|
|
349
|
+
key: 'test-key',
|
|
350
|
+
name: 'Test PEM without key',
|
|
351
|
+
type: 'pem',
|
|
352
|
+
cert: {
|
|
353
|
+
data: Buffer.from('test-cert-data'),
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
addClientCertificate(cert, options)
|
|
358
|
+
|
|
359
|
+
assert.isArray(options.cert, 'cert should be an array')
|
|
360
|
+
assert.lengthOf(options.cert as Buffer[], 1, 'cert should contain one certificate')
|
|
361
|
+
assert.isUndefined(options.key, 'key should not be set when certKey is not provided')
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
test('does not mutate original certificate object', ({ assert }) => {
|
|
365
|
+
const originalCert: IP12Certificate = {
|
|
366
|
+
kind: 'Core#Certificate',
|
|
367
|
+
key: 'test-key',
|
|
368
|
+
name: 'Test P12',
|
|
369
|
+
type: 'p12',
|
|
370
|
+
cert: {
|
|
371
|
+
data: Buffer.from('test-cert-data'),
|
|
372
|
+
passphrase: 'original-passphrase',
|
|
373
|
+
},
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const certCopy = structuredClone(originalCert)
|
|
377
|
+
addClientCertificate(originalCert, options)
|
|
378
|
+
|
|
379
|
+
assert.deepEqual(originalCert, certCopy, 'original certificate should not be mutated')
|
|
380
|
+
})
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
test.group('checkServerIdentity()', (group) => {
|
|
384
|
+
let mockCheckServerIdentity: sinon.SinonStub
|
|
385
|
+
|
|
386
|
+
group.setup(() => {
|
|
387
|
+
mockCheckServerIdentity = sinon.stub(tls, 'checkServerIdentity')
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
group.teardown(() => {
|
|
391
|
+
mockCheckServerIdentity.restore()
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
group.each.teardown(() => {
|
|
395
|
+
mockCheckServerIdentity.reset()
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
test('returns undefined when tls.checkServerIdentity returns undefined', ({ assert }) => {
|
|
399
|
+
const host = 'example.com'
|
|
400
|
+
const cert = { subject: { CN: 'example.com' } } as tls.PeerCertificate
|
|
401
|
+
|
|
402
|
+
mockCheckServerIdentity.returns(undefined)
|
|
403
|
+
|
|
404
|
+
const result = checkServerIdentity(host, cert)
|
|
405
|
+
|
|
406
|
+
assert.isUndefined(result, 'should return undefined when no error')
|
|
407
|
+
assert.isTrue(
|
|
408
|
+
mockCheckServerIdentity.calledOnceWith(host, cert),
|
|
409
|
+
'should call tls.checkServerIdentity with correct arguments'
|
|
410
|
+
)
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
test('returns error when tls.checkServerIdentity returns an error', ({ assert }) => {
|
|
414
|
+
const host = 'example.com'
|
|
415
|
+
const cert = { subject: { CN: 'different.com' } } as tls.PeerCertificate
|
|
416
|
+
const expectedError = new Error("Hostname/IP does not match certificate's altnames")
|
|
417
|
+
|
|
418
|
+
mockCheckServerIdentity.returns(expectedError)
|
|
419
|
+
|
|
420
|
+
const result = checkServerIdentity(host, cert)
|
|
421
|
+
|
|
422
|
+
assert.equal(result, expectedError, 'should return the error from tls.checkServerIdentity')
|
|
423
|
+
assert.isTrue(
|
|
424
|
+
mockCheckServerIdentity.calledOnceWith(host, cert),
|
|
425
|
+
'should call tls.checkServerIdentity with correct arguments'
|
|
426
|
+
)
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
test('passes through different error types', ({ assert }) => {
|
|
430
|
+
const host = 'example.com'
|
|
431
|
+
const cert = { subject: { CN: 'example.com' } } as tls.PeerCertificate
|
|
432
|
+
const expectedError = new TypeError('Invalid certificate format')
|
|
433
|
+
|
|
434
|
+
mockCheckServerIdentity.returns(expectedError)
|
|
435
|
+
|
|
436
|
+
const result = checkServerIdentity(host, cert)
|
|
437
|
+
|
|
438
|
+
assert.equal(result, expectedError, 'should return any error type from tls.checkServerIdentity')
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
test('handles empty host string', ({ assert }) => {
|
|
442
|
+
const host = ''
|
|
443
|
+
const cert = { subject: { CN: 'example.com' } } as tls.PeerCertificate
|
|
444
|
+
const expectedError = new Error('Invalid host')
|
|
445
|
+
|
|
446
|
+
mockCheckServerIdentity.returns(expectedError)
|
|
447
|
+
|
|
448
|
+
const result = checkServerIdentity(host, cert)
|
|
449
|
+
|
|
450
|
+
assert.equal(result, expectedError, 'should handle empty host string')
|
|
451
|
+
assert.isTrue(
|
|
452
|
+
mockCheckServerIdentity.calledOnceWith(host, cert),
|
|
453
|
+
'should call tls.checkServerIdentity with empty host'
|
|
454
|
+
)
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
test('handles null certificate', ({ assert }) => {
|
|
458
|
+
const host = 'example.com'
|
|
459
|
+
|
|
460
|
+
const result = checkServerIdentity(host, null)
|
|
461
|
+
assert.equal(result?.message, 'Certificate is required', 'should handle null certificate')
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
test('verifies function signature and call pattern', ({ assert }) => {
|
|
465
|
+
const host = 'test.example.com'
|
|
466
|
+
const cert = {
|
|
467
|
+
subject: { CN: 'test.example.com' },
|
|
468
|
+
issuer: { CN: 'Test CA' },
|
|
469
|
+
valid_from: '2024-01-01',
|
|
470
|
+
valid_to: '2025-01-01',
|
|
471
|
+
} as tls.PeerCertificate
|
|
472
|
+
|
|
473
|
+
mockCheckServerIdentity.returns(undefined)
|
|
474
|
+
|
|
475
|
+
checkServerIdentity(host, cert)
|
|
476
|
+
|
|
477
|
+
assert.isTrue(mockCheckServerIdentity.calledOnce, 'should call tls.checkServerIdentity exactly once')
|
|
478
|
+
const [calledHost, calledCert] = mockCheckServerIdentity.firstCall.args
|
|
479
|
+
assert.equal(calledHost, host, 'should pass correct host parameter')
|
|
480
|
+
assert.equal(calledCert, cert, 'should pass correct certificate parameter')
|
|
481
|
+
})
|
|
482
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
2
|
import fs from 'fs'
|
|
3
|
-
import { IResponse, Response, CoreEngine, HttpCertificate,
|
|
3
|
+
import { IResponse, Response, CoreEngine, HttpCertificate, createLogger } from '../../../../src/index.js'
|
|
4
4
|
|
|
5
|
-
const logger =
|
|
5
|
+
const logger = createLogger()
|
|
6
6
|
|
|
7
7
|
// TODO: Move to generating certs on the fly.
|
|
8
8
|
test.group('Client certificate', (group) => {
|