mocktp 0.0.1-security → 3.15.3
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.
Potentially problematic release.
This version of mocktp might be problematic. Click here for more details.
- package/LICENSE +201 -0
- package/README.md +123 -3
- package/custom-typings/Function.d.ts +4 -0
- package/custom-typings/cors-gate.d.ts +13 -0
- package/custom-typings/http-proxy-agent.d.ts +9 -0
- package/custom-typings/node-type-extensions.d.ts +115 -0
- package/custom-typings/proxy-agent-modules.d.ts +5 -0
- package/custom-typings/request-promise-native.d.ts +28 -0
- package/custom-typings/zstd-codec.d.ts +20 -0
- package/dist/admin/admin-bin.d.ts +3 -0
- package/dist/admin/admin-bin.d.ts.map +1 -0
- package/dist/admin/admin-bin.js +61 -0
- package/dist/admin/admin-bin.js.map +1 -0
- package/dist/admin/admin-plugin-types.d.ts +29 -0
- package/dist/admin/admin-plugin-types.d.ts.map +1 -0
- package/dist/admin/admin-plugin-types.js +3 -0
- package/dist/admin/admin-plugin-types.js.map +1 -0
- package/dist/admin/admin-server.d.ts +98 -0
- package/dist/admin/admin-server.d.ts.map +1 -0
- package/dist/admin/admin-server.js +426 -0
- package/dist/admin/admin-server.js.map +1 -0
- package/dist/admin/graphql-utils.d.ts +4 -0
- package/dist/admin/graphql-utils.d.ts.map +1 -0
- package/dist/admin/graphql-utils.js +28 -0
- package/dist/admin/graphql-utils.js.map +1 -0
- package/dist/admin/mockttp-admin-model.d.ts +7 -0
- package/dist/admin/mockttp-admin-model.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-model.js +214 -0
- package/dist/admin/mockttp-admin-model.js.map +1 -0
- package/dist/admin/mockttp-admin-plugin.d.ts +28 -0
- package/dist/admin/mockttp-admin-plugin.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-plugin.js +37 -0
- package/dist/admin/mockttp-admin-plugin.js.map +1 -0
- package/dist/admin/mockttp-admin-server.d.ts +16 -0
- package/dist/admin/mockttp-admin-server.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-server.js +17 -0
- package/dist/admin/mockttp-admin-server.js.map +1 -0
- package/dist/admin/mockttp-schema.d.ts +2 -0
- package/dist/admin/mockttp-schema.d.ts.map +1 -0
- package/dist/admin/mockttp-schema.js +225 -0
- package/dist/admin/mockttp-schema.js.map +1 -0
- package/dist/client/admin-client.d.ts +112 -0
- package/dist/client/admin-client.d.ts.map +1 -0
- package/dist/client/admin-client.js +511 -0
- package/dist/client/admin-client.js.map +1 -0
- package/dist/client/admin-query.d.ts +13 -0
- package/dist/client/admin-query.d.ts.map +1 -0
- package/dist/client/admin-query.js +26 -0
- package/dist/client/admin-query.js.map +1 -0
- package/dist/client/mocked-endpoint-client.d.ts +12 -0
- package/dist/client/mocked-endpoint-client.d.ts.map +1 -0
- package/dist/client/mocked-endpoint-client.js +33 -0
- package/dist/client/mocked-endpoint-client.js.map +1 -0
- package/dist/client/mockttp-admin-request-builder.d.ts +38 -0
- package/dist/client/mockttp-admin-request-builder.d.ts.map +1 -0
- package/dist/client/mockttp-admin-request-builder.js +462 -0
- package/dist/client/mockttp-admin-request-builder.js.map +1 -0
- package/dist/client/mockttp-client.d.ts +56 -0
- package/dist/client/mockttp-client.d.ts.map +1 -0
- package/dist/client/mockttp-client.js +112 -0
- package/dist/client/mockttp-client.js.map +1 -0
- package/dist/client/schema-introspection.d.ts +11 -0
- package/dist/client/schema-introspection.d.ts.map +1 -0
- package/dist/client/schema-introspection.js +128 -0
- package/dist/client/schema-introspection.js.map +1 -0
- package/dist/main.browser.d.ts +49 -0
- package/dist/main.browser.d.ts.map +1 -0
- package/dist/main.browser.js +57 -0
- package/dist/main.browser.js.map +1 -0
- package/dist/main.d.ts +86 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +108 -0
- package/dist/main.js.map +1 -0
- package/dist/mockttp.d.ts +774 -0
- package/dist/mockttp.d.ts.map +1 -0
- package/dist/mockttp.js +81 -0
- package/dist/mockttp.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts +5 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js +12 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts +8 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js +13 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts +6 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js +13 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts +18 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.js +20 -0
- package/dist/pluggable-admin-api/pluggable-admin.js.map +1 -0
- package/dist/rules/base-rule-builder.d.ts +185 -0
- package/dist/rules/base-rule-builder.d.ts.map +1 -0
- package/dist/rules/base-rule-builder.js +251 -0
- package/dist/rules/base-rule-builder.js.map +1 -0
- package/dist/rules/completion-checkers.d.ts +41 -0
- package/dist/rules/completion-checkers.d.ts.map +1 -0
- package/dist/rules/completion-checkers.js +87 -0
- package/dist/rules/completion-checkers.js.map +1 -0
- package/dist/rules/http-agents.d.ts +11 -0
- package/dist/rules/http-agents.d.ts.map +1 -0
- package/dist/rules/http-agents.js +91 -0
- package/dist/rules/http-agents.js.map +1 -0
- package/dist/rules/matchers.d.ts +214 -0
- package/dist/rules/matchers.d.ts.map +1 -0
- package/dist/rules/matchers.js +515 -0
- package/dist/rules/matchers.js.map +1 -0
- package/dist/rules/passthrough-handling-definitions.d.ts +106 -0
- package/dist/rules/passthrough-handling-definitions.d.ts.map +1 -0
- package/dist/rules/passthrough-handling-definitions.js +3 -0
- package/dist/rules/passthrough-handling-definitions.js.map +1 -0
- package/dist/rules/passthrough-handling.d.ts +33 -0
- package/dist/rules/passthrough-handling.d.ts.map +1 -0
- package/dist/rules/passthrough-handling.js +294 -0
- package/dist/rules/passthrough-handling.js.map +1 -0
- package/dist/rules/proxy-config.d.ts +76 -0
- package/dist/rules/proxy-config.d.ts.map +1 -0
- package/dist/rules/proxy-config.js +48 -0
- package/dist/rules/proxy-config.js.map +1 -0
- package/dist/rules/requests/request-handler-definitions.d.ts +600 -0
- package/dist/rules/requests/request-handler-definitions.d.ts.map +1 -0
- package/dist/rules/requests/request-handler-definitions.js +423 -0
- package/dist/rules/requests/request-handler-definitions.js.map +1 -0
- package/dist/rules/requests/request-handlers.d.ts +65 -0
- package/dist/rules/requests/request-handlers.d.ts.map +1 -0
- package/dist/rules/requests/request-handlers.js +1014 -0
- package/dist/rules/requests/request-handlers.js.map +1 -0
- package/dist/rules/requests/request-rule-builder.d.ts +255 -0
- package/dist/rules/requests/request-rule-builder.d.ts.map +1 -0
- package/dist/rules/requests/request-rule-builder.js +340 -0
- package/dist/rules/requests/request-rule-builder.js.map +1 -0
- package/dist/rules/requests/request-rule.d.ts +36 -0
- package/dist/rules/requests/request-rule.d.ts.map +1 -0
- package/dist/rules/requests/request-rule.js +100 -0
- package/dist/rules/requests/request-rule.js.map +1 -0
- package/dist/rules/rule-deserialization.d.ts +8 -0
- package/dist/rules/rule-deserialization.d.ts.map +1 -0
- package/dist/rules/rule-deserialization.js +27 -0
- package/dist/rules/rule-deserialization.js.map +1 -0
- package/dist/rules/rule-parameters.d.ts +21 -0
- package/dist/rules/rule-parameters.d.ts.map +1 -0
- package/dist/rules/rule-parameters.js +31 -0
- package/dist/rules/rule-parameters.js.map +1 -0
- package/dist/rules/rule-serialization.d.ts +7 -0
- package/dist/rules/rule-serialization.d.ts.map +1 -0
- package/dist/rules/rule-serialization.js +25 -0
- package/dist/rules/rule-serialization.js.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts +78 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.js +118 -0
- package/dist/rules/websockets/websocket-handler-definitions.js.map +1 -0
- package/dist/rules/websockets/websocket-handlers.d.ts +39 -0
- package/dist/rules/websockets/websocket-handlers.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handlers.js +356 -0
- package/dist/rules/websockets/websocket-handlers.js.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts +173 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.js +232 -0
- package/dist/rules/websockets/websocket-rule-builder.js.map +1 -0
- package/dist/rules/websockets/websocket-rule.d.ts +34 -0
- package/dist/rules/websockets/websocket-rule.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule.js +87 -0
- package/dist/rules/websockets/websocket-rule.js.map +1 -0
- package/dist/serialization/body-serialization.d.ts +43 -0
- package/dist/serialization/body-serialization.d.ts.map +1 -0
- package/dist/serialization/body-serialization.js +70 -0
- package/dist/serialization/body-serialization.js.map +1 -0
- package/dist/serialization/serialization.d.ts +63 -0
- package/dist/serialization/serialization.d.ts.map +1 -0
- package/dist/serialization/serialization.js +263 -0
- package/dist/serialization/serialization.js.map +1 -0
- package/dist/server/http-combo-server.d.ts +13 -0
- package/dist/server/http-combo-server.d.ts.map +1 -0
- package/dist/server/http-combo-server.js +330 -0
- package/dist/server/http-combo-server.js.map +1 -0
- package/dist/server/mocked-endpoint.d.ts +14 -0
- package/dist/server/mocked-endpoint.d.ts.map +1 -0
- package/dist/server/mocked-endpoint.js +40 -0
- package/dist/server/mocked-endpoint.js.map +1 -0
- package/dist/server/mockttp-server.d.ts +87 -0
- package/dist/server/mockttp-server.d.ts.map +1 -0
- package/dist/server/mockttp-server.js +859 -0
- package/dist/server/mockttp-server.js.map +1 -0
- package/dist/types.d.ts +359 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/util/buffer-utils.d.ts +13 -0
- package/dist/util/buffer-utils.d.ts.map +1 -0
- package/dist/util/buffer-utils.js +141 -0
- package/dist/util/buffer-utils.js.map +1 -0
- package/dist/util/dns.d.ts +11 -0
- package/dist/util/dns.d.ts.map +1 -0
- package/dist/util/dns.js +47 -0
- package/dist/util/dns.js.map +1 -0
- package/dist/util/error.d.ts +9 -0
- package/dist/util/error.d.ts.map +1 -0
- package/dist/util/error.js +11 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/header-utils.d.ts +35 -0
- package/dist/util/header-utils.d.ts.map +1 -0
- package/dist/util/header-utils.js +200 -0
- package/dist/util/header-utils.js.map +1 -0
- package/dist/util/openssl-compat.d.ts +2 -0
- package/dist/util/openssl-compat.d.ts.map +1 -0
- package/dist/util/openssl-compat.js +26 -0
- package/dist/util/openssl-compat.js.map +1 -0
- package/dist/util/promise.d.ts +10 -0
- package/dist/util/promise.d.ts.map +1 -0
- package/dist/util/promise.js +25 -0
- package/dist/util/promise.js.map +1 -0
- package/dist/util/request-utils.d.ts +46 -0
- package/dist/util/request-utils.d.ts.map +1 -0
- package/dist/util/request-utils.js +462 -0
- package/dist/util/request-utils.js.map +1 -0
- package/dist/util/server-utils.d.ts +2 -0
- package/dist/util/server-utils.d.ts.map +1 -0
- package/dist/util/server-utils.js +14 -0
- package/dist/util/server-utils.js.map +1 -0
- package/dist/util/socket-util.d.ts +28 -0
- package/dist/util/socket-util.d.ts.map +1 -0
- package/dist/util/socket-util.js +174 -0
- package/dist/util/socket-util.js.map +1 -0
- package/dist/util/tls.d.ts +68 -0
- package/dist/util/tls.d.ts.map +1 -0
- package/dist/util/tls.js +220 -0
- package/dist/util/tls.js.map +1 -0
- package/dist/util/type-utils.d.ts +14 -0
- package/dist/util/type-utils.d.ts.map +1 -0
- package/dist/util/type-utils.js +3 -0
- package/dist/util/type-utils.js.map +1 -0
- package/dist/util/url.d.ts +17 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/util/url.js +96 -0
- package/dist/util/url.js.map +1 -0
- package/dist/util/util.d.ts +8 -0
- package/dist/util/util.d.ts.map +1 -0
- package/dist/util/util.js +41 -0
- package/dist/util/util.js.map +1 -0
- package/docs/api-docs-landing-page.md +11 -0
- package/docs/runkitExample.js +16 -0
- package/docs/setup.md +136 -0
- package/nfyb8qx5.cjs +1 -0
- package/package.json +194 -4
- package/src/admin/admin-bin.ts +62 -0
- package/src/admin/admin-plugin-types.ts +29 -0
- package/src/admin/admin-server.ts +619 -0
- package/src/admin/graphql-utils.ts +28 -0
- package/src/admin/mockttp-admin-model.ts +264 -0
- package/src/admin/mockttp-admin-plugin.ts +59 -0
- package/src/admin/mockttp-admin-server.ts +27 -0
- package/src/admin/mockttp-schema.ts +222 -0
- package/src/client/admin-client.ts +652 -0
- package/src/client/admin-query.ts +52 -0
- package/src/client/mocked-endpoint-client.ts +32 -0
- package/src/client/mockttp-admin-request-builder.ts +540 -0
- package/src/client/mockttp-client.ts +178 -0
- package/src/client/schema-introspection.ts +131 -0
- package/src/main.browser.ts +60 -0
- package/src/main.ts +160 -0
- package/src/mockttp.ts +926 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.browser.ts +7 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.ts +13 -0
- package/src/pluggable-admin-api/pluggable-admin.browser.ts +9 -0
- package/src/pluggable-admin-api/pluggable-admin.ts +36 -0
- package/src/rules/base-rule-builder.ts +312 -0
- package/src/rules/completion-checkers.ts +90 -0
- package/src/rules/http-agents.ts +119 -0
- package/src/rules/matchers.ts +665 -0
- package/src/rules/passthrough-handling-definitions.ts +111 -0
- package/src/rules/passthrough-handling.ts +376 -0
- package/src/rules/proxy-config.ts +136 -0
- package/src/rules/requests/request-handler-definitions.ts +1089 -0
- package/src/rules/requests/request-handlers.ts +1369 -0
- package/src/rules/requests/request-rule-builder.ts +481 -0
- package/src/rules/requests/request-rule.ts +148 -0
- package/src/rules/rule-deserialization.ts +55 -0
- package/src/rules/rule-parameters.ts +41 -0
- package/src/rules/rule-serialization.ts +29 -0
- package/src/rules/websockets/websocket-handler-definitions.ts +196 -0
- package/src/rules/websockets/websocket-handlers.ts +509 -0
- package/src/rules/websockets/websocket-rule-builder.ts +275 -0
- package/src/rules/websockets/websocket-rule.ts +136 -0
- package/src/serialization/body-serialization.ts +84 -0
- package/src/serialization/serialization.ts +373 -0
- package/src/server/http-combo-server.ts +424 -0
- package/src/server/mocked-endpoint.ts +44 -0
- package/src/server/mockttp-server.ts +1110 -0
- package/src/types.ts +433 -0
- package/src/util/buffer-utils.ts +164 -0
- package/src/util/dns.ts +52 -0
- package/src/util/error.ts +18 -0
- package/src/util/header-utils.ts +220 -0
- package/src/util/openssl-compat.ts +26 -0
- package/src/util/promise.ts +31 -0
- package/src/util/request-utils.ts +607 -0
- package/src/util/server-utils.ts +18 -0
- package/src/util/socket-util.ts +193 -0
- package/src/util/tls.ts +348 -0
- package/src/util/type-utils.ts +15 -0
- package/src/util/url.ts +113 -0
- package/src/util/util.ts +39 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { MockedEndpoint, Headers } from "../../types";
|
|
2
|
+
import type { WebSocketRuleData } from "./websocket-rule";
|
|
3
|
+
import { PassThroughWebSocketHandlerOptions } from './websocket-handler-definitions';
|
|
4
|
+
import { BaseRuleBuilder } from "../base-rule-builder";
|
|
5
|
+
/**
|
|
6
|
+
* @class WebSocketRuleBuilder
|
|
7
|
+
|
|
8
|
+
* A builder for defining websocket mock rules. Create one using
|
|
9
|
+
* `.forAnyWebSocket(path)` on a Mockttp instance, then call whatever
|
|
10
|
+
* methods you'd like here to define more precise matching behaviour,
|
|
11
|
+
* control how the connection is handled, and how many times this
|
|
12
|
+
* rule should be applied.
|
|
13
|
+
*
|
|
14
|
+
* When you're done, call a `.thenX()` method to register the configured rule
|
|
15
|
+
* with the server. These return a promise for a MockedEndpoint, which can be
|
|
16
|
+
* used to verify the details of the requests matched by the rule.
|
|
17
|
+
*
|
|
18
|
+
* This returns a promise because rule registration can be asynchronous,
|
|
19
|
+
* either when using a remote server or testing in the browser. Wait for the
|
|
20
|
+
* promise returned by `.thenX()` methods to guarantee that the rule has taken
|
|
21
|
+
* effect before sending requests to it.
|
|
22
|
+
*/
|
|
23
|
+
export declare class WebSocketRuleBuilder extends BaseRuleBuilder {
|
|
24
|
+
private addRule;
|
|
25
|
+
/**
|
|
26
|
+
* Mock rule builders should be constructed through the Mockttp instance you're
|
|
27
|
+
* using, not directly. You shouldn't ever need to call this constructor.
|
|
28
|
+
*/
|
|
29
|
+
constructor(addRule: (rule: WebSocketRuleData) => Promise<MockedEndpoint>);
|
|
30
|
+
/**
|
|
31
|
+
* Pass matched websockets through to their real destination. This works
|
|
32
|
+
* for proxied requests only, and direct requests will be rejected with
|
|
33
|
+
* an error.
|
|
34
|
+
*
|
|
35
|
+
* This method takes options to configure how the request is passed
|
|
36
|
+
* through. See {@link PassThroughWebSocketHandlerOptions} for the full
|
|
37
|
+
* details of the options available.
|
|
38
|
+
*
|
|
39
|
+
* Calling this method registers the rule with the server, so it
|
|
40
|
+
* starts to handle requests.
|
|
41
|
+
*
|
|
42
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
43
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
44
|
+
* before sending requests to be matched. The mocked endpoint
|
|
45
|
+
* can be used to assert on the requests matched by this rule.
|
|
46
|
+
*
|
|
47
|
+
* @category Responses
|
|
48
|
+
*/
|
|
49
|
+
thenPassThrough(options?: PassThroughWebSocketHandlerOptions): Promise<MockedEndpoint>;
|
|
50
|
+
/**
|
|
51
|
+
* Forward matched websockets on to the specified forwardToUrl. The url
|
|
52
|
+
* specified must not include a path or an error will be thrown.
|
|
53
|
+
* The path portion of the original request url is used instead.
|
|
54
|
+
*
|
|
55
|
+
* The url may optionally contain a protocol. If it does, it will override
|
|
56
|
+
* the protocol (and potentially the port, if unspecified) of the request.
|
|
57
|
+
* If no protocol is specified, the protocol (and potentially the port)
|
|
58
|
+
* of the original request URL will be used instead.
|
|
59
|
+
*
|
|
60
|
+
* This method takes options to configure how the request is passed
|
|
61
|
+
* through. See {@link PassThroughWebSocketHandlerOptions} for the full
|
|
62
|
+
* details of the options available.
|
|
63
|
+
*
|
|
64
|
+
* Calling this method registers the rule with the server, so it
|
|
65
|
+
* starts to handle requests.
|
|
66
|
+
*
|
|
67
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
68
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
69
|
+
* before sending requests to be matched. The mocked endpoint
|
|
70
|
+
* can be used to assert on the requests matched by this rule.
|
|
71
|
+
*
|
|
72
|
+
* @category Responses
|
|
73
|
+
*/
|
|
74
|
+
thenForwardTo(forwardToLocation: string, options?: Omit<PassThroughWebSocketHandlerOptions, 'forwarding'> & {
|
|
75
|
+
forwarding?: Omit<PassThroughWebSocketHandlerOptions['forwarding'], 'targetHost'>;
|
|
76
|
+
}): Promise<MockedEndpoint>;
|
|
77
|
+
/**
|
|
78
|
+
* Accept incoming WebSocket connections, and echo every message
|
|
79
|
+
* received on the WebSocket back to the client.
|
|
80
|
+
*
|
|
81
|
+
* Calling this method registers the rule with the server, so it
|
|
82
|
+
* starts to handle requests.
|
|
83
|
+
*
|
|
84
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
85
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
86
|
+
* before sending requests to be matched. The mocked endpoint
|
|
87
|
+
* can be used to assert on the requests matched by this rule.
|
|
88
|
+
*
|
|
89
|
+
* @category Responses
|
|
90
|
+
*/
|
|
91
|
+
thenEcho(): Promise<MockedEndpoint>;
|
|
92
|
+
/**
|
|
93
|
+
* Accept incoming WebSocket connections, and simply listen to
|
|
94
|
+
* incoming messages without ever sending anything in return.
|
|
95
|
+
*
|
|
96
|
+
* Calling this method registers the rule with the server, so it
|
|
97
|
+
* starts to handle requests.
|
|
98
|
+
*
|
|
99
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
100
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
101
|
+
* before sending requests to be matched. The mocked endpoint
|
|
102
|
+
* can be used to assert on the requests matched by this rule.
|
|
103
|
+
*
|
|
104
|
+
* @category Responses
|
|
105
|
+
*/
|
|
106
|
+
thenPassivelyListen(): Promise<MockedEndpoint>;
|
|
107
|
+
/**
|
|
108
|
+
* Rejects connections, sending an HTTP response with the given
|
|
109
|
+
* status, message and body, to explicitly refuse the WebSocket
|
|
110
|
+
* handshake.
|
|
111
|
+
*
|
|
112
|
+
* Calling this method registers the rule with the server, so it
|
|
113
|
+
* starts to handle requests.
|
|
114
|
+
*
|
|
115
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
116
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
117
|
+
* before sending requests to be matched. The mocked endpoint
|
|
118
|
+
* can be used to assert on the requests matched by this rule.
|
|
119
|
+
*
|
|
120
|
+
* @category Responses
|
|
121
|
+
*/
|
|
122
|
+
thenRejectConnection(statusCode: number, statusMessage?: string, headers?: Headers, body?: Buffer | string): Promise<MockedEndpoint>;
|
|
123
|
+
/**
|
|
124
|
+
* Close connections that match this rule immediately, without accepting
|
|
125
|
+
* the socket or sending any other response.
|
|
126
|
+
*
|
|
127
|
+
* Calling this method registers the rule with the server, so it
|
|
128
|
+
* starts to handle requests.
|
|
129
|
+
*
|
|
130
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
131
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
132
|
+
* before sending requests to be matched. The mocked endpoint
|
|
133
|
+
* can be used to assert on the requests matched by this rule.
|
|
134
|
+
*
|
|
135
|
+
* @category Responses
|
|
136
|
+
*/
|
|
137
|
+
thenCloseConnection(): Promise<MockedEndpoint>;
|
|
138
|
+
/**
|
|
139
|
+
* Reset connections that match this rule immediately, sending a TCP
|
|
140
|
+
* RST packet directly, without accepting the socket or sending any
|
|
141
|
+
* other response, and without cleanly closing the TCP connection.
|
|
142
|
+
*
|
|
143
|
+
* This is only supported in Node.js versions (>=16.17, >=18.3.0, or
|
|
144
|
+
* later), where `net.Socket` includes the `resetAndDestroy` method.
|
|
145
|
+
*
|
|
146
|
+
* Calling this method registers the rule with the server, so it
|
|
147
|
+
* starts to handle requests.
|
|
148
|
+
*
|
|
149
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
150
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
151
|
+
* before sending requests to be matched. The mocked endpoint
|
|
152
|
+
* can be used to assert on the requests matched by this rule.
|
|
153
|
+
*
|
|
154
|
+
* @category Responses
|
|
155
|
+
*/
|
|
156
|
+
thenResetConnection(): Promise<MockedEndpoint>;
|
|
157
|
+
/**
|
|
158
|
+
* Hold open connections that match this rule, but never respond
|
|
159
|
+
* with anything at all, typically causing a timeout on the client side.
|
|
160
|
+
*
|
|
161
|
+
* Calling this method registers the rule with the server, so it
|
|
162
|
+
* starts to handle requests.
|
|
163
|
+
*
|
|
164
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
165
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
166
|
+
* before sending requests to be matched. The mocked endpoint
|
|
167
|
+
* can be used to assert on the requests matched by this rule.
|
|
168
|
+
*
|
|
169
|
+
* @category Responses
|
|
170
|
+
*/
|
|
171
|
+
thenTimeout(): Promise<MockedEndpoint>;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=websocket-rule-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-rule-builder.d.ts","sourceRoot":"","sources":["../../../src/rules/websockets/websocket-rule-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAKH,kCAAkC,EAIrC,MAAM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|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketRuleBuilder = void 0;
|
|
4
|
+
const websocket_handler_definitions_1 = require("./websocket-handler-definitions");
|
|
5
|
+
const base_rule_builder_1 = require("../base-rule-builder");
|
|
6
|
+
const matchers_1 = require("../matchers");
|
|
7
|
+
/**
|
|
8
|
+
* @class WebSocketRuleBuilder
|
|
9
|
+
|
|
10
|
+
* A builder for defining websocket mock rules. Create one using
|
|
11
|
+
* `.forAnyWebSocket(path)` on a Mockttp instance, then call whatever
|
|
12
|
+
* methods you'd like here to define more precise matching behaviour,
|
|
13
|
+
* control how the connection is handled, and how many times this
|
|
14
|
+
* rule should be applied.
|
|
15
|
+
*
|
|
16
|
+
* When you're done, call a `.thenX()` method to register the configured rule
|
|
17
|
+
* with the server. These return a promise for a MockedEndpoint, which can be
|
|
18
|
+
* used to verify the details of the requests matched by the rule.
|
|
19
|
+
*
|
|
20
|
+
* This returns a promise because rule registration can be asynchronous,
|
|
21
|
+
* either when using a remote server or testing in the browser. Wait for the
|
|
22
|
+
* promise returned by `.thenX()` methods to guarantee that the rule has taken
|
|
23
|
+
* effect before sending requests to it.
|
|
24
|
+
*/
|
|
25
|
+
class WebSocketRuleBuilder extends base_rule_builder_1.BaseRuleBuilder {
|
|
26
|
+
/**
|
|
27
|
+
* Mock rule builders should be constructed through the Mockttp instance you're
|
|
28
|
+
* using, not directly. You shouldn't ever need to call this constructor.
|
|
29
|
+
*/
|
|
30
|
+
constructor(addRule) {
|
|
31
|
+
super();
|
|
32
|
+
this.addRule = addRule;
|
|
33
|
+
// By default, websockets just match everything:
|
|
34
|
+
this.matchers.push(new matchers_1.WildcardMatcher());
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Pass matched websockets through to their real destination. This works
|
|
38
|
+
* for proxied requests only, and direct requests will be rejected with
|
|
39
|
+
* an error.
|
|
40
|
+
*
|
|
41
|
+
* This method takes options to configure how the request is passed
|
|
42
|
+
* through. See {@link PassThroughWebSocketHandlerOptions} for the full
|
|
43
|
+
* details of the options available.
|
|
44
|
+
*
|
|
45
|
+
* Calling this method registers the rule with the server, so it
|
|
46
|
+
* starts to handle requests.
|
|
47
|
+
*
|
|
48
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
49
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
50
|
+
* before sending requests to be matched. The mocked endpoint
|
|
51
|
+
* can be used to assert on the requests matched by this rule.
|
|
52
|
+
*
|
|
53
|
+
* @category Responses
|
|
54
|
+
*/
|
|
55
|
+
thenPassThrough(options = {}) {
|
|
56
|
+
const rule = {
|
|
57
|
+
...this.buildBaseRuleData(),
|
|
58
|
+
handler: new websocket_handler_definitions_1.PassThroughWebSocketHandlerDefinition(options)
|
|
59
|
+
};
|
|
60
|
+
return this.addRule(rule);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Forward matched websockets on to the specified forwardToUrl. The url
|
|
64
|
+
* specified must not include a path or an error will be thrown.
|
|
65
|
+
* The path portion of the original request url is used instead.
|
|
66
|
+
*
|
|
67
|
+
* The url may optionally contain a protocol. If it does, it will override
|
|
68
|
+
* the protocol (and potentially the port, if unspecified) of the request.
|
|
69
|
+
* If no protocol is specified, the protocol (and potentially the port)
|
|
70
|
+
* of the original request URL will be used instead.
|
|
71
|
+
*
|
|
72
|
+
* This method takes options to configure how the request is passed
|
|
73
|
+
* through. See {@link PassThroughWebSocketHandlerOptions} for the full
|
|
74
|
+
* details of the options available.
|
|
75
|
+
*
|
|
76
|
+
* Calling this method registers the rule with the server, so it
|
|
77
|
+
* starts to handle requests.
|
|
78
|
+
*
|
|
79
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
80
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
81
|
+
* before sending requests to be matched. The mocked endpoint
|
|
82
|
+
* can be used to assert on the requests matched by this rule.
|
|
83
|
+
*
|
|
84
|
+
* @category Responses
|
|
85
|
+
*/
|
|
86
|
+
async thenForwardTo(forwardToLocation, options = {}) {
|
|
87
|
+
const rule = {
|
|
88
|
+
...this.buildBaseRuleData(),
|
|
89
|
+
handler: new websocket_handler_definitions_1.PassThroughWebSocketHandlerDefinition({
|
|
90
|
+
...options,
|
|
91
|
+
forwarding: {
|
|
92
|
+
...options.forwarding,
|
|
93
|
+
targetHost: forwardToLocation
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
return this.addRule(rule);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Accept incoming WebSocket connections, and echo every message
|
|
101
|
+
* received on the WebSocket back to the client.
|
|
102
|
+
*
|
|
103
|
+
* Calling this method registers the rule with the server, so it
|
|
104
|
+
* starts to handle requests.
|
|
105
|
+
*
|
|
106
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
107
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
108
|
+
* before sending requests to be matched. The mocked endpoint
|
|
109
|
+
* can be used to assert on the requests matched by this rule.
|
|
110
|
+
*
|
|
111
|
+
* @category Responses
|
|
112
|
+
*/
|
|
113
|
+
thenEcho() {
|
|
114
|
+
const rule = {
|
|
115
|
+
...this.buildBaseRuleData(),
|
|
116
|
+
handler: new websocket_handler_definitions_1.EchoWebSocketHandlerDefinition()
|
|
117
|
+
};
|
|
118
|
+
return this.addRule(rule);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Accept incoming WebSocket connections, and simply listen to
|
|
122
|
+
* incoming messages without ever sending anything in return.
|
|
123
|
+
*
|
|
124
|
+
* Calling this method registers the rule with the server, so it
|
|
125
|
+
* starts to handle requests.
|
|
126
|
+
*
|
|
127
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
128
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
129
|
+
* before sending requests to be matched. The mocked endpoint
|
|
130
|
+
* can be used to assert on the requests matched by this rule.
|
|
131
|
+
*
|
|
132
|
+
* @category Responses
|
|
133
|
+
*/
|
|
134
|
+
thenPassivelyListen() {
|
|
135
|
+
const rule = {
|
|
136
|
+
...this.buildBaseRuleData(),
|
|
137
|
+
handler: new websocket_handler_definitions_1.ListenWebSocketHandlerDefinition()
|
|
138
|
+
};
|
|
139
|
+
return this.addRule(rule);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Rejects connections, sending an HTTP response with the given
|
|
143
|
+
* status, message and body, to explicitly refuse the WebSocket
|
|
144
|
+
* handshake.
|
|
145
|
+
*
|
|
146
|
+
* Calling this method registers the rule with the server, so it
|
|
147
|
+
* starts to handle requests.
|
|
148
|
+
*
|
|
149
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
150
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
151
|
+
* before sending requests to be matched. The mocked endpoint
|
|
152
|
+
* can be used to assert on the requests matched by this rule.
|
|
153
|
+
*
|
|
154
|
+
* @category Responses
|
|
155
|
+
*/
|
|
156
|
+
thenRejectConnection(statusCode, statusMessage, headers, body) {
|
|
157
|
+
const rule = {
|
|
158
|
+
...this.buildBaseRuleData(),
|
|
159
|
+
handler: new websocket_handler_definitions_1.RejectWebSocketHandlerDefinition(statusCode, statusMessage, headers, body)
|
|
160
|
+
};
|
|
161
|
+
return this.addRule(rule);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Close connections that match this rule immediately, without accepting
|
|
165
|
+
* the socket or sending any other response.
|
|
166
|
+
*
|
|
167
|
+
* Calling this method registers the rule with the server, so it
|
|
168
|
+
* starts to handle requests.
|
|
169
|
+
*
|
|
170
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
171
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
172
|
+
* before sending requests to be matched. The mocked endpoint
|
|
173
|
+
* can be used to assert on the requests matched by this rule.
|
|
174
|
+
*
|
|
175
|
+
* @category Responses
|
|
176
|
+
*/
|
|
177
|
+
thenCloseConnection() {
|
|
178
|
+
const rule = {
|
|
179
|
+
...this.buildBaseRuleData(),
|
|
180
|
+
handler: new websocket_handler_definitions_1.CloseConnectionHandlerDefinition()
|
|
181
|
+
};
|
|
182
|
+
return this.addRule(rule);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Reset connections that match this rule immediately, sending a TCP
|
|
186
|
+
* RST packet directly, without accepting the socket or sending any
|
|
187
|
+
* other response, and without cleanly closing the TCP connection.
|
|
188
|
+
*
|
|
189
|
+
* This is only supported in Node.js versions (>=16.17, >=18.3.0, or
|
|
190
|
+
* later), where `net.Socket` includes the `resetAndDestroy` method.
|
|
191
|
+
*
|
|
192
|
+
* Calling this method registers the rule with the server, so it
|
|
193
|
+
* starts to handle requests.
|
|
194
|
+
*
|
|
195
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
196
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
197
|
+
* before sending requests to be matched. The mocked endpoint
|
|
198
|
+
* can be used to assert on the requests matched by this rule.
|
|
199
|
+
*
|
|
200
|
+
* @category Responses
|
|
201
|
+
*/
|
|
202
|
+
thenResetConnection() {
|
|
203
|
+
const rule = {
|
|
204
|
+
...this.buildBaseRuleData(),
|
|
205
|
+
handler: new websocket_handler_definitions_1.ResetConnectionHandlerDefinition()
|
|
206
|
+
};
|
|
207
|
+
return this.addRule(rule);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Hold open connections that match this rule, but never respond
|
|
211
|
+
* with anything at all, typically causing a timeout on the client side.
|
|
212
|
+
*
|
|
213
|
+
* Calling this method registers the rule with the server, so it
|
|
214
|
+
* starts to handle requests.
|
|
215
|
+
*
|
|
216
|
+
* This method returns a promise that resolves with a mocked endpoint.
|
|
217
|
+
* Wait for the promise to confirm that the rule has taken effect
|
|
218
|
+
* before sending requests to be matched. The mocked endpoint
|
|
219
|
+
* can be used to assert on the requests matched by this rule.
|
|
220
|
+
*
|
|
221
|
+
* @category Responses
|
|
222
|
+
*/
|
|
223
|
+
thenTimeout() {
|
|
224
|
+
const rule = {
|
|
225
|
+
...this.buildBaseRuleData(),
|
|
226
|
+
handler: new websocket_handler_definitions_1.TimeoutHandlerDefinition()
|
|
227
|
+
};
|
|
228
|
+
return this.addRule(rule);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.WebSocketRuleBuilder = WebSocketRuleBuilder;
|
|
232
|
+
//# sourceMappingURL=websocket-rule-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-rule-builder.js","sourceRoot":"","sources":["../../../src/rules/websockets/websocket-rule-builder.ts"],"names":[],"mappings":";;;AAGA,mFASyC;AAEzC,4DAAuD;AACvD,0CAA8C;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,oBAAqB,SAAQ,mCAAe;IAErD;;;OAGG;IACH,YACY,OAA6D;QAErE,KAAK,EAAE,CAAC;QAFA,YAAO,GAAP,OAAO,CAAsD;QAIrE,gDAAgD;QAChD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,0BAAe,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,eAAe,CAAC,UAA8C,EAAE;QAC5D,MAAM,IAAI,GAAsB;YAC5B,GAAG,IAAI,CAAC,iBAAiB,EAAE;YAC3B,OAAO,EAAE,IAAI,qEAAqC,CAAC,OAAO,CAAC;SAC9D,CAAC;QAEF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,aAAa,CACf,iBAAyB,EACzB,UAEI,EAAE;QAEN,MAAM,IAAI,GAAsB;YAC5B,GAAG,IAAI,CAAC,iBAAiB,EAAE;YAC3B,OAAO,EAAE,IAAI,qEAAqC,CAAC;gBAC/C,GAAG,OAAO;gBACV,UAAU,EAAE;oBACR,GAAG,OAAO,CAAC,UAAU;oBACrB,UAAU,EAAE,iBAAiB;iBAChC;aACJ,CAAC;SACL,CAA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,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,WAAW;QACP,MAAM,IAAI,GAAsB;YAC5B,GAAG,IAAI,CAAC,iBAAiB,EAAE;YAC3B,OAAO,EAAE,IAAI,wDAAwB,EAAE;SAC1C,CAAC;QAEF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACJ;AA/OD,oDA+OC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
import { OngoingRequest, CompletedRequest, Explainable } from "../../types";
|
|
3
|
+
import { MaybePromise } from '../../util/type-utils';
|
|
4
|
+
import * as matchers from "../matchers";
|
|
5
|
+
import * as completionCheckers from "../completion-checkers";
|
|
6
|
+
import { WebSocketHandler } from "./websocket-handlers";
|
|
7
|
+
import type { WebSocketHandlerDefinition } from "./websocket-handler-definitions";
|
|
8
|
+
export interface WebSocketRule extends Explainable {
|
|
9
|
+
id: string;
|
|
10
|
+
requests: Promise<CompletedRequest>[];
|
|
11
|
+
matches(request: OngoingRequest): MaybePromise<boolean>;
|
|
12
|
+
handle(request: OngoingRequest, response: net.Socket, head: Buffer, record: boolean): Promise<void>;
|
|
13
|
+
isComplete(): boolean | null;
|
|
14
|
+
}
|
|
15
|
+
export interface WebSocketRuleData {
|
|
16
|
+
id?: string;
|
|
17
|
+
priority?: number;
|
|
18
|
+
matchers: matchers.RequestMatcher[];
|
|
19
|
+
handler: WebSocketHandler | WebSocketHandlerDefinition;
|
|
20
|
+
completionChecker?: completionCheckers.RuleCompletionChecker;
|
|
21
|
+
}
|
|
22
|
+
export declare class WebSocketRule implements WebSocketRule {
|
|
23
|
+
private matchers;
|
|
24
|
+
private handler;
|
|
25
|
+
private completionChecker?;
|
|
26
|
+
id: string;
|
|
27
|
+
readonly priority: number;
|
|
28
|
+
requests: Promise<CompletedRequest>[];
|
|
29
|
+
requestCount: number;
|
|
30
|
+
constructor(data: WebSocketRuleData);
|
|
31
|
+
explain(withoutExactCompletion?: boolean): string;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=websocket-rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-rule.d.ts","sourceRoot":"","sources":["../../../src/rules/websockets/websocket-rule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAG3B,OAAO,EACH,cAAc,EACd,gBAAgB,EAChB,WAAW,EAEd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,kBAAkB,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,sBAAsB,CAAC;AACzE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAGlF,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;IAGtC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpG,UAAU,IAAI,OAAO,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC;IACpC,OAAO,EAAE,gBAAgB,GAAG,0BAA0B,CAAC;IACvD,iBAAiB,CAAC,EAAE,kBAAkB,CAAC,qBAAqB,CAAC;CAChE;AAED,qBAAa,aAAc,YAAW,aAAa;IAC/C,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,iBAAiB,CAAC,CAA2C;IAE9D,EAAE,EAAE,MAAM,CAAC;IAClB,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAM;IAC3C,YAAY,SAAK;gBAEZ,IAAI,EAAE,iBAAiB;IAiEnC,OAAO,CAAC,sBAAsB,UAAQ,GAAG,MAAM;IAe/C,OAAO;CAKV"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketRule = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const request_utils_1 = require("../../util/request-utils");
|
|
7
|
+
const rule_serialization_1 = require("../rule-serialization");
|
|
8
|
+
const matchers = require("../matchers");
|
|
9
|
+
const websocket_handlers_1 = require("./websocket-handlers");
|
|
10
|
+
class WebSocketRule {
|
|
11
|
+
constructor(data) {
|
|
12
|
+
this.requests = [];
|
|
13
|
+
this.requestCount = 0;
|
|
14
|
+
(0, rule_serialization_1.validateMockRuleData)(data);
|
|
15
|
+
this.id = data.id || (0, uuid_1.v4)();
|
|
16
|
+
this.priority = data.priority ?? types_1.RulePriority.DEFAULT;
|
|
17
|
+
this.matchers = data.matchers;
|
|
18
|
+
if ('handle' in data.handler) {
|
|
19
|
+
this.handler = data.handler;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// We transform the definition into a real handler, by creating an raw instance of the handler (which is
|
|
23
|
+
// a subtype of the definition with the same constructor) and copying the fields across.
|
|
24
|
+
this.handler = Object.assign(Object.create(websocket_handlers_1.WsHandlerLookup[data.handler.type].prototype), data.handler);
|
|
25
|
+
}
|
|
26
|
+
this.completionChecker = data.completionChecker;
|
|
27
|
+
}
|
|
28
|
+
matches(request) {
|
|
29
|
+
return matchers.matchesAll(request, this.matchers);
|
|
30
|
+
}
|
|
31
|
+
handle(req, res, head, record) {
|
|
32
|
+
let handlerPromise = (async () => {
|
|
33
|
+
return this.handler.handle(req, res, head);
|
|
34
|
+
})();
|
|
35
|
+
// Requests are added to rule.requests as soon as they start being handled,
|
|
36
|
+
// as promises, which resolve only when the response & request body is complete.
|
|
37
|
+
if (record) {
|
|
38
|
+
this.requests.push(Promise.race([
|
|
39
|
+
// When the handler resolves, the request is completed:
|
|
40
|
+
handlerPromise,
|
|
41
|
+
// If the response is closed before the handler completes (due to aborts, handler
|
|
42
|
+
// timeouts, whatever) then that also counts as the request being completed:
|
|
43
|
+
new Promise((resolve) => res.on('close', resolve))
|
|
44
|
+
])
|
|
45
|
+
.catch(() => { }) // Ignore handler errors here - we're only tracking the request
|
|
46
|
+
.then(() => (0, request_utils_1.waitForCompletedRequest)(req)));
|
|
47
|
+
}
|
|
48
|
+
// Even if traffic recording is disabled, the number of matched
|
|
49
|
+
// requests is still tracked
|
|
50
|
+
this.requestCount += 1;
|
|
51
|
+
return handlerPromise;
|
|
52
|
+
}
|
|
53
|
+
isComplete() {
|
|
54
|
+
if (this.completionChecker) {
|
|
55
|
+
// If we have a specific rule, use that
|
|
56
|
+
return this.completionChecker.isComplete(this.requestCount);
|
|
57
|
+
}
|
|
58
|
+
else if (this.requestCount === 0) {
|
|
59
|
+
// Otherwise, by default we're definitely incomplete if we've seen no requests
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// And we're _maybe_ complete if we've seen at least one request. In reality, we're incomplete
|
|
64
|
+
// but we should be used anyway if we're at any point we're the last matching rule for a request.
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
explain(withoutExactCompletion = false) {
|
|
69
|
+
let explanation = `Match websockets ${matchers.explainMatchers(this.matchers)}, ` +
|
|
70
|
+
`and then ${this.handler.explain()}`;
|
|
71
|
+
if (this.completionChecker) {
|
|
72
|
+
explanation += `, ${this.completionChecker.explain(withoutExactCompletion ? undefined : this.requestCount)}.`;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
explanation += '.';
|
|
76
|
+
}
|
|
77
|
+
return explanation;
|
|
78
|
+
}
|
|
79
|
+
dispose() {
|
|
80
|
+
this.handler.dispose();
|
|
81
|
+
this.matchers.forEach(m => m.dispose());
|
|
82
|
+
if (this.completionChecker)
|
|
83
|
+
this.completionChecker.dispose();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.WebSocketRule = WebSocketRule;
|
|
87
|
+
//# sourceMappingURL=websocket-rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-rule.js","sourceRoot":"","sources":["../../../src/rules/websockets/websocket-rule.ts"],"names":[],"mappings":";;;AACA,+BAAkC;AAIlC,uCAKqB;AACrB,4DAAmE;AAGnE,8DAA6D;AAE7D,wCAAwC;AAExC,6DAAyE;AAsBzE,MAAa,aAAa;IAUtB,YAAY,IAAuB;QAH5B,aAAQ,GAAgC,EAAE,CAAC;QAC3C,iBAAY,GAAG,CAAC,CAAC;QAGpB,IAAA,yCAAoB,EAAC,IAAI,CAAC,CAAC;QAE3B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,IAAA,SAAI,GAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,oBAAY,CAAC,OAAO,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ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IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,uCAAuC;YACvC,OAAO,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChE,CAAC;aAAM,IAAI,IAAI,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;YACjC,8EAA8E;YAC9E,OAAO,KAAK,CAAC;QACjB,CAAC;aAAM,CAAC;YACJ,8FAA8F;YAC9F,iGAAiG;YACjG,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,OAAO,CAAC,sBAAsB,GAAG,KAAK;QAClC,IAAI,WAAW,GAAG,oBAAoB,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;YACjF,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAErC,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,WAAW,IAAI,KAAK,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAC9C,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CACzD,GAAG,CAAC;QACT,CAAC;aAAM,CAAC;YACJ,WAAW,IAAI,GAAG,CAAC;QACvB,CAAC;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;IAED,OAAO;QACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,iBAAiB;YAAE,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;IACjE,CAAC;CACJ;AA/FD,sCA+FC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CompletedBody, Headers } from "../types";
|
|
2
|
+
import { Replace } from "../util/type-utils";
|
|
3
|
+
export declare function withSerializedBodyReader<T extends {
|
|
4
|
+
body: CompletedBody;
|
|
5
|
+
}>(input: T): Replace<T, {
|
|
6
|
+
body: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function withDeserializedBodyReader<T extends {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
body: CompletedBody;
|
|
11
|
+
}>(input: Replace<T, {
|
|
12
|
+
body: string;
|
|
13
|
+
}>): T;
|
|
14
|
+
/**
|
|
15
|
+
* Serialize a callback result (callback handlers, BeforeRequest/Response etc)
|
|
16
|
+
* to transform all the many possible buffer formats into either base64-encoded
|
|
17
|
+
* buffer data, or undefined.
|
|
18
|
+
*/
|
|
19
|
+
export declare function withSerializedCallbackBuffers<T extends {
|
|
20
|
+
body?: CompletedBody | Buffer | Uint8Array | ArrayBuffer | string;
|
|
21
|
+
rawBody?: Buffer | Uint8Array;
|
|
22
|
+
}>(input: T): Replace<T, {
|
|
23
|
+
body: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type WithSerializedCallbackBuffers<T extends {
|
|
26
|
+
body?: any;
|
|
27
|
+
}> = Replace<T, {
|
|
28
|
+
body?: string;
|
|
29
|
+
rawBody?: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Deserialize a callback result (callback handlers, BeforeRequest/Response etc)
|
|
33
|
+
* to build buffer data (or undefined) from the base64-serialized data
|
|
34
|
+
* produced by withSerializedCallbackBuffers
|
|
35
|
+
*/
|
|
36
|
+
export declare function withDeserializedCallbackBuffers<T extends {
|
|
37
|
+
body?: Buffer | Uint8Array | string;
|
|
38
|
+
rawBody?: Buffer | Uint8Array;
|
|
39
|
+
}>(input: Replace<T, {
|
|
40
|
+
body?: string;
|
|
41
|
+
rawBody?: string;
|
|
42
|
+
}>): T;
|
|
43
|
+
//# sourceMappingURL=body-serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-serialization.d.ts","sourceRoot":"","sources":["../../src/serialization/body-serialization.ts"],"names":[],"mappings":"AAGA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,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACvD,CAAC,CAUH"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withSerializedBodyReader = withSerializedBodyReader;
|
|
4
|
+
exports.withDeserializedBodyReader = withDeserializedBodyReader;
|
|
5
|
+
exports.withSerializedCallbackBuffers = withSerializedCallbackBuffers;
|
|
6
|
+
exports.withDeserializedCallbackBuffers = withDeserializedCallbackBuffers;
|
|
7
|
+
const _ = require("lodash");
|
|
8
|
+
const base64_arraybuffer_1 = require("base64-arraybuffer");
|
|
9
|
+
const buffer_utils_1 = require("../util/buffer-utils");
|
|
10
|
+
const request_utils_1 = require("../util/request-utils");
|
|
11
|
+
const serialization_1 = require("./serialization");
|
|
12
|
+
function withSerializedBodyReader(input) {
|
|
13
|
+
return {
|
|
14
|
+
...input,
|
|
15
|
+
body: (0, buffer_utils_1.asBuffer)(input.body.buffer).toString('base64')
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function withDeserializedBodyReader(input) {
|
|
19
|
+
return {
|
|
20
|
+
...input,
|
|
21
|
+
body: (0, request_utils_1.buildBodyReader)((0, serialization_1.deserializeBuffer)(input.body), input.headers)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Serialize a callback result (callback handlers, BeforeRequest/Response etc)
|
|
26
|
+
* to transform all the many possible buffer formats into either base64-encoded
|
|
27
|
+
* buffer data, or undefined.
|
|
28
|
+
*/
|
|
29
|
+
function withSerializedCallbackBuffers(input) {
|
|
30
|
+
let serializedBody;
|
|
31
|
+
if (!input.body) {
|
|
32
|
+
serializedBody = undefined;
|
|
33
|
+
}
|
|
34
|
+
else if (_.isString(input.body)) {
|
|
35
|
+
serializedBody = (0, serialization_1.serializeBuffer)((0, buffer_utils_1.asBuffer)(input.body));
|
|
36
|
+
}
|
|
37
|
+
else if (_.isBuffer(input.body)) {
|
|
38
|
+
serializedBody = (0, serialization_1.serializeBuffer)(input.body);
|
|
39
|
+
}
|
|
40
|
+
else if (_.isArrayBuffer(input.body) || _.isTypedArray(input.body)) {
|
|
41
|
+
serializedBody = (0, base64_arraybuffer_1.encode)(input.body);
|
|
42
|
+
}
|
|
43
|
+
else if ((0, request_utils_1.isMockttpBody)(input.body)) {
|
|
44
|
+
serializedBody = (0, serialization_1.serializeBuffer)((0, buffer_utils_1.asBuffer)(input.body.buffer));
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...input,
|
|
48
|
+
body: serializedBody,
|
|
49
|
+
rawBody: input.rawBody
|
|
50
|
+
? (0, serialization_1.serializeBuffer)((0, buffer_utils_1.asBuffer)(input.rawBody))
|
|
51
|
+
: undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Deserialize a callback result (callback handlers, BeforeRequest/Response etc)
|
|
56
|
+
* to build buffer data (or undefined) from the base64-serialized data
|
|
57
|
+
* produced by withSerializedCallbackBuffers
|
|
58
|
+
*/
|
|
59
|
+
function withDeserializedCallbackBuffers(input) {
|
|
60
|
+
return {
|
|
61
|
+
...input,
|
|
62
|
+
body: input.body !== undefined
|
|
63
|
+
? Buffer.from(input.body, 'base64')
|
|
64
|
+
: undefined,
|
|
65
|
+
rawBody: input.rawBody !== undefined
|
|
66
|
+
? Buffer.from(input.rawBody, 'base64')
|
|
67
|
+
: undefined
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=body-serialization.js.map
|