@api-client/core 0.9.4 → 0.9.6
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 +14 -3
- package/build/browser.js +16 -2
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +15 -4
- package/build/index.js +17 -3
- package/build/index.js.map +1 -1
- package/build/src/data/{JmesparthReader.d.ts → JmespathReader.d.ts} +1 -1
- package/build/src/data/{JmesparthReader.js → JmespathReader.js} +2 -2
- package/build/src/data/JmespathReader.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +5 -5
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/data/XmlReader.js +14 -1
- package/build/src/data/XmlReader.js.map +1 -1
- package/build/src/events/BaseEvents.d.ts +25 -0
- package/build/src/events/Events.d.ts +1 -1
- package/build/src/events/transport/TransportEvents.d.ts +1 -1
- package/build/src/events/transport/TransportEvents.js.map +1 -1
- package/build/src/models/ClientCertificate.d.ts +9 -0
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.d.ts +3 -2
- package/build/src/models/Environment.js +11 -6
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/ErrorResponse.js.map +1 -1
- package/build/src/models/HttpRequest.d.ts +2 -7
- package/build/src/models/HttpRequest.js +1 -6
- package/build/src/models/HttpRequest.js.map +1 -1
- package/build/src/models/HttpResponse.d.ts +2 -7
- package/build/src/models/HttpResponse.js +1 -3
- package/build/src/models/HttpResponse.js.map +1 -1
- package/build/src/models/ProjectExecution.d.ts +115 -0
- package/build/src/models/ProjectExecution.js +148 -0
- package/build/src/models/ProjectExecution.js.map +1 -0
- package/build/src/models/ProjectRequest.d.ts +19 -0
- package/build/src/models/ProjectRequest.js +50 -0
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/Request.d.ts +12 -3
- package/build/src/models/Request.js +14 -1
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestLog.d.ts +11 -0
- package/build/src/models/RequestLog.js +15 -1
- package/build/src/models/RequestLog.js.map +1 -1
- package/build/src/models/SerializablePayload.d.ts +6 -1
- package/build/src/models/SerializablePayload.js +10 -6
- package/build/src/models/SerializablePayload.js.map +1 -1
- package/build/src/models/http-actions/AssertionError.d.ts +36 -0
- package/build/src/models/http-actions/AssertionError.js +35 -0
- package/build/src/models/http-actions/AssertionError.js.map +1 -0
- package/build/src/models/http-actions/HttpAssertion.d.ts +84 -0
- package/build/src/models/http-actions/HttpAssertion.js +52 -0
- package/build/src/models/http-actions/HttpAssertion.js.map +1 -0
- package/build/src/models/http-actions/HttpFlows.d.ts +109 -0
- package/build/src/models/http-actions/HttpFlows.js +31 -0
- package/build/src/models/http-actions/HttpFlows.js.map +1 -0
- package/build/src/models/http-actions/HttpStep.d.ts +29 -0
- package/build/src/models/http-actions/HttpStep.js +30 -0
- package/build/src/models/http-actions/HttpStep.js.map +1 -0
- package/build/src/models/http-actions/LegacyTranslator.d.ts +8 -7
- package/build/src/models/http-actions/LegacyTranslator.js +18 -13
- package/build/src/models/http-actions/LegacyTranslator.js.map +1 -1
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.d.ts +76 -0
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.js +79 -0
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.d.ts +76 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js +79 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.d.ts +29 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.d.ts +35 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js +53 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/index.d.ts +15 -0
- package/build/src/models/http-actions/steps/assertion/index.js +16 -0
- package/build/src/models/http-actions/steps/assertion/index.js.map +1 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.d.ts +44 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.js +67 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.d.ts +53 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js +60 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.d.ts +67 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.js +77 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.d.ts +45 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.js +52 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.d.ts +100 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.js +138 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.d.ts +77 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.js +69 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.d.ts +40 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.js +44 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/index.d.ts +7 -0
- package/build/src/models/http-actions/steps/data/index.js +8 -0
- package/build/src/models/http-actions/steps/data/index.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.d.ts +43 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.js +52 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.d.ts +38 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.js +65 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.d.ts +20 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.js +30 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/index.d.ts +6 -0
- package/build/src/models/http-actions/steps/transformation/index.js +7 -0
- package/build/src/models/http-actions/steps/transformation/index.js.map +1 -0
- package/build/src/proxy/HttpProjectProxy.d.ts +1 -1
- package/build/src/proxy/Proxy.d.ts +1 -1
- package/build/src/proxy/ProxyService.d.ts +1 -1
- package/build/src/proxy/RequestProxy.d.ts +7 -2
- package/build/src/proxy/RequestProxy.js +4 -1
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-runner/ConditionCheck.d.ts +10 -10
- package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -1
- package/build/src/runtime/http-runner/HttpAssertionRunner.d.ts +75 -0
- package/build/src/runtime/http-runner/HttpAssertionRunner.js +538 -0
- package/build/src/runtime/http-runner/HttpAssertionRunner.js.map +1 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +11 -6
- package/build/src/runtime/http-runner/HttpFlowRunner.js +24 -15
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -1
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +14 -3
- package/build/src/runtime/http-runner/HttpRequestRunner.js +44 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
- package/build/src/runtime/node/BaseRunner.d.ts +1 -1
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -2
- package/build/src/runtime/node/ProjectParallelRunner.js +2 -2
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js +6 -2
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +1 -1
- package/build/src/runtime/node/ProjectSerialRunner.d.ts +1 -1
- package/build/src/runtime/reporters/Reporter.d.ts +1 -33
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/interfaces/ApiClientStore.d.ts +2 -0
- package/build/src/runtime/store/interfaces/ProjectRuns.d.ts +56 -0
- package/build/src/runtime/store/interfaces/ProjectRuns.js +2 -0
- package/build/src/runtime/store/interfaces/ProjectRuns.js.map +1 -0
- package/package.json +3 -2
- package/src/data/{JmesparthReader.ts → JmespathReader.ts} +2 -2
- package/src/data/RequestDataExtractor.ts +5 -5
- package/src/data/XmlReader.ts +16 -2
- package/src/events/BaseEvents.ts +30 -0
- package/src/events/transport/TransportEvents.ts +1 -1
- package/src/models/ClientCertificate.ts +9 -0
- package/src/models/Environment.ts +11 -7
- package/src/models/ErrorResponse.ts +1 -1
- package/src/models/HttpRequest.ts +4 -14
- package/src/models/HttpResponse.ts +5 -11
- package/src/models/ProjectExecution.ts +227 -0
- package/src/models/ProjectRequest.ts +54 -0
- package/src/models/Request.ts +23 -4
- package/src/models/RequestAuthorization.ts +1 -1
- package/src/models/RequestLog.ts +21 -1
- package/src/models/SerializablePayload.ts +18 -1
- package/src/models/http-actions/AssertionError.ts +57 -0
- package/src/models/http-actions/HttpAssertion.ts +89 -0
- package/src/models/http-actions/HttpFlows.ts +115 -0
- package/src/models/http-actions/HttpStep.ts +50 -0
- package/src/models/http-actions/LegacyTranslator.ts +42 -30
- package/src/models/http-actions/steps/assertion/EqualAssertion.ts +130 -0
- package/src/models/http-actions/steps/assertion/GreaterThanAssertion.ts +87 -0
- package/src/models/http-actions/steps/assertion/IncludesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/IsEmptyAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/LengthOfAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/LessThanAssertion.ts +87 -0
- package/src/models/http-actions/steps/assertion/MatchesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.ts +85 -0
- package/src/models/http-actions/steps/assertion/NotEqualAssertion.ts +130 -0
- package/src/models/http-actions/steps/assertion/NotIncludesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/NotOkAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/NotToBeAssertion.ts +69 -0
- package/src/models/http-actions/steps/assertion/OkAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/ToBeAssertion.ts +76 -0
- package/src/models/http-actions/steps/data/DeleteCookieStep.ts +102 -0
- package/src/models/http-actions/steps/data/ReadDataSourceStep.ts +103 -0
- package/src/models/http-actions/steps/data/ReadDataStep.ts +128 -0
- package/src/models/http-actions/steps/data/ReadValueStep.ts +88 -0
- package/src/models/http-actions/steps/data/SetCookieStep.ts +206 -0
- package/src/models/http-actions/steps/data/SetDataStep.ts +124 -0
- package/src/models/http-actions/steps/data/SetVariableStep.ts +82 -0
- package/src/models/http-actions/steps/transformation/AsLowerCaseStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/AsNumberStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/AsUpperCaseStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/RoundStep.ts +86 -0
- package/src/models/http-actions/steps/transformation/SubstringStep.ts +93 -0
- package/src/models/http-actions/steps/transformation/TrimStep.ts +43 -0
- package/src/proxy/HttpProjectProxy.ts +1 -1
- package/src/proxy/Proxy.ts +1 -1
- package/src/proxy/ProxyService.ts +1 -1
- package/src/proxy/RequestProxy.ts +11 -3
- package/src/runtime/http-runner/ConditionCheck.ts +13 -14
- package/src/runtime/http-runner/HttpAssertionRunner.ts +540 -0
- package/src/runtime/http-runner/HttpFlowRunner.ts +33 -19
- package/src/runtime/http-runner/HttpRequestRunner.ts +53 -5
- package/src/runtime/node/BaseRunner.ts +1 -1
- package/src/runtime/node/ProjectParallelRunner.ts +5 -5
- package/src/runtime/node/ProjectRequestRunner.ts +6 -2
- package/src/runtime/node/ProjectRunner.ts +1 -1
- package/src/runtime/node/ProjectRunnerWorker.ts +1 -1
- package/src/runtime/node/ProjectSerialRunner.ts +1 -1
- package/src/runtime/reporters/Reporter.ts +1 -35
- package/src/runtime/store/interfaces/ApiClientStore.ts +3 -0
- package/src/runtime/store/interfaces/ProjectRuns.ts +64 -0
- package/build/src/data/JmesparthReader.js.map +0 -1
- package/build/src/models/http-actions/HttpActions.d.ts +0 -256
- package/build/src/models/http-actions/HttpActions.js +0 -46
- package/build/src/models/http-actions/HttpActions.js.map +0 -1
- package/src/models/http-actions/HttpActions.ts +0 -270
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { assert } from '@esm-bundle/chai';
|
|
2
|
+
import { HttpRequest } from "../../models/HttpRequest.js";
|
|
3
|
+
import { ISentRequest } from "../../models/SentRequest.js";
|
|
4
|
+
import { IResponse } from "../../models/Response.js";
|
|
5
|
+
import { ErrorResponse, IErrorResponse } from "../../models/ErrorResponse.js";
|
|
6
|
+
import { AssertionResult, IHttpAssertion } from "../../models/http-actions/HttpAssertion.js";
|
|
7
|
+
import { IHttpStep } from "../../models/http-actions/HttpStep.js";
|
|
8
|
+
import { FlowValue } from "./HttpFlowRunner.js";
|
|
9
|
+
import { FlowRequestDataEnum, FlowResponseDataEnum, FlowSourceEnum } from "../../models/http-actions/HttpFlows.js";
|
|
10
|
+
import { IReadDataSourceStep, ReadDataSourceStep, ReadDataSourceStepKind } from "../../models/http-actions/steps/data/ReadDataSourceStep.js";
|
|
11
|
+
import { IReadValueStep, ReadValueStep, ReadValueStepKind } from "../../models/http-actions/steps/data/ReadValueStep.js";
|
|
12
|
+
import * as DataUtils from '../../data/DataUtils.js';
|
|
13
|
+
import { HttpResponse } from "../../models/HttpResponse.js";
|
|
14
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
15
|
+
import { DataReader } from "../../data/DataReader.js";
|
|
16
|
+
import { JmespathReader } from "../../data/JmespathReader.js";
|
|
17
|
+
import { XmlReader } from "../../data/XmlReader.js";
|
|
18
|
+
import { UrlEncodedReader } from "../../data/UrlEncodedReader.js";
|
|
19
|
+
import { AsLowerCaseStepKind } from "../../models/http-actions/steps/transformation/AsLowerCaseStep.js";
|
|
20
|
+
import { AsUpperCaseStepKind } from "../../models/http-actions/steps/transformation/AsUpperCaseStep.js";
|
|
21
|
+
import { AsNumberStepKind } from "../../models/http-actions/steps/transformation/AsNumberStep.js";
|
|
22
|
+
import { IRoundStep, RoundStepKind } from "../../models/http-actions/steps/transformation/RoundStep.js";
|
|
23
|
+
import { ISubstringStep, SubstringStepKind } from "../../models/http-actions/steps/transformation/SubstringStep.js";
|
|
24
|
+
import { TrimStepKind } from "../../models/http-actions/steps/transformation/TrimStep.js";
|
|
25
|
+
import { EqualAssertionKind, IEqualAssertion } from "../../models/http-actions/steps/assertion/EqualAssertion.js";
|
|
26
|
+
import { INotEqualAssertion, NotEqualAssertionKind } from "../../models/http-actions/steps/assertion/NotEqualAssertion.js";
|
|
27
|
+
import { ApiSchemaValues } from "../../amf/ApiSchemaValues.js";
|
|
28
|
+
import { AssertionError } from "../../models/http-actions/AssertionError.js";
|
|
29
|
+
import { GreaterThanAssertionKind, IGreaterThanAssertion } from "../../models/http-actions/steps/assertion/GreaterThanAssertion.js";
|
|
30
|
+
import { ILessThanAssertion, LessThanAssertionKind } from "../../models/http-actions/steps/assertion/LessThanAssertion.js";
|
|
31
|
+
import { IIncludesAssertion, IncludesAssertionKind } from "../../models/http-actions/steps/assertion/IncludesAssertion.js";
|
|
32
|
+
import { INotIncludesAssertion, NotIncludesAssertionKind } from "../../models/http-actions/steps/assertion/NotIncludesAssertion.js";
|
|
33
|
+
import { OkAssertionKind } from "../../models/http-actions/steps/assertion/OkAssertion.js";
|
|
34
|
+
import { NotOkAssertionKind } from "../../models/http-actions/steps/assertion/NotOkAssertion.js";
|
|
35
|
+
import { IToBeAssertion, ToBeAssertionKind, ToBeTypes } from '../../models/http-actions/steps/assertion/ToBeAssertion.js';
|
|
36
|
+
import { INotToBeAssertion, NotToBeAssertionKind } from '../../models/http-actions/steps/assertion/NotToBeAssertion.js';
|
|
37
|
+
import { IsEmptyAssertionKind } from '../../models/http-actions/steps/assertion/IsEmptyAssertion.js';
|
|
38
|
+
import { IsNotEmptyAssertionKind } from '../../models/http-actions/steps/assertion/IsNotEmptyAssertion.js';
|
|
39
|
+
import { ILengthOfAssertion, LengthOfAssertionKind } from '../../models/http-actions/steps/assertion/LengthOfAssertion.js';
|
|
40
|
+
|
|
41
|
+
interface IStepValue {
|
|
42
|
+
value: FlowValue;
|
|
43
|
+
type?: FlowRequestDataEnum | FlowResponseDataEnum;
|
|
44
|
+
bodyMime?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A class that perform assertions that have been defined on an HTTP request.
|
|
49
|
+
*/
|
|
50
|
+
export class HttpAssertionRunner {
|
|
51
|
+
report: AssertionResult[] = [];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param request The request object sent to the server
|
|
56
|
+
* @param response The generated response
|
|
57
|
+
* @param assertions The list of assertions to perform.
|
|
58
|
+
*/
|
|
59
|
+
async run(request: ISentRequest, response: IResponse | IErrorResponse, assertions: IHttpAssertion[]): Promise<AssertionResult[]> {
|
|
60
|
+
this.report = [];
|
|
61
|
+
if (!assertions || !assertions.length) {
|
|
62
|
+
return [...this.report];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const assertion of assertions) {
|
|
66
|
+
await this.runAssertion(request, response, assertion);
|
|
67
|
+
}
|
|
68
|
+
return [...this.report];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected async runAssertion(request: ISentRequest, response: IResponse | IErrorResponse, assertion: IHttpAssertion): Promise<void> {
|
|
72
|
+
const { steps } = assertion;
|
|
73
|
+
|
|
74
|
+
// this keeps a value from the last step to be passed to the next step.
|
|
75
|
+
let lastResult: IStepValue = {
|
|
76
|
+
value: undefined,
|
|
77
|
+
};
|
|
78
|
+
let error: AssertionError | undefined;
|
|
79
|
+
for (const step of steps) {
|
|
80
|
+
try {
|
|
81
|
+
lastResult = await this.runStep(request, response, step, lastResult);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
const typed = e as AssertionError;
|
|
84
|
+
if (typed.name === 'AssertionError') {
|
|
85
|
+
error = typed;
|
|
86
|
+
} else {
|
|
87
|
+
const err = e as Error;
|
|
88
|
+
error = new AssertionError({
|
|
89
|
+
message: err.message,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const description = assertion.description || this.createDescription(steps);
|
|
96
|
+
if (error) {
|
|
97
|
+
this.report.push({
|
|
98
|
+
ok: false,
|
|
99
|
+
description,
|
|
100
|
+
error: error.toJSON(),
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
this.report.push({
|
|
104
|
+
ok: true,
|
|
105
|
+
description,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected createDescription(steps: IHttpStep[]): string {
|
|
111
|
+
const parts: string[] = [];
|
|
112
|
+
for (const step of steps) {
|
|
113
|
+
switch (step.kind) {
|
|
114
|
+
case ReadDataSourceStepKind: parts.push(this.getDataSourceStepLabel(step as IReadDataSourceStep)); break;
|
|
115
|
+
case ReadValueStepKind: parts.push(this.getValueStepLabel(step as IReadValueStep)); break;
|
|
116
|
+
case AsLowerCaseStepKind: parts.push('To lower case'); break;
|
|
117
|
+
case AsUpperCaseStepKind: parts.push('To upper case'); break;
|
|
118
|
+
case AsNumberStepKind: parts.push('As number'); break;
|
|
119
|
+
case RoundStepKind: parts.push('Round'); break;
|
|
120
|
+
case TrimStepKind: parts.push('Trim'); break;
|
|
121
|
+
case SubstringStepKind: parts.push('Substring'); break;
|
|
122
|
+
case EqualAssertionKind: parts.push(`Equals to ${(step as IEqualAssertion).value}`); break;
|
|
123
|
+
case NotEqualAssertionKind: parts.push(`Not equals to ${(step as INotEqualAssertion).value}`); break;
|
|
124
|
+
case GreaterThanAssertionKind: parts.push(`Is greater than ${(step as IGreaterThanAssertion).value}`); break;
|
|
125
|
+
case LessThanAssertionKind: parts.push(`Is less than ${(step as ILessThanAssertion).value}`); break;
|
|
126
|
+
case IncludesAssertionKind: parts.push(`Includes ${(step as IIncludesAssertion).value}`); break;
|
|
127
|
+
case NotIncludesAssertionKind: parts.push(`Not includes ${(step as INotIncludesAssertion).value}`); break;
|
|
128
|
+
case OkAssertionKind: parts.push(`Is OK`); break;
|
|
129
|
+
case NotOkAssertionKind: parts.push(`Is not OK`); break;
|
|
130
|
+
default:
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return parts.filter(i => !!i).join(' > ');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected getDataSourceStepLabel(step: IReadDataSourceStep): string {
|
|
137
|
+
if (step.source === FlowSourceEnum.request) {
|
|
138
|
+
if (step.data === FlowRequestDataEnum.url) {
|
|
139
|
+
return 'Request URL';
|
|
140
|
+
}
|
|
141
|
+
if (step.data === FlowRequestDataEnum.headers) {
|
|
142
|
+
return 'Request headers';
|
|
143
|
+
}
|
|
144
|
+
if (step.data === FlowRequestDataEnum.method) {
|
|
145
|
+
return 'HTTP method';
|
|
146
|
+
}
|
|
147
|
+
if (step.data === FlowRequestDataEnum.body) {
|
|
148
|
+
return 'Request body';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (step.source === FlowSourceEnum.response) {
|
|
152
|
+
if (step.data === FlowResponseDataEnum.url) {
|
|
153
|
+
return 'Response URL';
|
|
154
|
+
}
|
|
155
|
+
if (step.data === FlowResponseDataEnum.headers) {
|
|
156
|
+
return 'Response headers';
|
|
157
|
+
}
|
|
158
|
+
if (step.data === FlowResponseDataEnum.body) {
|
|
159
|
+
return 'Response body';
|
|
160
|
+
}
|
|
161
|
+
if (step.data === FlowResponseDataEnum.status) {
|
|
162
|
+
return 'Status code';
|
|
163
|
+
}
|
|
164
|
+
if (step.data === FlowResponseDataEnum.statusText) {
|
|
165
|
+
return 'Status message';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return 'Invalid step';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected getValueStepLabel(step: IReadValueStep): string {
|
|
172
|
+
const { path } = step;
|
|
173
|
+
return path || '';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected async runStep(request: ISentRequest, response: IResponse | IErrorResponse, step: IHttpStep, input: IStepValue): Promise<IStepValue> {
|
|
177
|
+
switch (step.kind) {
|
|
178
|
+
// data reading
|
|
179
|
+
case ReadDataSourceStepKind: return this.readDataSource(request, response, step);
|
|
180
|
+
case ReadValueStepKind: return this.readValue(input, step as IReadValueStep);
|
|
181
|
+
// transformations
|
|
182
|
+
case AsLowerCaseStepKind: return this.toLowerCase(input);
|
|
183
|
+
case AsUpperCaseStepKind: return this.toUpperCase(input);
|
|
184
|
+
case AsNumberStepKind: return this.asNumber(input);
|
|
185
|
+
case RoundStepKind: return this.round(input, step as IRoundStep);
|
|
186
|
+
case TrimStepKind: return this.trim(input);
|
|
187
|
+
case SubstringStepKind: return this.substring(input, step as ISubstringStep);
|
|
188
|
+
// assertions
|
|
189
|
+
case EqualAssertionKind: return this.assertEqual(input, step as IEqualAssertion);
|
|
190
|
+
case NotEqualAssertionKind: return this.assertNotEqual(input, step as INotEqualAssertion);
|
|
191
|
+
case GreaterThanAssertionKind: return this.assertGreaterThan(input, step as IGreaterThanAssertion);
|
|
192
|
+
case LessThanAssertionKind: return this.assertLessThan(input, step as ILessThanAssertion);
|
|
193
|
+
case IncludesAssertionKind: return this.assertIncludes(input, step as IIncludesAssertion);
|
|
194
|
+
case NotIncludesAssertionKind: return this.assertNotIncludes(input, step as INotIncludesAssertion);
|
|
195
|
+
case OkAssertionKind: return this.assertOk(input);
|
|
196
|
+
case NotOkAssertionKind: return this.assertNotOk(input);
|
|
197
|
+
case ToBeAssertionKind: return this.toBe(input, step as IToBeAssertion);
|
|
198
|
+
case NotToBeAssertionKind: return this.notToBe(input, step as INotToBeAssertion);
|
|
199
|
+
case IsEmptyAssertionKind: return this.isEmpty(input);
|
|
200
|
+
case IsNotEmptyAssertionKind: return this.isNotEmpty(input);
|
|
201
|
+
case LengthOfAssertionKind: return this.lengthOf(input, step as ILengthOfAssertion);
|
|
202
|
+
default: return { value: undefined };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Produces the data source.
|
|
208
|
+
*/
|
|
209
|
+
protected async readDataSource(request: ISentRequest, response: IResponse | IErrorResponse, step: IReadDataSourceStep): Promise<IStepValue> {
|
|
210
|
+
const instance = new ReadDataSourceStep(step);
|
|
211
|
+
if (instance.enabled === false || !instance.checkValidity()) {
|
|
212
|
+
return { value: undefined };
|
|
213
|
+
}
|
|
214
|
+
const { source, data } = step;
|
|
215
|
+
if (source === FlowSourceEnum.request) {
|
|
216
|
+
if (data === FlowRequestDataEnum.url) {
|
|
217
|
+
return {
|
|
218
|
+
value: request.url,
|
|
219
|
+
type: data,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (data === FlowRequestDataEnum.headers) {
|
|
223
|
+
return {
|
|
224
|
+
value: request.headers,
|
|
225
|
+
type: data,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (data === FlowRequestDataEnum.method) {
|
|
229
|
+
return {
|
|
230
|
+
value: request.method,
|
|
231
|
+
type: data,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (data === FlowRequestDataEnum.body) {
|
|
235
|
+
const instance = new HttpRequest(request);
|
|
236
|
+
const value = await this.processBody(instance);
|
|
237
|
+
return {
|
|
238
|
+
...value,
|
|
239
|
+
type: data,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (source === FlowSourceEnum.response) {
|
|
244
|
+
if (data === FlowResponseDataEnum.url) {
|
|
245
|
+
return {
|
|
246
|
+
value: request.url,
|
|
247
|
+
type: data,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (data === FlowResponseDataEnum.headers) {
|
|
251
|
+
return {
|
|
252
|
+
value: response.headers,
|
|
253
|
+
type: data,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
if (data === FlowResponseDataEnum.status) {
|
|
257
|
+
return {
|
|
258
|
+
value: response.status,
|
|
259
|
+
type: data,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (data === FlowResponseDataEnum.statusText) {
|
|
263
|
+
return {
|
|
264
|
+
value: response.statusText,
|
|
265
|
+
type: data,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (data === FlowResponseDataEnum.body) {
|
|
269
|
+
let instance: ErrorResponse | HttpResponse;
|
|
270
|
+
if (ErrorResponse.isErrorResponse(response)) {
|
|
271
|
+
instance = new ErrorResponse(response as IErrorResponse);
|
|
272
|
+
} else {
|
|
273
|
+
instance = new HttpResponse(response);
|
|
274
|
+
}
|
|
275
|
+
const value = await this.processBody(instance);
|
|
276
|
+
return {
|
|
277
|
+
...value,
|
|
278
|
+
type: data,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return { value: undefined };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
protected async processBody(input: HttpRequest | HttpResponse | ErrorResponse): Promise<IStepValue> {
|
|
286
|
+
const { headers } = input;
|
|
287
|
+
if (!headers) {
|
|
288
|
+
return { value: undefined };
|
|
289
|
+
}
|
|
290
|
+
const body = await input.readPayloadAsString();
|
|
291
|
+
if (!body) {
|
|
292
|
+
return { value: undefined };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const parser = new Headers(headers);
|
|
296
|
+
const mime = parser.get('content-type');
|
|
297
|
+
if (!mime) {
|
|
298
|
+
return { value: undefined };
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
value: body,
|
|
302
|
+
bodyMime: mime,
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Produces the value from the current input.
|
|
308
|
+
*/
|
|
309
|
+
protected async readValue(input: IStepValue, step: IReadValueStep): Promise<IStepValue> {
|
|
310
|
+
const instance = new ReadValueStep(step);
|
|
311
|
+
if (instance.enabled === false || !instance.checkValidity() || input.value === undefined || input.value === null) {
|
|
312
|
+
return { value: undefined };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const { path } = step;
|
|
316
|
+
const { type, value } = input;
|
|
317
|
+
const args = path ? path.split('.') : [];
|
|
318
|
+
if (type === FlowRequestDataEnum.url || type === FlowResponseDataEnum.url) {
|
|
319
|
+
if (!value) {
|
|
320
|
+
return { value: undefined };
|
|
321
|
+
}
|
|
322
|
+
const v = String(input.value);
|
|
323
|
+
return {
|
|
324
|
+
value: DataUtils.getDataUrl(v, args),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if (type === FlowRequestDataEnum.headers || type === FlowResponseDataEnum.headers) {
|
|
328
|
+
if (!value) {
|
|
329
|
+
return { value: undefined };
|
|
330
|
+
}
|
|
331
|
+
const v = String(input.value);
|
|
332
|
+
return {
|
|
333
|
+
value: DataUtils.getDataHeaders(v, args),
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (type === FlowRequestDataEnum.body || type === FlowResponseDataEnum.body) {
|
|
337
|
+
if (!input.bodyMime || !path) {
|
|
338
|
+
return { value: undefined };
|
|
339
|
+
}
|
|
340
|
+
let reader: DataReader | undefined;
|
|
341
|
+
if (input.bodyMime.includes('json')) {
|
|
342
|
+
reader = new JmespathReader();
|
|
343
|
+
} else if (input.bodyMime.includes('xml')) {
|
|
344
|
+
reader = new XmlReader();
|
|
345
|
+
} else if (input.bodyMime.includes('x-www-form-urlencoded')) {
|
|
346
|
+
reader = new UrlEncodedReader();
|
|
347
|
+
}
|
|
348
|
+
if (!reader) {
|
|
349
|
+
return { value: undefined };
|
|
350
|
+
}
|
|
351
|
+
await reader.writePayload(String(value));
|
|
352
|
+
const readValue = await reader.getValue(path);
|
|
353
|
+
return {
|
|
354
|
+
value: readValue,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (type === FlowResponseDataEnum.status) {
|
|
358
|
+
const v = Number(input.value);
|
|
359
|
+
if (Number.isNaN(v)) {
|
|
360
|
+
return { value: undefined };
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
value: v,
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (type === FlowResponseDataEnum.statusText) {
|
|
368
|
+
if (!value) {
|
|
369
|
+
return { value: undefined };
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
value,
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return { value: undefined };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
protected async toLowerCase(input: IStepValue): Promise<IStepValue> {
|
|
379
|
+
if (input.value === null || input.value === undefined) {
|
|
380
|
+
return { value: undefined };
|
|
381
|
+
}
|
|
382
|
+
const value = String(input.value);
|
|
383
|
+
return { value: value.toLowerCase() };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
protected async toUpperCase(input: IStepValue): Promise<IStepValue> {
|
|
387
|
+
if (input.value === null || input.value === undefined) {
|
|
388
|
+
return { value: undefined };
|
|
389
|
+
}
|
|
390
|
+
const value = String(input.value);
|
|
391
|
+
return { value: value.toUpperCase() };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
protected async asNumber(input: IStepValue): Promise<IStepValue> {
|
|
395
|
+
if (input.value === null || input.value === undefined) {
|
|
396
|
+
return { value: undefined };
|
|
397
|
+
}
|
|
398
|
+
const value = String(input.value);
|
|
399
|
+
const parsed = Number(value);
|
|
400
|
+
if (Number.isNaN(parsed)) {
|
|
401
|
+
return { value: undefined };
|
|
402
|
+
}
|
|
403
|
+
return { value: parsed };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
protected async round(input: IStepValue, step: IRoundStep): Promise<IStepValue> {
|
|
407
|
+
if (input.value === null || input.value === undefined) {
|
|
408
|
+
return { value: undefined };
|
|
409
|
+
}
|
|
410
|
+
const value = String(input.value);
|
|
411
|
+
const parsed = typeof input.value === 'number' ? input.value : Number(value);
|
|
412
|
+
if (Number.isNaN(parsed)) {
|
|
413
|
+
return { value: undefined };
|
|
414
|
+
}
|
|
415
|
+
return { value: parsed.toFixed(step.precision) };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
protected async trim(input: IStepValue): Promise<IStepValue> {
|
|
419
|
+
if (input.value === null || input.value === undefined) {
|
|
420
|
+
return { value: undefined };
|
|
421
|
+
}
|
|
422
|
+
const value = String(input.value);
|
|
423
|
+
return { ...input, value: value.trim() };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
protected async substring(input: IStepValue, step: ISubstringStep): Promise<IStepValue> {
|
|
427
|
+
if (input.value === null || input.value === undefined) {
|
|
428
|
+
return { value: undefined };
|
|
429
|
+
}
|
|
430
|
+
if (typeof step.start !== 'number') {
|
|
431
|
+
return input;
|
|
432
|
+
}
|
|
433
|
+
const value = String(input.value);
|
|
434
|
+
return { ...input, value: value.substring(step.start, step.end) };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
protected async assertEqual(input: IStepValue, step: IEqualAssertion): Promise<IStepValue> {
|
|
438
|
+
const { value } = input;
|
|
439
|
+
if (step.strict) {
|
|
440
|
+
const comparator = ApiSchemaValues.readTypedValue(step.value, step.dataType);
|
|
441
|
+
assert.strictEqual(value, comparator);
|
|
442
|
+
} else {
|
|
443
|
+
assert.equal(String(value), step.value);
|
|
444
|
+
}
|
|
445
|
+
return input;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
protected async assertNotEqual(input: IStepValue, step: INotEqualAssertion): Promise<IStepValue> {
|
|
449
|
+
const { value } = input;
|
|
450
|
+
if (step.strict) {
|
|
451
|
+
const comparator = ApiSchemaValues.readTypedValue(step.value, step.dataType);
|
|
452
|
+
assert.notStrictEqual(value, comparator);
|
|
453
|
+
} else {
|
|
454
|
+
assert.notEqual(value, step.value);
|
|
455
|
+
}
|
|
456
|
+
return input;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
protected async assertGreaterThan(input: IStepValue, step: IGreaterThanAssertion): Promise<IStepValue> {
|
|
460
|
+
assert.typeOf(input.value, 'number');
|
|
461
|
+
const value = input.value as number;
|
|
462
|
+
if (step.equal) {
|
|
463
|
+
assert.isAtLeast(value as number, step.value as number);
|
|
464
|
+
} else {
|
|
465
|
+
assert.isAbove(value as number, step.value as number);
|
|
466
|
+
}
|
|
467
|
+
return input;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
protected async assertLessThan(input: IStepValue, step: ILessThanAssertion): Promise<IStepValue> {
|
|
471
|
+
assert.typeOf(input.value, 'number');
|
|
472
|
+
const value = input.value as number;
|
|
473
|
+
if (step.equal) {
|
|
474
|
+
assert.isAtMost(value, step.value as number);
|
|
475
|
+
} else {
|
|
476
|
+
assert.isBelow(value, step.value as number);
|
|
477
|
+
}
|
|
478
|
+
return input;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
protected async assertIncludes(input: IStepValue, step: IIncludesAssertion): Promise<IStepValue> {
|
|
482
|
+
if (this.isPrimitive(input.value)) {
|
|
483
|
+
assert.include(String(input.value), String(step.value));
|
|
484
|
+
} else {
|
|
485
|
+
assert.include(JSON.stringify(input.value), String(step.value));
|
|
486
|
+
}
|
|
487
|
+
return input;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
protected async assertNotIncludes(input: IStepValue, step: INotIncludesAssertion): Promise<IStepValue> {
|
|
491
|
+
if (this.isPrimitive(input.value)) {
|
|
492
|
+
assert.notInclude(String(input.value), String(step.value));
|
|
493
|
+
} else {
|
|
494
|
+
assert.notInclude(JSON.stringify(input.value), String(step.value));
|
|
495
|
+
}
|
|
496
|
+
return input;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
protected async assertOk(input: IStepValue): Promise<IStepValue> {
|
|
500
|
+
assert.ok(input.value);
|
|
501
|
+
return input;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
protected async assertNotOk(input: IStepValue): Promise<IStepValue> {
|
|
505
|
+
assert.notOk(input.value);
|
|
506
|
+
return input;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
protected async toBe(input: IStepValue, step: IToBeAssertion): Promise<IStepValue> {
|
|
510
|
+
assert.typeOf(input.value, step.value as string);
|
|
511
|
+
return input;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
protected async notToBe(input: IStepValue, step: INotToBeAssertion): Promise<IStepValue> {
|
|
515
|
+
if (Array.isArray(input.value) && step.value === ToBeTypes.object) {
|
|
516
|
+
assert(false, 'expected [Array] to be an object');
|
|
517
|
+
}
|
|
518
|
+
assert.notTypeOf(input.value, step.value as string);
|
|
519
|
+
return input;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
protected async isEmpty(input: IStepValue): Promise<IStepValue> {
|
|
523
|
+
assert.isEmpty(input.value);
|
|
524
|
+
return input;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
protected async isNotEmpty(input: IStepValue): Promise<IStepValue> {
|
|
528
|
+
assert.isNotEmpty(input.value);
|
|
529
|
+
return input;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
protected async lengthOf(input: IStepValue, step: ILengthOfAssertion): Promise<IStepValue> {
|
|
533
|
+
assert.lengthOf(input.value as unknown[], step.value as number);
|
|
534
|
+
return input;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
protected isPrimitive(value: unknown): boolean {
|
|
538
|
+
return (typeof value !== 'object' && typeof value !== 'function') || value === null;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
@@ -4,13 +4,22 @@ import { ISentRequest } from "../../models/SentRequest.js";
|
|
|
4
4
|
import { IResponse } from "../../models/Response.js";
|
|
5
5
|
import { IErrorResponse } from "../../models/ErrorResponse.js";
|
|
6
6
|
import { HttpCookie } from "../../models/HttpCookie.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
FlowSourceEnum, IHttpAction,
|
|
9
|
+
IHttpFlow, IHttpCondition,
|
|
10
|
+
} from '../../models/http-actions/HttpFlows.js';
|
|
8
11
|
import { RequestDataExtractor } from "../../data/RequestDataExtractor.js";
|
|
9
12
|
import { checkCondition } from "./ConditionCheck.js";
|
|
10
13
|
import { ApiSchemaValues } from "../../amf/ApiSchemaValues.js";
|
|
11
14
|
import { SameSiteValue } from "../../cookies/CookieParser.js";
|
|
15
|
+
import { IHttpStep } from "../../models/http-actions/HttpStep.js";
|
|
16
|
+
import { IReadDataStep, ReadDataStep, ReadDataStepKind } from "../../models/http-actions/steps/data/ReadDataStep.js";
|
|
17
|
+
import { ISetDataStep, SetDataStep, SetDataStepKind } from "../../models/http-actions/steps/data/SetDataStep.js";
|
|
18
|
+
import { ISetVariableStep, SetVariableStep, SetVariableStepKind } from "../../models/http-actions/steps/data/SetVariableStep.js";
|
|
19
|
+
import { ISetCookieStep, SetCookieStep, SetCookieStepKind } from "../../models/http-actions/steps/data/SetCookieStep.js";
|
|
20
|
+
import { DeleteCookieStep, DeleteCookieStepKind, IDeleteCookieStep } from "../../models/http-actions/steps/data/DeleteCookieStep.js";
|
|
12
21
|
|
|
13
|
-
type FlowValue = string | number | boolean | null | undefined;
|
|
22
|
+
export type FlowValue = string | number | boolean | null | undefined | unknown;
|
|
14
23
|
|
|
15
24
|
export class HttpFlowRunner {
|
|
16
25
|
/**
|
|
@@ -27,7 +36,7 @@ export class HttpFlowRunner {
|
|
|
27
36
|
*/
|
|
28
37
|
cookies?: CookieJar;
|
|
29
38
|
|
|
30
|
-
async request(request: IHttpRequest, flows?:
|
|
39
|
+
async request(request: IHttpRequest, flows?: IHttpFlow[]): Promise<void> {
|
|
31
40
|
if (!flows || !flows.length) {
|
|
32
41
|
return;
|
|
33
42
|
}
|
|
@@ -38,7 +47,7 @@ export class HttpFlowRunner {
|
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
async response(request: IHttpRequest | ISentRequest, response: IResponse | IErrorResponse, flows?:
|
|
50
|
+
async response(request: IHttpRequest | ISentRequest, response: IResponse | IErrorResponse, flows?: IHttpFlow[]): Promise<void> {
|
|
42
51
|
if (!flows || !flows.length) {
|
|
43
52
|
return;
|
|
44
53
|
}
|
|
@@ -78,7 +87,7 @@ export class HttpFlowRunner {
|
|
|
78
87
|
return checkCondition(readValue, operator, value);
|
|
79
88
|
}
|
|
80
89
|
|
|
81
|
-
async _runStep(step:
|
|
90
|
+
async _runStep(step: IHttpStep, input: FlowValue, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<FlowValue> {
|
|
82
91
|
switch (step.kind) {
|
|
83
92
|
case ReadDataStepKind: return this._runReadDataStep(step as IReadDataStep, request, response);
|
|
84
93
|
case SetDataStepKind: return this._runSetDataStep(step as ISetDataStep);
|
|
@@ -98,21 +107,23 @@ export class HttpFlowRunner {
|
|
|
98
107
|
* @returns The read value or undefined.
|
|
99
108
|
*/
|
|
100
109
|
async _runReadDataStep(step: IReadDataStep, request: IHttpRequest | ISentRequest, response?: IResponse | IErrorResponse): Promise<string | number | undefined> {
|
|
101
|
-
const
|
|
102
|
-
|
|
110
|
+
const instance = new ReadDataStep(step);
|
|
111
|
+
|
|
112
|
+
if (instance.enabled === false || !instance.checkValidity()) {
|
|
103
113
|
return undefined;
|
|
104
114
|
}
|
|
105
|
-
|
|
115
|
+
const { source, data, path } = step;
|
|
116
|
+
if (source === FlowSourceEnum.request) {
|
|
106
117
|
const extractor = new RequestDataExtractor(request);
|
|
107
118
|
return extractor.extract(source, data, path);
|
|
108
119
|
}
|
|
109
120
|
|
|
110
|
-
if (source ===
|
|
121
|
+
if (source === FlowSourceEnum.response) {
|
|
111
122
|
const extractor = new RequestDataExtractor(request, response);
|
|
112
123
|
return extractor.extract(source, data, path);
|
|
113
124
|
}
|
|
114
125
|
|
|
115
|
-
if (source ===
|
|
126
|
+
if (source === FlowSourceEnum.variable && path && this.variables) {
|
|
116
127
|
return this.variables[path];
|
|
117
128
|
}
|
|
118
129
|
|
|
@@ -126,10 +137,11 @@ export class HttpFlowRunner {
|
|
|
126
137
|
* @returns The read value with applied data type.
|
|
127
138
|
*/
|
|
128
139
|
_runSetDataStep(step: ISetDataStep): FlowValue {
|
|
129
|
-
const
|
|
130
|
-
if (enabled === false) {
|
|
140
|
+
const instance = new SetDataStep(step);
|
|
141
|
+
if (instance.enabled === false || !instance.checkValidity()) {
|
|
131
142
|
return undefined;
|
|
132
143
|
}
|
|
144
|
+
const { value, dataType } = step;
|
|
133
145
|
if (value === null || value === undefined) {
|
|
134
146
|
return undefined;
|
|
135
147
|
}
|
|
@@ -143,10 +155,11 @@ export class HttpFlowRunner {
|
|
|
143
155
|
* @param value The value to set. A value that is `null` or `undefined` deletes the variable.
|
|
144
156
|
*/
|
|
145
157
|
_runSetVariableStep(step: ISetVariableStep, value: FlowValue): FlowValue {
|
|
146
|
-
const
|
|
147
|
-
if (enabled === false || !
|
|
158
|
+
const instance = new SetVariableStep(step);
|
|
159
|
+
if (instance.enabled === false || !instance.checkValidity() || !this.variables) {
|
|
148
160
|
return undefined;
|
|
149
161
|
}
|
|
162
|
+
const { name } = step;
|
|
150
163
|
if (value === null || typeof value === undefined) {
|
|
151
164
|
delete this.variables[name];
|
|
152
165
|
} else {
|
|
@@ -163,14 +176,15 @@ export class HttpFlowRunner {
|
|
|
163
176
|
* @param request The request object.
|
|
164
177
|
*/
|
|
165
178
|
async _runSetCookieStep(step: ISetCookieStep, value: FlowValue, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
|
|
166
|
-
const
|
|
179
|
+
const instance = new SetCookieStep(step);
|
|
167
180
|
const { cookies } = this;
|
|
168
|
-
if (enabled === false || !
|
|
181
|
+
if (instance.enabled === false || !instance.checkValidity() || !cookies ) {
|
|
169
182
|
return undefined;
|
|
170
183
|
}
|
|
171
184
|
if (value === null || typeof value === undefined) {
|
|
172
185
|
return undefined;
|
|
173
186
|
}
|
|
187
|
+
const { name, expires, hostOnly, httpOnly, sameSite, secure, session } = step;
|
|
174
188
|
const typedValue = String(value);
|
|
175
189
|
let url: string;
|
|
176
190
|
if (step.url) {
|
|
@@ -215,9 +229,9 @@ export class HttpFlowRunner {
|
|
|
215
229
|
* A step to delete cookies from the cookie jar.
|
|
216
230
|
*/
|
|
217
231
|
async _runDeleteCookieStep(step: IDeleteCookieStep, request: IHttpRequest | ISentRequest): Promise<FlowValue> {
|
|
218
|
-
const
|
|
232
|
+
const instance = new DeleteCookieStep(step);
|
|
219
233
|
const { cookies } = this;
|
|
220
|
-
if (enabled === false || !cookies ) {
|
|
234
|
+
if (instance.enabled === false || !instance.checkValidity() || !cookies ) {
|
|
221
235
|
return undefined;
|
|
222
236
|
}
|
|
223
237
|
let url: string;
|
|
@@ -226,7 +240,7 @@ export class HttpFlowRunner {
|
|
|
226
240
|
} else {
|
|
227
241
|
url = request.url;
|
|
228
242
|
}
|
|
229
|
-
await cookies.deleteCookies(url, name);
|
|
243
|
+
await cookies.deleteCookies(url, step.name);
|
|
230
244
|
return undefined;
|
|
231
245
|
}
|
|
232
246
|
}
|