@api-client/core 0.6.30 → 0.7.1
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/browser.d.ts +6 -14
- package/build/browser.js +11 -16
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +8 -20
- package/build/index.js +13 -25
- package/build/index.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts +2 -0
- package/build/src/amf/ApiSchemaValues.js +29 -23
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/authorization/lib/Utils.d.ts +1 -1
- package/build/src/cookies/CookieJar.d.ts +23 -0
- package/build/src/cookies/CookieJar.js +3 -0
- package/build/src/cookies/CookieJar.js.map +1 -0
- package/build/src/cookies/CookieParser.d.ts +67 -0
- package/build/src/cookies/CookieParser.js +316 -0
- package/build/src/cookies/CookieParser.js.map +1 -0
- package/build/src/cookies/InMemoryCookieJar.d.ts +12 -0
- package/build/src/cookies/InMemoryCookieJar.js +68 -0
- package/build/src/cookies/InMemoryCookieJar.js.map +1 -0
- package/build/src/cookies/Punycode.d.ts +12 -0
- package/build/src/cookies/Punycode.js +124 -0
- package/build/src/cookies/Punycode.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +8 -7
- package/build/src/data/RequestDataExtractor.js +8 -10
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/events/CustomEvent.js +5 -0
- package/build/src/events/CustomEvent.js.map +1 -1
- package/build/src/events/EventTypes.d.ts +43 -43
- package/build/src/events/amf/AmfEventTypes.d.ts +4 -4
- package/build/src/events/authorization/AuthorizationEventTypes.d.ts +4 -4
- package/build/src/events/cookies/CookieEventTypes.d.ts +9 -9
- package/build/src/events/encryption/EncryptionEventTypes.d.ts +2 -2
- package/build/src/events/environment/EnvironmentEventTypes.d.ts +1 -1
- package/build/src/events/models/ModelEventTypes.d.ts +7 -7
- package/build/src/events/process/ProcessEventTypes.d.ts +3 -3
- package/build/src/events/reporting/ReportingEventTypes.d.ts +1 -1
- package/build/src/events/telemetry/TelemetryEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEventTypes.d.ts +6 -6
- package/build/src/events/transport/TransportEvents.d.ts +2 -2
- package/build/src/mocking/ProjectMock.d.ts +3 -2
- package/build/src/mocking/ProjectMock.js +3 -3
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/App.d.ts +36 -0
- package/build/src/mocking/lib/App.js +70 -0
- package/build/src/mocking/lib/App.js.map +1 -0
- package/build/src/models/{arc/ArcProject.d.ts → AppProject.d.ts} +296 -134
- package/build/src/models/{arc/ArcProject.js → AppProject.js} +436 -79
- package/build/src/models/AppProject.js.map +1 -0
- package/build/src/models/AppRequest.d.ts +69 -0
- package/build/src/models/{arc/ArcHttpRequest.js → AppRequest.js} +53 -17
- package/build/src/models/AppRequest.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +2 -2
- package/build/src/models/Environment.d.ts +8 -1
- package/build/src/models/Environment.js +21 -0
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/HostRule.d.ts +2 -2
- package/build/src/models/HttpCookie.d.ts +63 -12
- package/build/src/models/HttpCookie.js +178 -44
- package/build/src/models/HttpCookie.js.map +1 -1
- package/build/src/models/HttpHistory.d.ts +8 -3
- package/build/src/models/HttpHistory.js +3 -3
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +34 -1
- package/build/src/models/HttpProject.js +104 -8
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -0
- package/build/src/models/ProjectFolder.js +14 -0
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +2 -0
- package/build/src/models/ProjectItem.js +20 -0
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectParent.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +3 -2
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/Property.d.ts +2 -2
- package/build/src/models/Property.js +2 -2
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Request.d.ts +16 -8
- package/build/src/models/Request.js +20 -15
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestUiMeta.d.ts +0 -14
- package/build/src/models/RequestUiMeta.js +1 -10
- package/build/src/models/RequestUiMeta.js.map +1 -1
- package/build/src/models/Server.d.ts +1 -2
- package/build/src/models/Server.js.map +1 -1
- package/build/src/models/http-actions/HttpActions.d.ts +256 -0
- package/build/src/models/http-actions/HttpActions.js +46 -0
- package/build/src/models/http-actions/HttpActions.js.map +1 -0
- package/build/src/models/http-actions/LegacyTranslator.d.ts +17 -0
- package/build/src/models/http-actions/LegacyTranslator.js +222 -0
- package/build/src/models/http-actions/LegacyTranslator.js.map +1 -0
- package/build/src/models/store/Backend.d.ts +136 -1
- package/build/src/models/store/File.d.ts +1 -1
- package/build/src/models/store/File.js +2 -0
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/User.d.ts +3 -3
- package/build/src/runtime/http-engine/CoreEngine.d.ts +2 -0
- package/build/src/runtime/http-engine/CoreEngine.js +1 -0
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.d.ts +13 -0
- package/build/src/runtime/http-engine/HttpEngine.js +39 -31
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/{actions/ConditionRunner.d.ts → http-runner/ConditionCheck.d.ts} +2 -2
- package/build/src/runtime/{actions/ConditionRunner.js → http-runner/ConditionCheck.js} +2 -2
- package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +62 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js +217 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -0
- package/build/src/runtime/{node/RequestFactory.d.ts → http-runner/HttpRequestRunner.d.ts} +40 -54
- package/build/src/runtime/http-runner/HttpRequestRunner.js +316 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.d.ts +25 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js +2 -0
- package/build/src/runtime/http-runner/HttpRuntimeEnvironment.js.map +1 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.d.ts +56 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js +143 -0
- package/build/src/runtime/http-runner/RequestAuthorizationProcessor.js.map +1 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.d.ts +24 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js +65 -0
- package/build/src/runtime/http-runner/RequestCookiesProcessor.js.map +1 -0
- package/build/src/runtime/node/InteropInterfaces.d.ts +21 -6
- package/build/src/runtime/node/ProjectParallelRunner.js +3 -1
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +24 -10
- package/build/src/runtime/node/ProjectRequestRunner.js +116 -45
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +5 -7
- package/build/src/runtime/node/ProjectRunner.js +30 -14
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js +3 -0
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/reporters/Reporter.d.ts +5 -0
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/AppSdk.d.ts +185 -0
- package/build/src/runtime/store/AppSdk.js +704 -0
- package/build/src/runtime/store/AppSdk.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.js +4 -4
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +2 -2
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +17 -2
- package/build/src/runtime/store/RouteBuilder.js +60 -3
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +5 -0
- package/build/src/runtime/store/Sdk.js +5 -0
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +1 -1
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +1 -1
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +2 -2
- package/src/amf/ApiSchemaValues.ts +41 -33
- package/src/cookies/CookieJar.ts +26 -0
- package/src/cookies/CookieParser.ts +327 -0
- package/src/cookies/InMemoryCookieJar.ts +70 -0
- package/src/cookies/Punycode.ts +133 -0
- package/src/data/RequestDataExtractor.ts +14 -15
- package/src/events/CustomEvent.ts +4 -0
- package/src/mocking/ProjectMock.ts +4 -3
- package/src/mocking/lib/App.ts +101 -0
- package/src/models/{arc/ArcProject.ts → AppProject.ts} +671 -225
- package/src/models/AppRequest.ts +176 -0
- package/src/models/ClientCertificate.ts +2 -2
- package/src/models/Environment.ts +24 -2
- package/src/models/HostRule.ts +2 -2
- package/src/models/HttpCookie.ts +210 -48
- package/src/models/HttpHistory.ts +12 -5
- package/src/models/HttpProject.ts +113 -10
- package/src/models/ProjectFolder.ts +16 -0
- package/src/models/ProjectItem.ts +18 -0
- package/src/models/ProjectParent.ts +4 -1
- package/src/models/ProjectRequest.ts +4 -3
- package/src/models/Property.ts +4 -4
- package/src/models/Request.ts +29 -19
- package/src/models/RequestAuthorization.ts +4 -4
- package/src/models/RequestUiMeta.ts +1 -21
- package/src/models/Server.ts +1 -2
- package/src/models/http-actions/HttpActions.ts +270 -0
- package/src/models/http-actions/LegacyTranslator.ts +223 -0
- package/src/models/store/Backend.ts +148 -2
- package/src/models/store/File.ts +3 -1
- package/src/models/store/User.ts +3 -3
- package/src/runtime/http-engine/CoreEngine.ts +3 -2
- package/src/runtime/http-engine/HttpEngine.ts +48 -30
- package/src/runtime/{actions/ConditionRunner.ts → http-runner/ConditionCheck.ts} +3 -3
- package/src/runtime/http-runner/HttpFlowRunner.ts +232 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +353 -0
- package/src/runtime/http-runner/HttpRuntimeEnvironment.ts +27 -0
- package/src/runtime/http-runner/RequestAuthorizationProcessor.ts +144 -0
- package/src/runtime/http-runner/RequestCookiesProcessor.ts +74 -0
- package/src/runtime/node/InteropInterfaces.ts +24 -6
- package/src/runtime/node/ProjectParallelRunner.ts +4 -2
- package/src/runtime/node/ProjectRequestRunner.ts +130 -60
- package/src/runtime/node/ProjectRunner.ts +37 -22
- package/src/runtime/node/ProjectRunnerWorker.ts +3 -0
- package/src/runtime/reporters/Reporter.ts +5 -0
- package/src/runtime/store/AppSdk.ts +709 -0
- package/src/runtime/store/FilesSdk.ts +4 -4
- package/src/runtime/store/HistorySdk.ts +2 -2
- package/src/runtime/store/RouteBuilder.ts +75 -3
- package/src/runtime/store/Sdk.ts +6 -0
- package/src/runtime/store/SharedSdk.ts +1 -1
- package/src/runtime/store/UsersSdk.ts +1 -1
- package/build/src/lib/cookies/Cookie.d.ts +0 -123
- package/build/src/lib/cookies/Cookie.js +0 -257
- package/build/src/lib/cookies/Cookie.js.map +0 -1
- package/build/src/lib/cookies/Cookies.d.ts +0 -90
- package/build/src/lib/cookies/Cookies.js +0 -310
- package/build/src/lib/cookies/Cookies.js.map +0 -1
- package/build/src/lib/cookies/Utils.d.ts +0 -47
- package/build/src/lib/cookies/Utils.js +0 -163
- package/build/src/lib/cookies/Utils.js.map +0 -1
- package/build/src/mocking/lib/Arc.d.ts +0 -10
- package/build/src/mocking/lib/Arc.js +0 -31
- package/build/src/mocking/lib/Arc.js.map +0 -1
- package/build/src/models/RequestActions.d.ts +0 -65
- package/build/src/models/RequestActions.js +0 -114
- package/build/src/models/RequestActions.js.map +0 -1
- package/build/src/models/actions/Action.d.ts +0 -75
- package/build/src/models/actions/Action.js +0 -188
- package/build/src/models/actions/Action.js.map +0 -1
- package/build/src/models/actions/ActionView.d.ts +0 -15
- package/build/src/models/actions/ActionView.js +0 -33
- package/build/src/models/actions/ActionView.js.map +0 -1
- package/build/src/models/actions/Condition.d.ts +0 -81
- package/build/src/models/actions/Condition.js +0 -185
- package/build/src/models/actions/Condition.js.map +0 -1
- package/build/src/models/actions/ConditionView.d.ts +0 -17
- package/build/src/models/actions/ConditionView.js +0 -34
- package/build/src/models/actions/ConditionView.js.map +0 -1
- package/build/src/models/actions/Enums.d.ts +0 -26
- package/build/src/models/actions/Enums.js +0 -31
- package/build/src/models/actions/Enums.js.map +0 -1
- package/build/src/models/actions/RunnableAction.d.ts +0 -59
- package/build/src/models/actions/RunnableAction.js +0 -106
- package/build/src/models/actions/RunnableAction.js.map +0 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +0 -44
- package/build/src/models/actions/runnable/DeleteCookieAction.js +0 -92
- package/build/src/models/actions/runnable/DeleteCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/Runnable.d.ts +0 -8
- package/build/src/models/actions/runnable/Runnable.js +0 -4
- package/build/src/models/actions/runnable/Runnable.js.map +0 -1
- package/build/src/models/actions/runnable/SetCookieAction.d.ts +0 -87
- package/build/src/models/actions/runnable/SetCookieAction.js +0 -176
- package/build/src/models/actions/runnable/SetCookieAction.js.map +0 -1
- package/build/src/models/actions/runnable/SetVariableAction.d.ts +0 -31
- package/build/src/models/actions/runnable/SetVariableAction.js +0 -63
- package/build/src/models/actions/runnable/SetVariableAction.js.map +0 -1
- package/build/src/models/actions/runnable/index.d.ts +0 -7
- package/build/src/models/actions/runnable/index.js +0 -2
- package/build/src/models/actions/runnable/index.js.map +0 -1
- package/build/src/models/arc/ArcHttpRequest.d.ts +0 -40
- package/build/src/models/arc/ArcHttpRequest.js.map +0 -1
- package/build/src/models/arc/ArcProject.js.map +0 -1
- package/build/src/runtime/actions/ActionRunner.d.ts +0 -17
- package/build/src/runtime/actions/ActionRunner.js +0 -74
- package/build/src/runtime/actions/ActionRunner.js.map +0 -1
- package/build/src/runtime/actions/ConditionRunner.js.map +0 -1
- package/build/src/runtime/actions/RunnableCondition.d.ts +0 -27
- package/build/src/runtime/actions/RunnableCondition.js +0 -50
- package/build/src/runtime/actions/RunnableCondition.js.map +0 -1
- package/build/src/runtime/actions/runnable/ActionRunnable.d.ts +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js +0 -13
- package/build/src/runtime/actions/runnable/ActionRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +0 -7
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js +0 -36
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js +0 -89
- package/build/src/runtime/actions/runnable/SetCookieRunnable.js.map +0 -1
- package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +0 -10
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js +0 -49
- package/build/src/runtime/actions/runnable/SetVariableRunnable.js.map +0 -1
- package/build/src/runtime/modules/BasicAuthCache.d.ts +0 -39
- package/build/src/runtime/modules/BasicAuthCache.js +0 -122
- package/build/src/runtime/modules/BasicAuthCache.js.map +0 -1
- package/build/src/runtime/modules/ExecutionResponse.d.ts +0 -4
- package/build/src/runtime/modules/ExecutionResponse.js +0 -6
- package/build/src/runtime/modules/ExecutionResponse.js.map +0 -1
- package/build/src/runtime/modules/ModulesRegistry.d.ts +0 -93
- package/build/src/runtime/modules/ModulesRegistry.js +0 -69
- package/build/src/runtime/modules/ModulesRegistry.js.map +0 -1
- package/build/src/runtime/modules/RequestAuthorization.d.ts +0 -6
- package/build/src/runtime/modules/RequestAuthorization.js +0 -110
- package/build/src/runtime/modules/RequestAuthorization.js.map +0 -1
- package/build/src/runtime/modules/RequestCookies.d.ts +0 -17
- package/build/src/runtime/modules/RequestCookies.js +0 -134
- package/build/src/runtime/modules/RequestCookies.js.map +0 -1
- package/build/src/runtime/node/RequestFactory.js +0 -406
- package/build/src/runtime/node/RequestFactory.js.map +0 -1
- package/build/src/runtime/node/VariablesStore.d.ts +0 -9
- package/build/src/runtime/node/VariablesStore.js +0 -19
- package/build/src/runtime/node/VariablesStore.js.map +0 -1
- package/src/lib/cookies/Cookie.ts +0 -312
- package/src/lib/cookies/Cookies.ts +0 -326
- package/src/lib/cookies/Utils.ts +0 -168
- package/src/mocking/lib/Arc.ts +0 -34
- package/src/models/RequestActions.ts +0 -161
- package/src/models/actions/Action.ts +0 -213
- package/src/models/actions/ActionView.ts +0 -40
- package/src/models/actions/Condition.ts +0 -207
- package/src/models/actions/ConditionView.ts +0 -42
- package/src/models/actions/Enums.ts +0 -29
- package/src/models/actions/RunnableAction.ts +0 -144
- package/src/models/actions/runnable/DeleteCookieAction.ts +0 -113
- package/src/models/actions/runnable/Runnable.ts +0 -9
- package/src/models/actions/runnable/SetCookieAction.ts +0 -216
- package/src/models/actions/runnable/SetVariableAction.ts +0 -81
- package/src/models/arc/ArcHttpRequest.ts +0 -129
- package/src/models/arc/readme.md +0 -3
- package/src/runtime/actions/ActionRunner.ts +0 -83
- package/src/runtime/actions/RunnableCondition.ts +0 -56
- package/src/runtime/actions/runnable/ActionRunnable.ts +0 -19
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +0 -39
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +0 -92
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +0 -53
- package/src/runtime/modules/BasicAuthCache.ts +0 -129
- package/src/runtime/modules/ExecutionResponse.ts +0 -4
- package/src/runtime/modules/ModulesRegistry.ts +0 -136
- package/src/runtime/modules/RequestAuthorization.ts +0 -106
- package/src/runtime/modules/RequestCookies.ts +0 -146
- package/src/runtime/node/RequestFactory.ts +0 -432
- package/src/runtime/node/VariablesStore.ts +0 -25
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { IRequest } from '../../models/Request.js';
|
|
2
|
+
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
3
|
+
import { IRequestConfig } from '../../models/RequestConfig.js';
|
|
4
|
+
import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
|
|
5
|
+
import { IRequestLog } from '../../models/RequestLog.js';
|
|
6
|
+
import { VariablesProcessor } from '../variables/VariablesProcessor.js';
|
|
7
|
+
import { IHttpActionFlow } from '../../models/http-actions/HttpActions.js';
|
|
8
|
+
import { HttpEngineOptions } from '../http-engine/HttpEngine.js';
|
|
9
|
+
import { CoreEngine } from '../http-engine/CoreEngine.js';
|
|
10
|
+
import { Logger } from '../../lib/logging/Logger.js';
|
|
11
|
+
import { CookieJar } from '../../cookies/CookieJar.js';
|
|
12
|
+
import { RequestAuthorizationProcessor } from './RequestAuthorizationProcessor.js';
|
|
13
|
+
import { RequestCookiesProcessor } from './RequestCookiesProcessor.js';
|
|
14
|
+
import { HttpFlowRunner } from './HttpFlowRunner.js';
|
|
15
|
+
import { ISentRequest } from "../../models/SentRequest.js";
|
|
16
|
+
import { IResponse } from "../../models/Response.js";
|
|
17
|
+
import { IErrorResponse } from "../../models/ErrorResponse.js";
|
|
18
|
+
import { HttpCertificate } from '../../models/ClientCertificate.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A class that takes a single HttpRequest definition and executes it.
|
|
22
|
+
*
|
|
23
|
+
* This class does the following (in order):
|
|
24
|
+
*
|
|
25
|
+
* - applies variables
|
|
26
|
+
* - applies authorization configuration
|
|
27
|
+
* - applies cookies
|
|
28
|
+
* - runs request actions
|
|
29
|
+
* - transports the request
|
|
30
|
+
* - processes response and redirect cookies
|
|
31
|
+
* - runs response actions
|
|
32
|
+
* - reports the request log
|
|
33
|
+
*/
|
|
34
|
+
export class HttpRequestRunner {
|
|
35
|
+
/**
|
|
36
|
+
* Request processing configuration.
|
|
37
|
+
*/
|
|
38
|
+
config?: IRequestConfig;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Request authorization configuration
|
|
42
|
+
*/
|
|
43
|
+
authorization?: IRequestAuthorization[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Actions to be performed when the request is executed.
|
|
47
|
+
*/
|
|
48
|
+
flows?: IHttpActionFlow[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The cumulative list of all variables to be applied to the request and other properties.
|
|
52
|
+
* The variables must be already processed for variables in values (evaluated).
|
|
53
|
+
*
|
|
54
|
+
* These variables are passed by reference. Changes made anywhere to the variables will result
|
|
55
|
+
* with updating this list.
|
|
56
|
+
*/
|
|
57
|
+
variables?: Record<string, string>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The variables processor instance.
|
|
61
|
+
*/
|
|
62
|
+
variablesProcessor = new VariablesProcessor();
|
|
63
|
+
|
|
64
|
+
logger?: Logger;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The abort signal to set on this request.
|
|
68
|
+
* Aborts the request when the signal fires.
|
|
69
|
+
* @type {(AbortSignal | undefined)}
|
|
70
|
+
*/
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* An instance of a cookie jar (store) to put/read cookies.
|
|
75
|
+
*/
|
|
76
|
+
cookies?: CookieJar;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Certificates to send with the request.
|
|
80
|
+
*/
|
|
81
|
+
certificates?: HttpCertificate[]
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates an instance from the IRequest object with setting the corresponding variables.
|
|
85
|
+
* @param request The request object to use.
|
|
86
|
+
*/
|
|
87
|
+
static fromRequest(request: IRequest): HttpRequestRunner {
|
|
88
|
+
const instance = new HttpRequestRunner();
|
|
89
|
+
instance.flows = request.flows;
|
|
90
|
+
instance.authorization = request.authorization;
|
|
91
|
+
instance.config = request.config;
|
|
92
|
+
return instance;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Runs the request and all tasks around the HTTp request execution like gathering
|
|
97
|
+
* environment information, running actions, and HTTP modules.
|
|
98
|
+
*
|
|
99
|
+
* @param request The request object to execute.
|
|
100
|
+
* @returns The execution log.
|
|
101
|
+
*/
|
|
102
|
+
async run(request: IHttpRequest): Promise<IRequestLog> {
|
|
103
|
+
const requestCopy = await this.processRequest(request);
|
|
104
|
+
const result = await this.executeRequest(requestCopy);
|
|
105
|
+
await this.processResponse(result);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @returns the configuration processed by the variables processor.
|
|
111
|
+
*/
|
|
112
|
+
async readConfig(): Promise<IRequestConfig | undefined> {
|
|
113
|
+
const { config, variables, variablesProcessor } = this;
|
|
114
|
+
if (!config) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
if (!variables) {
|
|
118
|
+
return config;
|
|
119
|
+
}
|
|
120
|
+
return variablesProcessor.evaluateVariablesWithContext(config, variables);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @returns the authorization data processed by the variables processor.
|
|
125
|
+
*/
|
|
126
|
+
async readAuthorization(): Promise<IRequestAuthorization[] | undefined> {
|
|
127
|
+
const { variables, authorization, variablesProcessor } = this;
|
|
128
|
+
if (!Array.isArray(authorization) || !authorization.length) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (!variables) {
|
|
132
|
+
return authorization;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const ps = authorization.filter(i => i.enabled !== false).map(async (item) => {
|
|
136
|
+
const copy = await variablesProcessor.evaluateVariablesWithContext(item, variables);
|
|
137
|
+
if (copy.config) {
|
|
138
|
+
copy.config = await variablesProcessor.evaluateVariablesWithContext(copy.config, variables);
|
|
139
|
+
}
|
|
140
|
+
return copy;
|
|
141
|
+
});
|
|
142
|
+
const result = await Promise.all(ps);
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Prepares the request object before making the HTTP request
|
|
148
|
+
* and runs actions and modules.
|
|
149
|
+
*
|
|
150
|
+
* @param request The request to execute.
|
|
151
|
+
* @returns the copy of the request object.
|
|
152
|
+
*/
|
|
153
|
+
async processRequest(request: IHttpRequest): Promise<IHttpRequest> {
|
|
154
|
+
let copy = await this.applyVariables(request);
|
|
155
|
+
copy = await this.applyAuthorization(copy);
|
|
156
|
+
copy = await this.applyCookies(copy);
|
|
157
|
+
await this.runRequestFlows(copy);
|
|
158
|
+
return copy;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Runs the request through the variables processor.
|
|
163
|
+
* @returns A copy of the passed request with possibly changed values.
|
|
164
|
+
*/
|
|
165
|
+
async applyVariables(request: IHttpRequest): Promise<IHttpRequest> {
|
|
166
|
+
const { variables, variablesProcessor } = this;
|
|
167
|
+
let copy: IHttpRequest = { ...request };
|
|
168
|
+
if (variables) {
|
|
169
|
+
copy = await variablesProcessor.evaluateVariablesWithContext(copy, variables);
|
|
170
|
+
}
|
|
171
|
+
return copy;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async applyAuthorization(request: IHttpRequest): Promise<IHttpRequest> {
|
|
175
|
+
const auth = await this.readAuthorization();
|
|
176
|
+
RequestAuthorizationProcessor.setAuthorization(request, auth);
|
|
177
|
+
return request;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async applyCookies(request: IHttpRequest): Promise<IHttpRequest> {
|
|
181
|
+
const { cookies } = this;
|
|
182
|
+
if (!cookies || !this.sessionCookies) {
|
|
183
|
+
return request;
|
|
184
|
+
}
|
|
185
|
+
const list = await cookies.listCookies(request.url);
|
|
186
|
+
RequestCookiesProcessor.request(request, list);
|
|
187
|
+
return request;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Executes the request actions and modules.
|
|
192
|
+
*/
|
|
193
|
+
async runRequestFlows(request: IHttpRequest): Promise<void> {
|
|
194
|
+
const flows = await this.readFlows('request');
|
|
195
|
+
const runner = new HttpFlowRunner();
|
|
196
|
+
runner.cookies = this.cookies;
|
|
197
|
+
runner.variables = this.variables;
|
|
198
|
+
await runner.request(request, flows);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Executes the request actions and modules.
|
|
203
|
+
*/
|
|
204
|
+
async runResponseFlows(request: ISentRequest, response: IResponse | IErrorResponse): Promise<void> {
|
|
205
|
+
const flows = await this.readFlows('response');
|
|
206
|
+
const runner = new HttpFlowRunner();
|
|
207
|
+
runner.cookies = this.cookies;
|
|
208
|
+
runner.variables = this.variables;
|
|
209
|
+
await runner.response(request, response, flows);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Reads and evaluates action flows.
|
|
214
|
+
*
|
|
215
|
+
* @param trigger The trigger name to read the flows for.
|
|
216
|
+
*/
|
|
217
|
+
protected async readFlows(trigger: 'request' | 'response'): Promise<IHttpActionFlow[]> {
|
|
218
|
+
const result: IHttpActionFlow[] = [];
|
|
219
|
+
const { flows, variables = {}, variablesProcessor } = this;
|
|
220
|
+
if (!Array.isArray(flows) || !flows.length) {
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
for (const flow of flows) {
|
|
224
|
+
if (flow.trigger !== trigger) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (!Array.isArray(flow.actions) || !flow.actions.length) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const copy = { ...flow } as IHttpActionFlow;
|
|
231
|
+
const actions = copy.actions.map(async (action) => {
|
|
232
|
+
const actionCopy = { ...action };
|
|
233
|
+
if (actionCopy.condition) {
|
|
234
|
+
actionCopy.condition = await variablesProcessor.evaluateVariablesWithContext(actionCopy.condition, variables);
|
|
235
|
+
}
|
|
236
|
+
if (Array.isArray(actionCopy.steps) && actionCopy.steps.length) {
|
|
237
|
+
const stepsPromises = actionCopy.steps.map((step) => variablesProcessor.evaluateVariablesWithContext(step, variables));
|
|
238
|
+
actionCopy.steps = await Promise.all(stepsPromises);
|
|
239
|
+
}
|
|
240
|
+
return actionCopy;
|
|
241
|
+
});
|
|
242
|
+
copy.actions = await Promise.all(actions);
|
|
243
|
+
result.push(copy);
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Prepares the HTTP engine configuration and executes the request,
|
|
250
|
+
* @param request The request to execute.
|
|
251
|
+
* @returns The execution log.
|
|
252
|
+
*/
|
|
253
|
+
async executeRequest(request: IHttpRequest): Promise<IRequestLog> {
|
|
254
|
+
const opts = await this.prepareEngineConfig();
|
|
255
|
+
const engine = new CoreEngine(request, opts);
|
|
256
|
+
return engine.send();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Creates a configuration options for the HTTP engine.
|
|
261
|
+
*/
|
|
262
|
+
async prepareEngineConfig(): Promise<HttpEngineOptions> {
|
|
263
|
+
const { logger, signal } = this;
|
|
264
|
+
const auth = await this.readAuthorization();
|
|
265
|
+
const config = await this.readConfig();
|
|
266
|
+
const cert = RequestAuthorizationProcessor.readCertificate(auth);
|
|
267
|
+
const opts: HttpEngineOptions = {};
|
|
268
|
+
if (cert) {
|
|
269
|
+
opts.certificates = [cert];
|
|
270
|
+
}
|
|
271
|
+
if (this.certificates) {
|
|
272
|
+
if (!opts.certificates) {
|
|
273
|
+
opts.certificates = [];
|
|
274
|
+
}
|
|
275
|
+
opts.certificates = opts.certificates.concat(this.certificates);
|
|
276
|
+
}
|
|
277
|
+
if (Array.isArray(auth)) {
|
|
278
|
+
opts.authorization = auth;
|
|
279
|
+
}
|
|
280
|
+
if (logger) {
|
|
281
|
+
opts.logger = logger;
|
|
282
|
+
}
|
|
283
|
+
if (signal) {
|
|
284
|
+
opts.signal = signal;
|
|
285
|
+
}
|
|
286
|
+
if (!config || config.enabled === false) {
|
|
287
|
+
return opts;
|
|
288
|
+
}
|
|
289
|
+
if (typeof config.timeout === 'number') {
|
|
290
|
+
opts.timeout = config.timeout;
|
|
291
|
+
}
|
|
292
|
+
if (typeof config.sentMessageLimit === 'number') {
|
|
293
|
+
opts.sentMessageLimit = config.sentMessageLimit;
|
|
294
|
+
}
|
|
295
|
+
if (typeof config.followRedirects === 'boolean') {
|
|
296
|
+
opts.followRedirects = config.followRedirects;
|
|
297
|
+
}
|
|
298
|
+
if (typeof config.defaultHeaders === 'boolean') {
|
|
299
|
+
opts.defaultHeaders = config.defaultHeaders;
|
|
300
|
+
}
|
|
301
|
+
if (typeof config.validateCertificates === 'boolean') {
|
|
302
|
+
opts.validateCertificates = config.validateCertificates;
|
|
303
|
+
}
|
|
304
|
+
if (config.defaultUserAgent) {
|
|
305
|
+
opts.defaultUserAgent = config.defaultUserAgent;
|
|
306
|
+
}
|
|
307
|
+
if (config.defaultAccept) {
|
|
308
|
+
opts.defaultAccept = config.defaultAccept;
|
|
309
|
+
}
|
|
310
|
+
if (config.proxy) {
|
|
311
|
+
opts.proxy = config.proxy;
|
|
312
|
+
}
|
|
313
|
+
if (config.proxyUsername) {
|
|
314
|
+
opts.proxyUsername = config.proxyUsername;
|
|
315
|
+
}
|
|
316
|
+
if (config.proxyPassword) {
|
|
317
|
+
opts.proxyPassword = config.proxyPassword;
|
|
318
|
+
}
|
|
319
|
+
if (Array.isArray(config.hosts) ) {
|
|
320
|
+
opts.hosts = config.hosts;
|
|
321
|
+
}
|
|
322
|
+
return opts;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async processResponse(log: IRequestLog): Promise<void> {
|
|
326
|
+
const { request, response } = log;
|
|
327
|
+
if (!request || !response) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (this.cookies && this.sessionCookies) {
|
|
331
|
+
const cookies = RequestCookiesProcessor.response(log);
|
|
332
|
+
if (cookies) {
|
|
333
|
+
const ps = Object.keys(cookies).map((url) => {
|
|
334
|
+
const items = cookies[url];
|
|
335
|
+
this.cookies?.setCookies(url, items);
|
|
336
|
+
});
|
|
337
|
+
await Promise.allSettled(ps);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
await this.runResponseFlows(request, response);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
get sessionCookies(): boolean {
|
|
344
|
+
const { config } = this;
|
|
345
|
+
if (!config) {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
if (config.enabled === false) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
return !config.ignoreSessionCookies;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CookieJar } from "../../cookies/CookieJar";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The request(s) execution environment.
|
|
5
|
+
* An environment is applied to each request in the iteration (if running a project request)
|
|
6
|
+
* or to the HTTP request (when running a single request).
|
|
7
|
+
*
|
|
8
|
+
* In the iteration mode, the environment is shared across all requests in the iteration.
|
|
9
|
+
* After that the environment is discarded and re-created for the next iteration.
|
|
10
|
+
*
|
|
11
|
+
* Cookies, depending on the implementation, most likely are shared across all iterations.
|
|
12
|
+
* This is why the implementation must to make sure it is safe to run the cookie functions
|
|
13
|
+
* in the parallel mode of a project runner.
|
|
14
|
+
*/
|
|
15
|
+
export interface IHttpRuntimeEnvironment {
|
|
16
|
+
/**
|
|
17
|
+
* The computed environment variables to use with this request or iteration.
|
|
18
|
+
* Variables can be changed but this change is not persistent. After each iteration
|
|
19
|
+
* the environment is restored it its default values.
|
|
20
|
+
*/
|
|
21
|
+
variables: Record<string, string>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An instance of a cookie jar (store) to put/read cookies.
|
|
25
|
+
*/
|
|
26
|
+
cookies: CookieJar;
|
|
27
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
2
|
+
import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
|
|
3
|
+
import { IBearerAuthorization, IBasicAuthorization, IOidcAuthorization, IOAuth2Authorization, ICCAuthorization } from '../../models/Authorization.js';
|
|
4
|
+
import { HttpCertificate } from '../../models/ClientCertificate.js';
|
|
5
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Applies authorization data to the HttpRequest from
|
|
9
|
+
* request authorization configuration.
|
|
10
|
+
*/
|
|
11
|
+
export class RequestAuthorizationProcessor {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Applies the auth data from the authorization config.
|
|
15
|
+
*
|
|
16
|
+
* Note, this mutates the original request. Make a copy of you don't want to change
|
|
17
|
+
* the values in the source request.
|
|
18
|
+
*
|
|
19
|
+
* Note, this does not process client certificates. Use the `#readCertificates()` method to
|
|
20
|
+
* get a certificate to use with the HTTP request,
|
|
21
|
+
*
|
|
22
|
+
* @param request The request to apply the authorization to.
|
|
23
|
+
* @returns The same request (a reference)
|
|
24
|
+
*/
|
|
25
|
+
static setAuthorization(request: IHttpRequest, authorization?: IRequestAuthorization[]): IHttpRequest {
|
|
26
|
+
if (!Array.isArray(authorization) || !authorization.length) {
|
|
27
|
+
return request;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const auth of authorization) {
|
|
31
|
+
if (auth.enabled === false || !auth.config) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
switch (auth.type) {
|
|
35
|
+
case 'basic': this.processBasicAuth(request, auth.config as IBasicAuthorization); break;
|
|
36
|
+
case 'oauth 2': this.processOAuth2(request, auth.config as IOAuth2Authorization); break;
|
|
37
|
+
case 'open id': this.processOpenId(request, auth.config as IOidcAuthorization); break;
|
|
38
|
+
case 'bearer': this.processBearer(request, auth.config as IBearerAuthorization); break;
|
|
39
|
+
default:
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return request;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reads the client certificate from the authorization configuration.
|
|
47
|
+
*
|
|
48
|
+
* @param authorization The HTTP request authorization configuration.
|
|
49
|
+
* @returns The certificate to use with the HTTP request or undefined when not configured.
|
|
50
|
+
*/
|
|
51
|
+
static readCertificate(authorization?: IRequestAuthorization[]): HttpCertificate | undefined {
|
|
52
|
+
if (!Array.isArray(authorization) || !authorization.length) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const item = authorization.find(i => i.enabled !== false && i.type === 'client certificate');
|
|
56
|
+
if (!item || !item.config) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const init = item.config as ICCAuthorization;
|
|
60
|
+
return init.certificate;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Injects basic auth header into the request headers.
|
|
65
|
+
*/
|
|
66
|
+
protected static processBasicAuth(request: IHttpRequest, config: IBasicAuthorization): void {
|
|
67
|
+
const { username } = config;
|
|
68
|
+
if (!username) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.applyRequestBasicAuthData(request, config);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Injects oauth 2 auth header into the request headers.
|
|
76
|
+
*/
|
|
77
|
+
protected static processOAuth2(request: IHttpRequest, config: IOAuth2Authorization): void {
|
|
78
|
+
const { accessToken, tokenType='Bearer', deliveryMethod='header', deliveryName='authorization' } = config;
|
|
79
|
+
if (!accessToken) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const value = `${tokenType} ${accessToken}`;
|
|
83
|
+
if (deliveryMethod === 'header') {
|
|
84
|
+
const headers = new Headers(request.headers || '');
|
|
85
|
+
headers.append(deliveryName, value);
|
|
86
|
+
request.headers = headers.toString();
|
|
87
|
+
} else if (deliveryMethod === 'query') {
|
|
88
|
+
const { url } = request;
|
|
89
|
+
try {
|
|
90
|
+
const parsed = new URL(url);
|
|
91
|
+
parsed.searchParams.append(deliveryName, value);
|
|
92
|
+
request.url = parsed.toString();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
// ...
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Injects OpenID Connect auth header into the request headers.
|
|
101
|
+
*/
|
|
102
|
+
protected static processOpenId(request: IHttpRequest, config: IOidcAuthorization): void {
|
|
103
|
+
const { accessToken } = config;
|
|
104
|
+
if (accessToken) {
|
|
105
|
+
this.processOAuth2(request, config);
|
|
106
|
+
}
|
|
107
|
+
// todo - if AT is missing find the current token from the tokens list in the passed configuration.
|
|
108
|
+
// Currently the authorization method UI sets the token when the requests is generated so it's not as much important.
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Injects bearer auth header into the request headers.
|
|
113
|
+
*/
|
|
114
|
+
protected static processBearer(request: IHttpRequest, config: IBearerAuthorization): void {
|
|
115
|
+
const { token } = config;
|
|
116
|
+
const value = `Bearer ${token}`;
|
|
117
|
+
const headers = new Headers(request.headers || '');
|
|
118
|
+
headers.append('authorization', value);
|
|
119
|
+
request.headers = headers.toString();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Applies the basic authorization data to the request.
|
|
124
|
+
*
|
|
125
|
+
* If the header value have changed then it fires `request-headers-changed` custom event.
|
|
126
|
+
* It sets computed value of the readers to the event's detail object.
|
|
127
|
+
*
|
|
128
|
+
* @param request The event's detail object. Changes made here will be propagated to the event.
|
|
129
|
+
* @param data The authorization data to apply.
|
|
130
|
+
*/
|
|
131
|
+
protected static applyRequestBasicAuthData(request: IHttpRequest, data: IBasicAuthorization): void {
|
|
132
|
+
const { username='', password='' } = data;
|
|
133
|
+
const headers = new Headers(request.headers || '');
|
|
134
|
+
let hash: string;
|
|
135
|
+
const decoded = `${username}:${password}`;
|
|
136
|
+
if (typeof Buffer === 'function' && typeof Buffer.from === 'function') {
|
|
137
|
+
hash = Buffer.from(decoded).toString('base64');
|
|
138
|
+
} else {
|
|
139
|
+
hash = btoa(decoded);
|
|
140
|
+
}
|
|
141
|
+
headers.set('authorization', `Basic ${hash}`);
|
|
142
|
+
request.headers = headers.toString();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IHttpCookie, HttpCookie } from "../../models/HttpCookie.js";
|
|
2
|
+
import { IHttpRequest } from "../../models/HttpRequest.js";
|
|
3
|
+
import { IRequestLog } from "../../models/RequestLog.js";
|
|
4
|
+
import { IErrorResponse } from "../../models/ErrorResponse.js";
|
|
5
|
+
import { IResponse } from "../../models/Response.js";
|
|
6
|
+
import { IResponseRedirect } from '../../models/ResponseRedirect.js';
|
|
7
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
8
|
+
import { CookieParser } from "../../cookies/CookieParser.js";
|
|
9
|
+
|
|
10
|
+
export class RequestCookiesProcessor {
|
|
11
|
+
/**
|
|
12
|
+
* Applies cookies to the request object.
|
|
13
|
+
*
|
|
14
|
+
* Note, this mutates the request object.
|
|
15
|
+
*
|
|
16
|
+
* @param request The request to which apply the cookies.
|
|
17
|
+
* @param cookies The cookies to apply
|
|
18
|
+
*/
|
|
19
|
+
static request(request: IHttpRequest, cookies?: (IHttpCookie | HttpCookie)[]): void {
|
|
20
|
+
if (!Array.isArray(cookies) || !cookies.length) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const header = cookies.map((c) => `${c.name}=${c.value}`).join('; ');
|
|
24
|
+
const headers = new Headers(request.headers);
|
|
25
|
+
headers.append('cookie', header);
|
|
26
|
+
request.headers = headers.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes a list of cookies in the response. This includes the redirect cookies and the final response.
|
|
31
|
+
*
|
|
32
|
+
* @param log The HTTP log.
|
|
33
|
+
* @returns A map where keys are the URL of the request and the values are cookies. It may be empty map when no cookies.
|
|
34
|
+
*/
|
|
35
|
+
static response(log: IRequestLog): Record<string, HttpCookie[]> | undefined {
|
|
36
|
+
if (!log.response || !log.request) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const typedError = log.response as IErrorResponse;
|
|
40
|
+
if (typedError.error) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const typedResponse = log.response as IResponse;
|
|
44
|
+
return this.extract(typedResponse, log.request.url, log.redirects);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected static extract(response: IResponse, url: string, redirects?: IResponseRedirect[]): Record<string, HttpCookie[]> {
|
|
48
|
+
const result: Record<string, HttpCookie[]> = {};
|
|
49
|
+
let redirectUrl = url;
|
|
50
|
+
if (redirects && redirects.length) {
|
|
51
|
+
for (const redirect of redirects) {
|
|
52
|
+
const headers = new Headers(redirect.response.headers);
|
|
53
|
+
const sc = headers.get('set-cookie');
|
|
54
|
+
if (sc) {
|
|
55
|
+
const cookies = CookieParser.parse(redirectUrl, sc);
|
|
56
|
+
if (cookies.length) {
|
|
57
|
+
result[redirectUrl] = cookies;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
redirectUrl = redirect.url;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const headers = new Headers(response.headers);
|
|
65
|
+
const sc = headers.get('set-cookie');
|
|
66
|
+
if (sc) {
|
|
67
|
+
const cookies = CookieParser.parse(redirectUrl, sc);
|
|
68
|
+
if (cookies.length) {
|
|
69
|
+
result[redirectUrl] = cookies;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
1
2
|
import { IProjectRequestIterator, IHttpProject } from '../../models/HttpProject.js';
|
|
2
3
|
import { Environment } from '../../models/Environment.js';
|
|
3
4
|
import { Logger } from '../../lib/logging/Logger.js';
|
|
4
5
|
import { IRequestLog } from '../../models/RequestLog.js';
|
|
6
|
+
import { CookieJar } from '../../cookies/CookieJar.js';
|
|
5
7
|
|
|
6
|
-
export interface
|
|
8
|
+
export interface IRequestRunnerOptions {
|
|
7
9
|
/**
|
|
8
10
|
* When provided it overrides any project / folder defined environment.
|
|
9
11
|
*/
|
|
@@ -20,16 +22,27 @@ export interface ProjectRunnerOptions {
|
|
|
20
22
|
*/
|
|
21
23
|
logger?: Logger;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
24
|
-
* By default it creates its own target.
|
|
25
|
+
* An instance of a cookie jar (store) to put/read cookies.
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
cookies?: CookieJar;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export interface
|
|
30
|
+
export interface IRequestRunnerRunOptions extends IProjectRequestIterator {
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export interface
|
|
33
|
+
export interface IProjectExecutionResult {
|
|
34
|
+
/**
|
|
35
|
+
* The variables evaluated during the run.
|
|
36
|
+
* These variables have values set by requests' HTTP flows.
|
|
37
|
+
*/
|
|
38
|
+
variables: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* The executed items.
|
|
41
|
+
*/
|
|
42
|
+
items: IRunResult[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IRunResult {
|
|
33
46
|
/**
|
|
34
47
|
* The key of the request from the HttpProject that was executed.
|
|
35
48
|
*/
|
|
@@ -124,4 +137,9 @@ export interface IProjectRunnerOptions {
|
|
|
124
137
|
* It aborts the execution when the ``abort` event is dispatched.
|
|
125
138
|
*/
|
|
126
139
|
signal?: AbortSignal;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* An instance of a cookie jar (store) to put/read cookies.
|
|
143
|
+
*/
|
|
144
|
+
cookies?: CookieJar;
|
|
127
145
|
}
|
|
@@ -141,7 +141,7 @@ export class ProjectParallelRunner extends BaseRunner {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
if (this.mainRejecter) {
|
|
144
|
-
this.mainRejecter
|
|
144
|
+
this.mainRejecter(new Error(`The execution has been aborted.`));
|
|
145
145
|
this.mainRejecter = undefined;
|
|
146
146
|
this.mainResolver = undefined;
|
|
147
147
|
}
|
|
@@ -172,7 +172,9 @@ export class ProjectParallelRunner extends BaseRunner {
|
|
|
172
172
|
cluster.on('exit', this._exitHandler);
|
|
173
173
|
} catch (e) {
|
|
174
174
|
const cause = e as Error;
|
|
175
|
-
this.mainRejecter
|
|
175
|
+
if (this.mainRejecter) {
|
|
176
|
+
this.mainRejecter(cause);
|
|
177
|
+
}
|
|
176
178
|
this.mainResolver = undefined
|
|
177
179
|
this.mainRejecter = undefined
|
|
178
180
|
this._state = State.Idle as State;
|