@api-client/core 0.18.11 → 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/modeling/DomainModel.d.ts.map +1 -1
- package/build/src/modeling/DomainModel.js +11 -4
- package/build/src/modeling/DomainModel.js.map +1 -1
- 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 +24 -24
- package/package.json +2 -2
- package/src/lib/logging/DefaultLogger.ts +32 -0
- package/src/modeling/DomainModel.ts +11 -4
- 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/modeling/domain_model_entities.spec.ts +306 -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,561 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import {
|
|
3
|
+
IResponse,
|
|
4
|
+
Response,
|
|
5
|
+
IHttpRequest,
|
|
6
|
+
RequestTime,
|
|
7
|
+
CoreEngine,
|
|
8
|
+
HttpEngineOptions,
|
|
9
|
+
Headers,
|
|
10
|
+
PayloadSerializer,
|
|
11
|
+
RequestAuthorizationKind,
|
|
12
|
+
createLogger,
|
|
13
|
+
} from '../../../../src/index.js'
|
|
14
|
+
import { HttpEngineErrorFactory } from '../../../../src/runtime/http-engine/errors/index.js'
|
|
15
|
+
import { MessageBuilder } from '../../../../src/runtime/http-engine/message/index.js'
|
|
16
|
+
import { AuthManager } from '../../../../src/runtime/http-engine/auth/index.js'
|
|
17
|
+
import { ConnectionManager } from '../../../../src/runtime/http-engine/connections/index.js'
|
|
18
|
+
|
|
19
|
+
const logger = createLogger()
|
|
20
|
+
|
|
21
|
+
test.group('CoreEngine - Message Builder Integration', () => {
|
|
22
|
+
test('builds HTTP messages correctly with MessageBuilder', async ({ assert, httpConfig }) => {
|
|
23
|
+
const request: IHttpRequest = {
|
|
24
|
+
url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: 'content-type: text/plain',
|
|
27
|
+
payload: PayloadSerializer.stringifyBuffer(Buffer.from('test data')),
|
|
28
|
+
}
|
|
29
|
+
const opts: HttpEngineOptions = {
|
|
30
|
+
timeout: 50000,
|
|
31
|
+
followRedirects: false,
|
|
32
|
+
logger,
|
|
33
|
+
}
|
|
34
|
+
const engine = new CoreEngine(request, opts)
|
|
35
|
+
const message = await engine.prepareMessage()
|
|
36
|
+
|
|
37
|
+
assert.isTrue(message instanceof Buffer)
|
|
38
|
+
const messageStr = message.toString()
|
|
39
|
+
assert.include(messageStr, 'POST /api/endpoint?query=param HTTP/1.1')
|
|
40
|
+
assert.include(messageStr, 'Host: localhost:')
|
|
41
|
+
assert.include(messageStr, 'content-type: text/plain')
|
|
42
|
+
}).tags(['@core-engine2', '@message-builder'])
|
|
43
|
+
|
|
44
|
+
test('handles proxy requests with correct status line', async ({ assert, httpConfig }) => {
|
|
45
|
+
const request: IHttpRequest = {
|
|
46
|
+
url: `http://localhost:${httpConfig.httpPort}/api/endpoint`,
|
|
47
|
+
method: 'GET',
|
|
48
|
+
}
|
|
49
|
+
const opts: HttpEngineOptions = {
|
|
50
|
+
logger,
|
|
51
|
+
proxy: `http://localhost:${httpConfig.httpPort}`,
|
|
52
|
+
}
|
|
53
|
+
const engine = new CoreEngine(request, opts)
|
|
54
|
+
const message = await engine.prepareMessage()
|
|
55
|
+
|
|
56
|
+
const messageStr = message.toString()
|
|
57
|
+
// For proxy requests, the full URL should be in the status line
|
|
58
|
+
assert.include(messageStr, `GET http://localhost:${httpConfig.httpPort}/api/endpoint HTTP/1.1`)
|
|
59
|
+
}).tags(['@core-engine2', '@message-builder', '@proxy'])
|
|
60
|
+
|
|
61
|
+
test('handles HTTPS tunnel requests correctly', async ({ assert, httpConfig }) => {
|
|
62
|
+
const request: IHttpRequest = {
|
|
63
|
+
url: `https://localhost:${httpConfig.httpsPort}/api/endpoint`,
|
|
64
|
+
method: 'GET',
|
|
65
|
+
}
|
|
66
|
+
const opts: HttpEngineOptions = {
|
|
67
|
+
logger,
|
|
68
|
+
proxy: `http://localhost:${httpConfig.httpPort}`,
|
|
69
|
+
}
|
|
70
|
+
const engine = new CoreEngine(request, opts)
|
|
71
|
+
const message = await engine.prepareMessage()
|
|
72
|
+
|
|
73
|
+
const messageStr = message.toString()
|
|
74
|
+
// For HTTPS tunnel, should use path only
|
|
75
|
+
assert.include(messageStr, 'GET /api/endpoint HTTP/1.1')
|
|
76
|
+
}).tags(['@core-engine2', '@message-builder', '@proxy', '@tunnel'])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test.group('CoreEngine - Authentication Manager Integration', () => {
|
|
80
|
+
test('handles NTLM authentication correctly', async ({ assert, httpConfig }) => {
|
|
81
|
+
const request: IHttpRequest = {
|
|
82
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/auth/ntlm/resource`,
|
|
83
|
+
method: 'GET',
|
|
84
|
+
}
|
|
85
|
+
const opts: HttpEngineOptions = {
|
|
86
|
+
logger,
|
|
87
|
+
authorization: [
|
|
88
|
+
{
|
|
89
|
+
kind: RequestAuthorizationKind,
|
|
90
|
+
enabled: true,
|
|
91
|
+
valid: true,
|
|
92
|
+
type: 'ntlm',
|
|
93
|
+
config: {
|
|
94
|
+
username: 'u1',
|
|
95
|
+
password: 'u2',
|
|
96
|
+
domain: 'custom.com',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
}
|
|
101
|
+
const engine = new CoreEngine(request, opts)
|
|
102
|
+
const log = await engine.send()
|
|
103
|
+
const response = log.response as IResponse
|
|
104
|
+
assert.equal(response.status, 200, 'has the 200 status code')
|
|
105
|
+
}).tags(['@core-engine2', '@auth-manager', '@ntlm'])
|
|
106
|
+
|
|
107
|
+
test('handles Basic authentication correctly', async ({ assert, httpConfig }) => {
|
|
108
|
+
const request: IHttpRequest = {
|
|
109
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/auth/basic/resource`,
|
|
110
|
+
method: 'GET',
|
|
111
|
+
}
|
|
112
|
+
const opts: HttpEngineOptions = {
|
|
113
|
+
logger,
|
|
114
|
+
authorization: [
|
|
115
|
+
{
|
|
116
|
+
kind: RequestAuthorizationKind,
|
|
117
|
+
enabled: true,
|
|
118
|
+
valid: true,
|
|
119
|
+
type: 'basic',
|
|
120
|
+
config: {
|
|
121
|
+
username: 'testuser',
|
|
122
|
+
password: 'testpass',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
}
|
|
127
|
+
const engine = new CoreEngine(request, opts)
|
|
128
|
+
const log = await engine.send()
|
|
129
|
+
const response = log.response as IResponse
|
|
130
|
+
assert.equal(response.status, 200, 'has the 200 status code')
|
|
131
|
+
}).tags(['@core-engine2', '@auth-manager', '@basic'])
|
|
132
|
+
|
|
133
|
+
test('handles Bearer token authentication correctly', async ({ assert, httpConfig }) => {
|
|
134
|
+
const request: IHttpRequest = {
|
|
135
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/auth/bearer/resource`,
|
|
136
|
+
method: 'GET',
|
|
137
|
+
}
|
|
138
|
+
const opts: HttpEngineOptions = {
|
|
139
|
+
logger,
|
|
140
|
+
authorization: [
|
|
141
|
+
{
|
|
142
|
+
kind: RequestAuthorizationKind,
|
|
143
|
+
enabled: true,
|
|
144
|
+
valid: true,
|
|
145
|
+
type: 'bearer',
|
|
146
|
+
config: {
|
|
147
|
+
token: 'test-token-123',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
}
|
|
152
|
+
const engine = new CoreEngine(request, opts)
|
|
153
|
+
const log = await engine.send()
|
|
154
|
+
const response = log.response as IResponse
|
|
155
|
+
assert.equal(response.status, 200, 'has the 200 status code')
|
|
156
|
+
}).tags(['@core-engine2', '@auth-manager', '@bearer'])
|
|
157
|
+
|
|
158
|
+
test('handles proxy authentication correctly', async ({ assert, httpConfig }) => {
|
|
159
|
+
const request: IHttpRequest = {
|
|
160
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/get`,
|
|
161
|
+
method: 'GET',
|
|
162
|
+
}
|
|
163
|
+
const opts: HttpEngineOptions = {
|
|
164
|
+
logger,
|
|
165
|
+
proxy: `http://localhost:${httpConfig.proxyHttpPort}`,
|
|
166
|
+
proxyUsername: 'proxyuser',
|
|
167
|
+
proxyPassword: 'proxypass',
|
|
168
|
+
}
|
|
169
|
+
const engine = new CoreEngine(request, opts)
|
|
170
|
+
const log = await engine.send()
|
|
171
|
+
const response = log.response as IResponse
|
|
172
|
+
assert.equal(response.status, 200, 'has the 200 status code')
|
|
173
|
+
}).tags(['@core-engine2', '@auth-manager', '@proxy-auth'])
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
test.group('CoreEngine - Connection Manager Integration', () => {
|
|
177
|
+
test('establishes direct HTTP connections correctly', async ({ assert, httpConfig }) => {
|
|
178
|
+
const request: IHttpRequest = {
|
|
179
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/get`,
|
|
180
|
+
method: 'GET',
|
|
181
|
+
}
|
|
182
|
+
const opts: HttpEngineOptions = {
|
|
183
|
+
logger,
|
|
184
|
+
}
|
|
185
|
+
const engine = new CoreEngine(request, opts)
|
|
186
|
+
const log = await engine.send()
|
|
187
|
+
|
|
188
|
+
assert.ok(log, 'has the response')
|
|
189
|
+
const response = new Response(log.response as IResponse)
|
|
190
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
191
|
+
}).tags(['@core-engine2', '@connection-manager', '@direct'])
|
|
192
|
+
|
|
193
|
+
test('establishes direct HTTPS connections correctly', async ({ assert, httpConfig }) => {
|
|
194
|
+
const request: IHttpRequest = {
|
|
195
|
+
url: `https://localhost:${httpConfig.httpsPort}/v1/get`,
|
|
196
|
+
method: 'GET',
|
|
197
|
+
}
|
|
198
|
+
const opts: HttpEngineOptions = {
|
|
199
|
+
logger,
|
|
200
|
+
validateCertificates: false,
|
|
201
|
+
}
|
|
202
|
+
const engine = new CoreEngine(request, opts)
|
|
203
|
+
const log = await engine.send()
|
|
204
|
+
|
|
205
|
+
assert.ok(log, 'has the response')
|
|
206
|
+
const response = new Response(log.response as IResponse)
|
|
207
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
208
|
+
}).tags(['@core-engine2', '@connection-manager', '@direct-https'])
|
|
209
|
+
|
|
210
|
+
test('establishes proxy HTTP connections correctly', async ({ assert, httpConfig }) => {
|
|
211
|
+
const request: IHttpRequest = {
|
|
212
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/get`,
|
|
213
|
+
method: 'GET',
|
|
214
|
+
}
|
|
215
|
+
const opts: HttpEngineOptions = {
|
|
216
|
+
logger,
|
|
217
|
+
proxy: `http://localhost:${httpConfig.httpPort}`,
|
|
218
|
+
}
|
|
219
|
+
const engine = new CoreEngine(request, opts)
|
|
220
|
+
const log = await engine.send()
|
|
221
|
+
|
|
222
|
+
assert.ok(log, 'has the response')
|
|
223
|
+
const response = new Response(log.response as IResponse)
|
|
224
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
225
|
+
}).tags(['@core-engine2', '@connection-manager', '@proxy'])
|
|
226
|
+
|
|
227
|
+
test('establishes HTTPS tunnel connections correctly', async ({ assert, httpConfig }) => {
|
|
228
|
+
const request: IHttpRequest = {
|
|
229
|
+
url: `https://localhost:${httpConfig.httpsPort}/v1/get`,
|
|
230
|
+
method: 'GET',
|
|
231
|
+
}
|
|
232
|
+
const opts: HttpEngineOptions = {
|
|
233
|
+
logger,
|
|
234
|
+
proxy: `http://localhost:${httpConfig.proxyHttpPort}`,
|
|
235
|
+
validateCertificates: false,
|
|
236
|
+
}
|
|
237
|
+
const engine = new CoreEngine(request, opts)
|
|
238
|
+
const log = await engine.send()
|
|
239
|
+
|
|
240
|
+
assert.ok(log, 'has the response')
|
|
241
|
+
const response = new Response(log.response as IResponse)
|
|
242
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
243
|
+
}).tags(['@core-engine2', '@connection-manager', '@tunnel'])
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test.group('CoreEngine - Error Handling Integration', () => {
|
|
247
|
+
test('handles connection timeouts with proper error types', async ({ assert, httpConfig }) => {
|
|
248
|
+
const request: IHttpRequest = {
|
|
249
|
+
url: `https://localhost:${httpConfig.httpsPort}/v1/get`,
|
|
250
|
+
method: 'GET',
|
|
251
|
+
}
|
|
252
|
+
const opts: HttpEngineOptions = {
|
|
253
|
+
logger,
|
|
254
|
+
timeout: 100, // Very short timeout
|
|
255
|
+
}
|
|
256
|
+
const engine = new CoreEngine(request, opts)
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
await engine.send()
|
|
260
|
+
assert.fail('Should have thrown a timeout error')
|
|
261
|
+
} catch (error: unknown) {
|
|
262
|
+
assert.isTrue(error instanceof Error)
|
|
263
|
+
if (error instanceof Error) {
|
|
264
|
+
assert.include(error.message, 'timeout')
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}).tags(['@core-engine2', '@error-handling', '@timeout'])
|
|
268
|
+
|
|
269
|
+
test('handles connection errors with proper error types', async ({ assert }) => {
|
|
270
|
+
const request: IHttpRequest = {
|
|
271
|
+
url: 'http://invalid-hostname-that-does-not-exist-12345.com/api',
|
|
272
|
+
method: 'GET',
|
|
273
|
+
}
|
|
274
|
+
const opts: HttpEngineOptions = {
|
|
275
|
+
logger,
|
|
276
|
+
timeout: 5000,
|
|
277
|
+
}
|
|
278
|
+
const engine = new CoreEngine(request, opts)
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
await engine.send()
|
|
282
|
+
assert.fail('Should have thrown a connection error')
|
|
283
|
+
} catch (error: unknown) {
|
|
284
|
+
assert.isTrue(error instanceof Error)
|
|
285
|
+
if (error instanceof Error) {
|
|
286
|
+
assert.include(error.message, 'connect')
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}).tags(['@core-engine2', '@error-handling', '@connection'])
|
|
290
|
+
|
|
291
|
+
test('handles unsupported payload types with proper error types', async ({ assert, httpConfig }) => {
|
|
292
|
+
const request: IHttpRequest = {
|
|
293
|
+
url: `http://localhost:${httpConfig.httpPort}/api/endpoint`,
|
|
294
|
+
method: 'POST',
|
|
295
|
+
payload: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
data: 'test',
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
const opts: HttpEngineOptions = {
|
|
301
|
+
logger,
|
|
302
|
+
}
|
|
303
|
+
const engine = new CoreEngine(request, opts)
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
await engine.prepareMessage()
|
|
307
|
+
// This should not throw since 'string' is a valid payload type
|
|
308
|
+
assert.ok(true, 'String payload type should be supported')
|
|
309
|
+
} catch (error: unknown) {
|
|
310
|
+
assert.isTrue(error instanceof Error)
|
|
311
|
+
if (error instanceof Error) {
|
|
312
|
+
assert.include(error.message, 'Unsupported payload type')
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}).tags(['@core-engine2', '@error-handling', '@payload'])
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
test.group('CoreEngine - Complete Integration Tests', () => {
|
|
319
|
+
test('performs complete HTTP request with all components', async ({ assert, httpConfig }) => {
|
|
320
|
+
const request: IHttpRequest = {
|
|
321
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/get?a=b`,
|
|
322
|
+
method: 'GET',
|
|
323
|
+
headers: 'x-custom: true',
|
|
324
|
+
}
|
|
325
|
+
const opts: HttpEngineOptions = {
|
|
326
|
+
logger,
|
|
327
|
+
timeout: 10000,
|
|
328
|
+
followRedirects: true,
|
|
329
|
+
}
|
|
330
|
+
const engine = new CoreEngine(request, opts)
|
|
331
|
+
const log = await engine.send()
|
|
332
|
+
|
|
333
|
+
assert.ok(log, 'has the response')
|
|
334
|
+
const response = new Response(log.response as IResponse)
|
|
335
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
336
|
+
assert.strictEqual(response.statusText, 'OK', 'has the response status text')
|
|
337
|
+
assert.isNotEmpty(response.headers, 'has the response headers')
|
|
338
|
+
assert.ok(response.payload, 'has the payload')
|
|
339
|
+
|
|
340
|
+
const payload = (await response.readPayload('buffer')) as Buffer
|
|
341
|
+
const bodyStr = payload.toString('utf8')
|
|
342
|
+
const body = JSON.parse(bodyStr)
|
|
343
|
+
|
|
344
|
+
assert.equal(body.headers['x-custom'], 'true', 'passes request headers')
|
|
345
|
+
assert.equal(body.method, 'GET', 'passes the method')
|
|
346
|
+
assert.deepEqual(body.query, { a: 'b' }, 'passes the query parameters')
|
|
347
|
+
|
|
348
|
+
const timings = response.timings as RequestTime
|
|
349
|
+
assert.isAtLeast(timings.connect, 0, 'has the timings.connect')
|
|
350
|
+
assert.isAtLeast(timings.receive, 0, 'has the timings.receive')
|
|
351
|
+
assert.isAtLeast(timings.send, 0, 'has the timings.send')
|
|
352
|
+
if (timings.wait !== undefined && timings.wait >= 0) {
|
|
353
|
+
assert.isAtLeast(response.loadingTime, timings.wait, 'has the timings.wait')
|
|
354
|
+
}
|
|
355
|
+
}).tags(['@core-engine2', '@integration', '@complete'])
|
|
356
|
+
|
|
357
|
+
test('performs complete HTTPS request with all components', async ({ assert, httpConfig }) => {
|
|
358
|
+
const request: IHttpRequest = {
|
|
359
|
+
url: `https://localhost:${httpConfig.httpsPort}/v1/get?a=b`,
|
|
360
|
+
method: 'GET',
|
|
361
|
+
headers: 'x-custom: true',
|
|
362
|
+
}
|
|
363
|
+
const opts: HttpEngineOptions = {
|
|
364
|
+
logger,
|
|
365
|
+
timeout: 10000,
|
|
366
|
+
followRedirects: true,
|
|
367
|
+
validateCertificates: false,
|
|
368
|
+
}
|
|
369
|
+
const engine = new CoreEngine(request, opts)
|
|
370
|
+
const log = await engine.send()
|
|
371
|
+
|
|
372
|
+
assert.ok(log, 'has the response')
|
|
373
|
+
const response = new Response(log.response as IResponse)
|
|
374
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
375
|
+
assert.strictEqual(response.statusText, 'OK', 'has the response status text')
|
|
376
|
+
assert.isNotEmpty(response.headers, 'has the response headers')
|
|
377
|
+
assert.ok(response.payload, 'has the payload')
|
|
378
|
+
|
|
379
|
+
const payload = (await response.readPayload('buffer')) as Buffer
|
|
380
|
+
const bodyStr = payload.toString('utf8')
|
|
381
|
+
const body = JSON.parse(bodyStr)
|
|
382
|
+
|
|
383
|
+
assert.equal(body.headers['x-custom'], 'true', 'passes request headers')
|
|
384
|
+
assert.equal(body.method, 'GET', 'passes the method')
|
|
385
|
+
assert.deepEqual(body.query, { a: 'b' }, 'passes the query parameters')
|
|
386
|
+
|
|
387
|
+
const timings = response.timings as RequestTime
|
|
388
|
+
assert.isAtLeast(timings.connect, 0, 'has the timings.connect')
|
|
389
|
+
assert.isAtLeast(timings.receive, 0, 'has the timings.receive')
|
|
390
|
+
assert.isAtLeast(timings.send, 0, 'has the timings.send')
|
|
391
|
+
if (timings.wait !== undefined) {
|
|
392
|
+
assert.isAtLeast(response.loadingTime, timings.wait, 'has the timings.wait')
|
|
393
|
+
}
|
|
394
|
+
assert.isAtLeast(timings.ssl!, 0, 'has the timings.ssl')
|
|
395
|
+
}).tags(['@core-engine2', '@integration', '@complete', '@https'])
|
|
396
|
+
|
|
397
|
+
test('performs POST request with payload', async ({ assert, httpConfig }) => {
|
|
398
|
+
const sentBody = JSON.stringify({ test: true, data: 'value' })
|
|
399
|
+
const request: IHttpRequest = {
|
|
400
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/post`,
|
|
401
|
+
method: 'POST',
|
|
402
|
+
headers: 'content-type: application/json\nx-custom: true',
|
|
403
|
+
payload: sentBody,
|
|
404
|
+
}
|
|
405
|
+
const opts: HttpEngineOptions = {
|
|
406
|
+
logger,
|
|
407
|
+
timeout: 10000,
|
|
408
|
+
}
|
|
409
|
+
const engine = new CoreEngine(request, opts)
|
|
410
|
+
const log = await engine.send()
|
|
411
|
+
|
|
412
|
+
assert.ok(log, 'has the response')
|
|
413
|
+
const response = new Response(log.response as IResponse)
|
|
414
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
415
|
+
assert.strictEqual(response.statusText, 'OK', 'has the response status text')
|
|
416
|
+
|
|
417
|
+
const payload = (await response.readPayload('buffer')) as Buffer
|
|
418
|
+
const bodyStr = payload.toString('utf8')
|
|
419
|
+
const body = JSON.parse(bodyStr)
|
|
420
|
+
|
|
421
|
+
assert.equal(body.method, 'POST', 'passes the method')
|
|
422
|
+
assert.equal(body.headers['content-type'], 'application/json', 'passes content-type')
|
|
423
|
+
assert.equal(body.headers['x-custom'], 'true', 'passes custom headers')
|
|
424
|
+
assert.deepEqual(body.body, { test: true, data: 'value' }, 'passes the payload')
|
|
425
|
+
}).tags(['@core-engine2', '@integration', '@post'])
|
|
426
|
+
|
|
427
|
+
test('handles redirects correctly', async ({ assert, httpConfig }) => {
|
|
428
|
+
const request: IHttpRequest = {
|
|
429
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/redirect`,
|
|
430
|
+
method: 'GET',
|
|
431
|
+
}
|
|
432
|
+
const opts: HttpEngineOptions = {
|
|
433
|
+
logger,
|
|
434
|
+
followRedirects: true,
|
|
435
|
+
}
|
|
436
|
+
const engine = new CoreEngine(request, opts)
|
|
437
|
+
const log = await engine.send()
|
|
438
|
+
|
|
439
|
+
assert.ok(log, 'has the response')
|
|
440
|
+
const response = new Response(log.response as IResponse)
|
|
441
|
+
assert.strictEqual(response.status, 200, 'has the final response status code')
|
|
442
|
+
|
|
443
|
+
// Should have redirect information
|
|
444
|
+
assert.isArray(log.redirects, 'has redirects array')
|
|
445
|
+
if (log.redirects) {
|
|
446
|
+
assert.isAbove(log.redirects.length, 0, 'has at least one redirect')
|
|
447
|
+
}
|
|
448
|
+
}).tags(['@core-engine2', '@integration', '@redirects'])
|
|
449
|
+
|
|
450
|
+
test('handles chunked responses correctly', async ({ assert, httpConfig }) => {
|
|
451
|
+
const request: IHttpRequest = {
|
|
452
|
+
url: `http://localhost:${httpConfig.httpPort}/v1/chunked`,
|
|
453
|
+
method: 'GET',
|
|
454
|
+
}
|
|
455
|
+
const opts: HttpEngineOptions = {
|
|
456
|
+
logger,
|
|
457
|
+
}
|
|
458
|
+
const engine = new CoreEngine(request, opts)
|
|
459
|
+
const log = await engine.send()
|
|
460
|
+
|
|
461
|
+
assert.ok(log, 'has the response')
|
|
462
|
+
const response = new Response(log.response as IResponse)
|
|
463
|
+
assert.strictEqual(response.status, 200, 'has the response status code')
|
|
464
|
+
assert.ok(response.payload, 'has the payload')
|
|
465
|
+
|
|
466
|
+
const payload = (await response.readPayload('buffer')) as Buffer
|
|
467
|
+
const bodyStr = payload.toString('utf8')
|
|
468
|
+
assert.isNotEmpty(bodyStr, 'has chunked response body')
|
|
469
|
+
}).tags(['@core-engine2', '@integration', '@chunked'])
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
test.group('CoreEngine - Component Isolation Tests', () => {
|
|
473
|
+
test('MessageBuilder creates correct HTTP messages', async ({ assert }) => {
|
|
474
|
+
const logger = createLogger()
|
|
475
|
+
const request: IHttpRequest = {
|
|
476
|
+
url: 'http://localhost:8080/api/endpoint?query=param',
|
|
477
|
+
method: 'POST',
|
|
478
|
+
headers: 'content-type: text/plain',
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const messageBuilder = new MessageBuilder({
|
|
482
|
+
logger,
|
|
483
|
+
request,
|
|
484
|
+
hasProxy: false,
|
|
485
|
+
isProxyTunnel: false,
|
|
486
|
+
hostHeader: 'localhost:8080',
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
const headers = new Headers('content-type: text/plain')
|
|
490
|
+
const message = messageBuilder.buildMessage(headers)
|
|
491
|
+
|
|
492
|
+
assert.isTrue(message instanceof Buffer)
|
|
493
|
+
const messageStr = message.toString()
|
|
494
|
+
assert.include(messageStr, 'POST /api/endpoint?query=param HTTP/1.1')
|
|
495
|
+
assert.include(messageStr, 'Host: localhost:8080')
|
|
496
|
+
assert.include(messageStr, 'content-type: text/plain')
|
|
497
|
+
}).tags(['@core-engine2', '@component-isolation', '@message-builder'])
|
|
498
|
+
|
|
499
|
+
test('AuthManager handles NTLM authentication', async ({ assert }) => {
|
|
500
|
+
const logger = createLogger()
|
|
501
|
+
const headers = new Headers()
|
|
502
|
+
|
|
503
|
+
const authManager = new AuthManager({
|
|
504
|
+
logger,
|
|
505
|
+
credentials: {
|
|
506
|
+
username: 'testuser',
|
|
507
|
+
password: 'testpass',
|
|
508
|
+
},
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
const authConfig = {
|
|
512
|
+
kind: RequestAuthorizationKind,
|
|
513
|
+
enabled: true,
|
|
514
|
+
type: 'ntlm',
|
|
515
|
+
config: {
|
|
516
|
+
username: 'testuser',
|
|
517
|
+
password: 'testpass',
|
|
518
|
+
domain: 'test.com',
|
|
519
|
+
},
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
authManager.handleRequestAuthorization(headers, [authConfig])
|
|
523
|
+
assert.isTrue(headers.has('Authorization'))
|
|
524
|
+
const authHeader = headers.get('Authorization')
|
|
525
|
+
assert.include(authHeader, 'NTLM ')
|
|
526
|
+
}).tags(['@core-engine2', '@component-isolation', '@auth-manager'])
|
|
527
|
+
|
|
528
|
+
test('ConnectionManager creates correct connection types', async ({ assert }) => {
|
|
529
|
+
const logger = createLogger()
|
|
530
|
+
const stats = {
|
|
531
|
+
connectionTime: 0,
|
|
532
|
+
lookupTime: 0,
|
|
533
|
+
connectedTime: 0,
|
|
534
|
+
secureStartTime: 0,
|
|
535
|
+
secureConnectedTime: 0,
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const connectionManager = new ConnectionManager(logger, stats)
|
|
539
|
+
|
|
540
|
+
assert.ok(connectionManager, 'ConnectionManager created successfully')
|
|
541
|
+
// Note: We can't actually test connection creation without a real server
|
|
542
|
+
// but we can verify the manager is properly instantiated
|
|
543
|
+
}).tags(['@core-engine2', '@component-isolation', '@connection-manager'])
|
|
544
|
+
|
|
545
|
+
test('Error system creates proper error types', async ({ assert }) => {
|
|
546
|
+
// Test connection error
|
|
547
|
+
const connectionError = HttpEngineErrorFactory.connectionError('Connection failed', 111)
|
|
548
|
+
assert.equal(connectionError.category, 'connection')
|
|
549
|
+
assert.equal(connectionError.connectionType, 'direct')
|
|
550
|
+
|
|
551
|
+
// Test authentication error
|
|
552
|
+
const authError = HttpEngineErrorFactory.authenticationError('Auth failed', 401, 'ntlm')
|
|
553
|
+
assert.equal(authError.category, 'authentication')
|
|
554
|
+
assert.equal(authError.authType, 'ntlm')
|
|
555
|
+
|
|
556
|
+
// Test timeout error
|
|
557
|
+
const timeoutError = HttpEngineErrorFactory.connectionTimeout(30000)
|
|
558
|
+
assert.equal(timeoutError.category, 'timeout')
|
|
559
|
+
assert.equal(timeoutError.timeoutType, 'connection')
|
|
560
|
+
}).tags(['@core-engine2', '@component-isolation', '@error-system'])
|
|
561
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
|
-
import { CoreEngine,
|
|
2
|
+
import { CoreEngine, createLogger } from '../../../../src/index.js'
|
|
3
3
|
|
|
4
|
-
const logger =
|
|
4
|
+
const logger = createLogger()
|
|
5
5
|
|
|
6
6
|
test.group('Status codes', () => {
|
|
7
7
|
test('results with 200', async ({ assert, httpConfig }) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
2
|
import sinon from 'sinon'
|
|
3
|
-
import {
|
|
3
|
+
import { createLogger, CoreEngine, IHttpRequest, HttpEngineOptions } from '../../../../src/index.js'
|
|
4
4
|
|
|
5
|
-
const logger =
|
|
5
|
+
const logger = createLogger()
|
|
6
6
|
|
|
7
7
|
test.group('Events', (group) => {
|
|
8
8
|
let engine: CoreEngine
|
|
@@ -1,101 +1,15 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
|
-
import sinon from 'sinon'
|
|
3
2
|
import {
|
|
4
3
|
IResponse,
|
|
5
4
|
Response,
|
|
6
|
-
|
|
5
|
+
createLogger,
|
|
7
6
|
CoreEngine,
|
|
8
7
|
IHttpRequest,
|
|
9
8
|
HttpEngineOptions,
|
|
10
9
|
Headers,
|
|
11
|
-
PayloadSerializer,
|
|
12
|
-
HeadersReceivedDetail,
|
|
13
10
|
} from '../../../../src/index.js'
|
|
14
11
|
|
|
15
|
-
const logger =
|
|
16
|
-
|
|
17
|
-
test.group('_parseHeaders()', (group) => {
|
|
18
|
-
let engine: CoreEngine
|
|
19
|
-
let headersStr: string
|
|
20
|
-
let headersBuf: Buffer
|
|
21
|
-
group.each.setup(() => {
|
|
22
|
-
const payloadBuffer = Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])
|
|
23
|
-
const request: IHttpRequest = {
|
|
24
|
-
url: `http://localhost/v1/tests`,
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers: 'content-type: text/plain',
|
|
27
|
-
payload: PayloadSerializer.stringifyBuffer(payloadBuffer),
|
|
28
|
-
}
|
|
29
|
-
const opts: HttpEngineOptions = {
|
|
30
|
-
logger,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
engine = new CoreEngine(request, opts)
|
|
34
|
-
const response = Response.fromValues(0)
|
|
35
|
-
response.loadingTime = 0
|
|
36
|
-
engine.currentResponse = response
|
|
37
|
-
headersStr = 'Content-Type: application/test\r\n'
|
|
38
|
-
headersStr += 'Content-Length: 123\r\n'
|
|
39
|
-
headersStr += 'Transfer-Encoding: chunked\r\n'
|
|
40
|
-
headersBuf = Buffer.from(headersStr)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('sets the headers property', ({ assert }) => {
|
|
44
|
-
engine._parseHeaders(headersBuf)
|
|
45
|
-
assert.typeOf(engine.currentResponse!.headers, 'string')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('contains all headers', ({ assert }) => {
|
|
49
|
-
engine._parseHeaders(headersBuf)
|
|
50
|
-
const list: Record<string, string> = {}
|
|
51
|
-
engine.currentHeaders!.forEach((value, name) => {
|
|
52
|
-
list[name] = value
|
|
53
|
-
})
|
|
54
|
-
assert.lengthOf(Object.keys(list), 3)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('sets the responseInfo.contentLength property', ({ assert }) => {
|
|
58
|
-
engine._parseHeaders(headersBuf)
|
|
59
|
-
assert.equal(engine.responseInfo!.contentLength, 123)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('sets the responseInfo.chunked property', ({ assert }) => {
|
|
63
|
-
engine._parseHeaders(headersBuf)
|
|
64
|
-
assert.isTrue(engine.responseInfo!.chunked)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('dispatches the headersreceived event', ({ assert }) => {
|
|
68
|
-
const spy = sinon.spy()
|
|
69
|
-
engine.once('headersreceived', spy)
|
|
70
|
-
engine._parseHeaders(headersBuf)
|
|
71
|
-
assert.isTrue(spy.calledOnce)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('has the returnValue on the headersreceived event', ({ assert }) => {
|
|
75
|
-
const spy = sinon.spy()
|
|
76
|
-
engine.once('headersreceived', spy)
|
|
77
|
-
engine._parseHeaders(headersBuf)
|
|
78
|
-
const info: HeadersReceivedDetail = spy.args[0][0]
|
|
79
|
-
assert.isTrue(info.returnValue)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('has the value property on the headersreceived event', ({ assert }) => {
|
|
83
|
-
const spy = sinon.spy()
|
|
84
|
-
engine.once('headersreceived', spy)
|
|
85
|
-
engine._parseHeaders(headersBuf)
|
|
86
|
-
const info: HeadersReceivedDetail = spy.args[0][0]
|
|
87
|
-
assert.ok(info.value)
|
|
88
|
-
assert.typeOf(info.value, 'string')
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('aborts the request when the event is canceled', ({ assert }) => {
|
|
92
|
-
engine.once('headersreceived', (detail) => {
|
|
93
|
-
detail.returnValue = false
|
|
94
|
-
})
|
|
95
|
-
engine._parseHeaders(headersBuf)
|
|
96
|
-
assert.isTrue(engine.aborted)
|
|
97
|
-
})
|
|
98
|
-
})
|
|
12
|
+
const logger = createLogger()
|
|
99
13
|
|
|
100
14
|
test.group('prepareHeaders()', (group) => {
|
|
101
15
|
let request: IHttpRequest
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
|
-
import {
|
|
2
|
+
import { createLogger, CoreEngine, IHttpRequest, HttpEngineOptions, HostRuleKind } from '../../../../src/index.js'
|
|
3
3
|
|
|
4
|
-
const logger =
|
|
4
|
+
const logger = createLogger()
|
|
5
5
|
|
|
6
6
|
test.group('Hosts evaluation', () => {
|
|
7
7
|
test('alters the uri', ({ assert }) => {
|