@stuntman/server 0.1.7 → 0.1.8
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/dist/api/api.d.ts +25 -0
- package/dist/api/api.d.ts.map +1 -0
- package/dist/api/api.js +212 -0
- package/dist/api/api.js.map +1 -0
- package/dist/api/utils.d.ts +5 -0
- package/dist/api/utils.d.ts.map +1 -0
- package/dist/api/utils.js +61 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/api/validators.d.ts +4 -0
- package/dist/api/validators.d.ts.map +1 -0
- package/dist/api/validators.js +125 -0
- package/dist/api/validators.js.map +1 -0
- package/dist/api/webgui/rules.pug +147 -0
- package/dist/api/webgui/style.css +28 -0
- package/dist/api/webgui/traffic.pug +38 -0
- package/dist/bin/stuntman.d.ts +3 -0
- package/dist/bin/stuntman.d.ts.map +1 -0
- package/dist/bin/stuntman.js +8 -0
- package/dist/bin/stuntman.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/ipUtils.d.ts +18 -0
- package/dist/ipUtils.d.ts.map +1 -0
- package/dist/ipUtils.js +102 -0
- package/dist/ipUtils.js.map +1 -0
- package/dist/mock.d.ts +32 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +306 -0
- package/dist/mock.js.map +1 -0
- package/dist/requestContext.d.ts +10 -0
- package/dist/requestContext.d.ts.map +1 -0
- package/dist/requestContext.js +19 -0
- package/dist/requestContext.js.map +1 -0
- package/dist/ruleExecutor.d.ts +23 -0
- package/dist/ruleExecutor.d.ts.map +1 -0
- package/dist/ruleExecutor.js +189 -0
- package/dist/ruleExecutor.js.map +1 -0
- package/dist/rules/catchAll.d.ts +3 -0
- package/dist/rules/catchAll.d.ts.map +1 -0
- package/dist/rules/catchAll.js +16 -0
- package/dist/rules/catchAll.js.map +1 -0
- package/dist/rules/echo.d.ts +3 -0
- package/dist/rules/echo.d.ts.map +1 -0
- package/dist/rules/echo.js +16 -0
- package/dist/rules/echo.js.map +1 -0
- package/dist/rules/index.d.ts +4 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +71 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +43 -0
- package/dist/storage.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
div#container {
|
|
2
|
+
resize: vertical;
|
|
3
|
+
overflow: auto;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
body {
|
|
7
|
+
font-family: Menlo, Monaco, 'Courier New', monospace;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
button.rule {
|
|
11
|
+
font-family: Menlo, Monaco, 'Courier New', monospace;
|
|
12
|
+
background: none !important;
|
|
13
|
+
border: none;
|
|
14
|
+
padding: 0 !important;
|
|
15
|
+
color: #aaa;
|
|
16
|
+
text-decoration: underline;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
margin-top: 10px;
|
|
19
|
+
font-size: x-small;
|
|
20
|
+
text-align: left;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ul.no-bullets {
|
|
24
|
+
list-style-type: none;
|
|
25
|
+
padding: 0;
|
|
26
|
+
margin: 0;
|
|
27
|
+
text-align: left;
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
doctype html
|
|
2
|
+
html
|
|
3
|
+
head
|
|
4
|
+
title Stuntman - rule editor
|
|
5
|
+
script(src='https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.35.0/min/vs/loader.min.js')
|
|
6
|
+
style
|
|
7
|
+
include style.css
|
|
8
|
+
body(style='color: rgb(204, 204, 204); background-color: rgb(50, 50, 50)')
|
|
9
|
+
div(style='width: 100%; overflow: hidden')
|
|
10
|
+
div(style='width: 200px; float: left')
|
|
11
|
+
h3 Traffic log
|
|
12
|
+
div(style='margin-left: 220px')
|
|
13
|
+
#container(style='height: 800px')
|
|
14
|
+
script.
|
|
15
|
+
/* eslint no-undef: 0 */
|
|
16
|
+
require.config({
|
|
17
|
+
paths: {
|
|
18
|
+
vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.35.0/min/vs',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
require(['vs/editor/editor.main'], function () {
|
|
22
|
+
const traffic = !{ traffic };
|
|
23
|
+
const model = monaco.editor.createModel(JSON.stringify(traffic, null, 2), 'json');
|
|
24
|
+
const editor = monaco.editor.create(document.getElementById('container'), {
|
|
25
|
+
theme: 'vs-dark',
|
|
26
|
+
autoIndent: true,
|
|
27
|
+
formatOnPaste: true,
|
|
28
|
+
formatOnType: true,
|
|
29
|
+
automaticLayout: true,
|
|
30
|
+
readOnly: true,
|
|
31
|
+
});
|
|
32
|
+
editor.onDidChangeModel((event) => {
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
editor.getAction('editor.action.formatDocument').run();
|
|
35
|
+
}, 100);
|
|
36
|
+
});
|
|
37
|
+
editor.setModel(model);
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stuntman.d.ts","sourceRoot":"","sources":["../../src/bin/stuntman.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const mock_1 = require("../mock");
|
|
5
|
+
const shared_1 = require("@stuntman/shared");
|
|
6
|
+
const mock = new mock_1.Mock(shared_1.stuntmanConfig);
|
|
7
|
+
mock.start();
|
|
8
|
+
//# sourceMappingURL=stuntman.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stuntman.js","sourceRoot":"","sources":["../../src/bin/stuntman.ts"],"names":[],"mappings":";;;AAEA,kCAA+B;AAC/B,6CAAkD;AAElD,MAAM,IAAI,GAAG,IAAI,WAAI,CAAC,uBAAc,CAAC,CAAC;AAEtC,IAAI,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StuntmanMock = void 0;
|
|
4
|
+
var mock_1 = require("./mock");
|
|
5
|
+
Object.defineProperty(exports, "StuntmanMock", { enumerable: true, get: function () { return mock_1.Mock; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAA8C;AAArC,oGAAA,IAAI,OAAgB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import dns from 'node:dns';
|
|
3
|
+
export declare class IPUtils {
|
|
4
|
+
protected dnsResolutionCache: import("lru-cache")<string, string>;
|
|
5
|
+
protected mockUuid: string;
|
|
6
|
+
externalDns: dns.Resolver | null;
|
|
7
|
+
constructor(options: {
|
|
8
|
+
mockUuid: string;
|
|
9
|
+
externalDns?: string[];
|
|
10
|
+
});
|
|
11
|
+
isLocalhostIP(ip: string): boolean;
|
|
12
|
+
private resolveIPs;
|
|
13
|
+
resolveIP(hostname: string, options?: {
|
|
14
|
+
useExternalDns?: true;
|
|
15
|
+
}): Promise<string>;
|
|
16
|
+
isIP(hostname: string): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ipUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipUtils.d.ts","sourceRoot":"","sources":["../src/ipUtils.ts"],"names":[],"mappings":";AACA,OAAO,GAAgC,MAAM,UAAU,CAAC;AAmBxD,qBAAa,OAAO;IAChB,SAAS,CAAC,kBAAkB,sCAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAQ;gBAE5B,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;IASjE,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;YAIpB,UAAU;IAiClB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAQvF,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGlC"}
|
package/dist/ipUtils.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.IPUtils = void 0;
|
|
27
|
+
const os_1 = require("os");
|
|
28
|
+
const node_dns_1 = __importStar(require("node:dns"));
|
|
29
|
+
const storage_1 = require("./storage");
|
|
30
|
+
const shared_1 = require("@stuntman/shared");
|
|
31
|
+
const localhostIPs = ['127.0.0.1'];
|
|
32
|
+
const IP_WITH_OPTIONAL_PORT_REGEX = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}(:[0-9]+)?$/i;
|
|
33
|
+
for (const nets of Object.values((0, os_1.networkInterfaces)())) {
|
|
34
|
+
if (!nets) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (const net of nets) {
|
|
38
|
+
const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4;
|
|
39
|
+
if (net.family === familyV4Value && !localhostIPs.includes(net.address)) {
|
|
40
|
+
localhostIPs.push(net.address);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class IPUtils {
|
|
45
|
+
constructor(options) {
|
|
46
|
+
var _a;
|
|
47
|
+
this.externalDns = null;
|
|
48
|
+
this.mockUuid = options.mockUuid;
|
|
49
|
+
if ((_a = options.externalDns) === null || _a === void 0 ? void 0 : _a.length) {
|
|
50
|
+
this.externalDns = new node_dns_1.Resolver();
|
|
51
|
+
this.externalDns.setServers(options.externalDns);
|
|
52
|
+
}
|
|
53
|
+
this.dnsResolutionCache = (0, storage_1.getDnsResolutionCache)(this.mockUuid);
|
|
54
|
+
}
|
|
55
|
+
isLocalhostIP(ip) {
|
|
56
|
+
return localhostIPs.includes(ip);
|
|
57
|
+
}
|
|
58
|
+
async resolveIPs(hostname, options) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const callback = (error, addresses) => {
|
|
61
|
+
if (error) {
|
|
62
|
+
shared_1.logger.debug({ error, hostname }, 'error resolving hostname');
|
|
63
|
+
reject(error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (typeof addresses === 'string') {
|
|
67
|
+
shared_1.logger.debug({ ip: [addresses], hostname }, 'resolved hostname');
|
|
68
|
+
resolve([addresses]);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!addresses || addresses.length === 0) {
|
|
72
|
+
shared_1.logger.debug({ hostname }, 'missing IPs');
|
|
73
|
+
reject(new Error('No addresses found'));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
shared_1.logger.debug({ ip: addresses, hostname }, 'resolved hostname');
|
|
77
|
+
resolve([addresses[0], ...addresses.slice(1)]);
|
|
78
|
+
};
|
|
79
|
+
if (options === null || options === void 0 ? void 0 : options.useExternalDns) {
|
|
80
|
+
if (!this.externalDns) {
|
|
81
|
+
reject(new Error('external dns servers not set'));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.externalDns.resolve(hostname, callback);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
node_dns_1.default.lookup(hostname, callback);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async resolveIP(hostname, options) {
|
|
91
|
+
const cachedIP = this.dnsResolutionCache.get(hostname);
|
|
92
|
+
if (cachedIP) {
|
|
93
|
+
return cachedIP;
|
|
94
|
+
}
|
|
95
|
+
return (await this.resolveIPs(hostname, options))[0];
|
|
96
|
+
}
|
|
97
|
+
isIP(hostname) {
|
|
98
|
+
return IP_WITH_OPTIONAL_PORT_REGEX.test(hostname);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
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EAAE;oBACnB,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;oBAClD,OAAO;iBACV;gBACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAC7C,OAAO;aACV;YACD,kBAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,OAAmC;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,QAAQ,EAAE;YACV,OAAO,QAAQ,CAAC;SACnB;QACD,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,QAAgB;QACjB,OAAO,2BAA2B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;CACJ;AA9DD,0BA8DC"}
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import https from 'https';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import type * as Stuntman from '@stuntman/shared';
|
|
7
|
+
import { IPUtils } from './ipUtils';
|
|
8
|
+
import LRUCache from 'lru-cache';
|
|
9
|
+
import { API } from './api/api';
|
|
10
|
+
export declare class Mock {
|
|
11
|
+
readonly mockUuid: string;
|
|
12
|
+
protected options: Stuntman.Config;
|
|
13
|
+
protected mockApp: express.Express | null;
|
|
14
|
+
protected MOCK_DOMAIN_REGEX: RegExp;
|
|
15
|
+
protected URL_PORT_REGEX: RegExp;
|
|
16
|
+
protected server: http.Server | null;
|
|
17
|
+
protected serverHttps: https.Server | null;
|
|
18
|
+
protected trafficStore: LRUCache<string, Stuntman.LogEntry>;
|
|
19
|
+
protected ipUtils: IPUtils | null;
|
|
20
|
+
private _api;
|
|
21
|
+
get apiServer(): API | null;
|
|
22
|
+
get ruleExecutor(): Stuntman.RuleExecutorInterface;
|
|
23
|
+
constructor(options: Stuntman.Config);
|
|
24
|
+
private requestHandler;
|
|
25
|
+
init(): void;
|
|
26
|
+
private proxyRequest;
|
|
27
|
+
start(): void;
|
|
28
|
+
stop(): void;
|
|
29
|
+
protected unproxyRequest(req: express.Request): Stuntman.BaseRequest;
|
|
30
|
+
protected removeProxyPort(req: Stuntman.Request): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAM9B,OAAO,KAAK,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAQhC,qBAAa,IAAI;IACb,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;IACnC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAQ;IACjD,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACpC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAQ;IAC5C,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAQ;IAClD,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5D,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAQ;IACzC,OAAO,CAAC,IAAI,CAAoB;IAEhC,IAAI,SAAS,eAQZ;IAED,IAAW,YAAY,IAAI,QAAQ,CAAC,qBAAqB,CAExD;gBAEW,OAAO,EAAE,QAAQ,CAAC,MAAM;YA4BtB,cAAc;IAqI5B,IAAI;YA+BU,YAAY;IAkDnB,KAAK;IA6BL,IAAI;IAaX,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC,WAAW;IAepE,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,IAAI;CAYzD"}
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Mock = void 0;
|
|
7
|
+
const undici_1 = require("undici");
|
|
8
|
+
const https_1 = __importDefault(require("https"));
|
|
9
|
+
const express_1 = __importDefault(require("express"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const ruleExecutor_1 = require("./ruleExecutor");
|
|
12
|
+
const storage_1 = require("./storage");
|
|
13
|
+
const shared_1 = require("@stuntman/shared");
|
|
14
|
+
const requestContext_1 = __importDefault(require("./requestContext"));
|
|
15
|
+
const ipUtils_1 = require("./ipUtils");
|
|
16
|
+
const api_1 = require("./api/api");
|
|
17
|
+
// TODO add proper web proxy mode
|
|
18
|
+
class Mock {
|
|
19
|
+
get apiServer() {
|
|
20
|
+
if (this.options.api.disabled) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!this._api) {
|
|
24
|
+
this._api = new api_1.API({ ...this.options.api, mockUuid: this.mockUuid }, this.options.webgui);
|
|
25
|
+
}
|
|
26
|
+
return this._api;
|
|
27
|
+
}
|
|
28
|
+
get ruleExecutor() {
|
|
29
|
+
return (0, ruleExecutor_1.getRuleExecutor)(this.mockUuid);
|
|
30
|
+
}
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.mockApp = null;
|
|
33
|
+
this.server = null;
|
|
34
|
+
this.serverHttps = null;
|
|
35
|
+
this.ipUtils = null;
|
|
36
|
+
this._api = null;
|
|
37
|
+
this.mockUuid = (0, uuid_1.v4)();
|
|
38
|
+
this.options = options;
|
|
39
|
+
if (this.options.mock.httpsPort && (!this.options.mock.httpsKey || !this.options.mock.httpsCert)) {
|
|
40
|
+
throw new Error('missing https key/cert');
|
|
41
|
+
}
|
|
42
|
+
this.MOCK_DOMAIN_REGEX = new RegExp(`(?:\\.([0-9]+))?\\.(?:(?:${this.options.mock.domain}(https?)?)|(?:localhost))(:${this.options.mock.port}${this.options.mock.httpsPort ? `|${this.options.mock.httpsPort}` : ''})?(?:\\b|$)`, 'i');
|
|
43
|
+
this.URL_PORT_REGEX = new RegExp(`^(https?:\\/\\/[^:/]+):(?:${this.options.mock.port}${this.options.mock.httpsPort ? `|${this.options.mock.httpsPort}` : ''})(\\/.*)`, 'i');
|
|
44
|
+
this.trafficStore = (0, storage_1.getTrafficStore)(this.mockUuid, this.options.storage.traffic);
|
|
45
|
+
this.ipUtils =
|
|
46
|
+
!this.options.mock.externalDns || this.options.mock.externalDns.length === 0
|
|
47
|
+
? null
|
|
48
|
+
: new ipUtils_1.IPUtils({ mockUuid: this.mockUuid, externalDns: this.options.mock.externalDns });
|
|
49
|
+
this.requestHandler = this.requestHandler.bind(this);
|
|
50
|
+
}
|
|
51
|
+
async requestHandler(req, res) {
|
|
52
|
+
const ctx = requestContext_1.default.get(req);
|
|
53
|
+
const requestUuid = (ctx === null || ctx === void 0 ? void 0 : ctx.uuid) || (0, uuid_1.v4)();
|
|
54
|
+
const timestamp = Date.now();
|
|
55
|
+
const originalHostname = req.headers.host || req.hostname;
|
|
56
|
+
const unproxiedHostname = req.hostname.replace(this.MOCK_DOMAIN_REGEX, '');
|
|
57
|
+
const isProxiedHostname = originalHostname !== unproxiedHostname;
|
|
58
|
+
const originalRequest = {
|
|
59
|
+
id: requestUuid,
|
|
60
|
+
timestamp,
|
|
61
|
+
url: `${req.protocol}://${req.hostname}${req.originalUrl}`,
|
|
62
|
+
method: req.method,
|
|
63
|
+
rawHeaders: new shared_1.RawHeaders(...req.rawHeaders),
|
|
64
|
+
...((Buffer.isBuffer(req.body) && { body: req.body.toString('utf-8') }) ||
|
|
65
|
+
(typeof req.body === 'string' && { body: req.body })),
|
|
66
|
+
};
|
|
67
|
+
shared_1.logger.debug(originalRequest, 'processing request');
|
|
68
|
+
const logContext = {
|
|
69
|
+
requestId: originalRequest.id,
|
|
70
|
+
};
|
|
71
|
+
const mockEntry = {
|
|
72
|
+
originalRequest,
|
|
73
|
+
modifiedRequest: {
|
|
74
|
+
...this.unproxyRequest(req),
|
|
75
|
+
id: requestUuid,
|
|
76
|
+
timestamp,
|
|
77
|
+
...(originalRequest.body && { gqlBody: (0, shared_1.naiveGQLParser)(originalRequest.body) }),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
if (!isProxiedHostname) {
|
|
81
|
+
this.removeProxyPort(mockEntry.modifiedRequest);
|
|
82
|
+
}
|
|
83
|
+
const matchingRule = await (0, ruleExecutor_1.getRuleExecutor)(this.mockUuid).findMatchingRule(mockEntry.modifiedRequest);
|
|
84
|
+
if (matchingRule) {
|
|
85
|
+
mockEntry.mockRuleId = matchingRule.id;
|
|
86
|
+
mockEntry.labels = matchingRule.labels;
|
|
87
|
+
if (matchingRule.actions.mockResponse) {
|
|
88
|
+
const staticResponse = typeof matchingRule.actions.mockResponse === 'function'
|
|
89
|
+
? matchingRule.actions.mockResponse(mockEntry.modifiedRequest)
|
|
90
|
+
: matchingRule.actions.mockResponse;
|
|
91
|
+
mockEntry.modifiedResponse = staticResponse;
|
|
92
|
+
shared_1.logger.debug({ ...logContext, staticResponse }, 'replying with mocked response');
|
|
93
|
+
if (matchingRule.storeTraffic) {
|
|
94
|
+
this.trafficStore.set(requestUuid, mockEntry);
|
|
95
|
+
}
|
|
96
|
+
if (staticResponse.rawHeaders) {
|
|
97
|
+
for (const header of staticResponse.rawHeaders.toHeaderPairs()) {
|
|
98
|
+
res.setHeader(header[0], header[1]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
res.status(staticResponse.status || 200);
|
|
102
|
+
res.send(staticResponse.body);
|
|
103
|
+
// static response blocks any further processing
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (matchingRule.actions.modifyRequest) {
|
|
107
|
+
mockEntry.modifiedRequest = matchingRule.actions.modifyRequest(mockEntry.modifiedRequest);
|
|
108
|
+
shared_1.logger.debug({ ...logContext, modifiedRequest: mockEntry.modifiedRequest }, 'modified original request');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (this.ipUtils && !isProxiedHostname && !this.ipUtils.isIP(originalHostname)) {
|
|
112
|
+
const hostname = originalHostname.split(':')[0];
|
|
113
|
+
try {
|
|
114
|
+
const internalIPs = await this.ipUtils.resolveIP(hostname);
|
|
115
|
+
if (this.ipUtils.isLocalhostIP(internalIPs) && this.options.mock.externalDns.length) {
|
|
116
|
+
const externalIPs = await this.ipUtils.resolveIP(hostname, { useExternalDns: true });
|
|
117
|
+
shared_1.logger.debug({ ...logContext, hostname, externalIPs, internalIPs }, 'switched to external IP');
|
|
118
|
+
mockEntry.modifiedRequest.url = mockEntry.modifiedRequest.url.replace(/^(https?:\/\/)[^:/]+/i, `$1${externalIPs}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// swallow the exeception, don't think much can be done at this point
|
|
123
|
+
shared_1.logger.warn({ ...logContext, error }, `error trying to resolve IP for "${hostname}"`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const originalResponse = this.options.mock.disableProxy
|
|
127
|
+
? {
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
body: undefined,
|
|
130
|
+
rawHeaders: new shared_1.RawHeaders(),
|
|
131
|
+
status: 404,
|
|
132
|
+
}
|
|
133
|
+
: await this.proxyRequest(req, mockEntry, logContext);
|
|
134
|
+
shared_1.logger.debug({ ...logContext, originalResponse }, 'received response');
|
|
135
|
+
mockEntry.originalResponse = originalResponse;
|
|
136
|
+
let modifedResponse = {
|
|
137
|
+
...originalResponse,
|
|
138
|
+
rawHeaders: new shared_1.RawHeaders(...Array.from(originalResponse.rawHeaders.toHeaderPairs()).flatMap(([key, value]) => {
|
|
139
|
+
// TODO this replace may be too aggressive and doesn't handle protocol (won't be necessary with a trusted cert and mock serving http+https)
|
|
140
|
+
return [
|
|
141
|
+
key,
|
|
142
|
+
isProxiedHostname
|
|
143
|
+
? value
|
|
144
|
+
: value.replace(new RegExp(`(?:^|\\b)(${(0, shared_1.escapeStringRegexp)(unproxiedHostname)})(?:\\b|$)`, 'igm'), originalHostname),
|
|
145
|
+
];
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
if (matchingRule === null || matchingRule === void 0 ? void 0 : matchingRule.actions.modifyResponse) {
|
|
149
|
+
modifedResponse = matchingRule === null || matchingRule === void 0 ? void 0 : matchingRule.actions.modifyResponse(mockEntry.modifiedRequest, originalResponse);
|
|
150
|
+
shared_1.logger.debug({ ...logContext, modifedResponse }, 'modified response');
|
|
151
|
+
}
|
|
152
|
+
mockEntry.modifiedResponse = modifedResponse;
|
|
153
|
+
if (matchingRule === null || matchingRule === void 0 ? void 0 : matchingRule.storeTraffic) {
|
|
154
|
+
this.trafficStore.set(requestUuid, mockEntry);
|
|
155
|
+
}
|
|
156
|
+
if (modifedResponse.status) {
|
|
157
|
+
res.status(modifedResponse.status);
|
|
158
|
+
}
|
|
159
|
+
if (modifedResponse.rawHeaders) {
|
|
160
|
+
for (const header of modifedResponse.rawHeaders.toHeaderPairs()) {
|
|
161
|
+
// since fetch decompresses responses we need to get rid of some headers
|
|
162
|
+
// TODO maybe could be handled better than just skipping, although express should add these back for new body
|
|
163
|
+
// if (/^content-(?:length|encoding)$/i.test(header[0])) {
|
|
164
|
+
// continue;
|
|
165
|
+
// }
|
|
166
|
+
res.setHeader(header[0], isProxiedHostname ? header[1].replace(unproxiedHostname, originalHostname) : header[1]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
res.end(Buffer.from(modifedResponse.body, 'binary'));
|
|
170
|
+
}
|
|
171
|
+
init() {
|
|
172
|
+
if (this.mockApp) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.mockApp = (0, express_1.default)();
|
|
176
|
+
// TODO for now request body is just a buffer passed further, not inflated
|
|
177
|
+
this.mockApp.use(express_1.default.raw({ type: '*/*' }));
|
|
178
|
+
this.mockApp.use((req, _res, next) => {
|
|
179
|
+
requestContext_1.default.bind(req, this.mockUuid);
|
|
180
|
+
next();
|
|
181
|
+
});
|
|
182
|
+
this.mockApp.all(/.*/, this.requestHandler);
|
|
183
|
+
this.mockApp.use((error, req, res) => {
|
|
184
|
+
const ctx = requestContext_1.default.get(req);
|
|
185
|
+
const uuid = (ctx === null || ctx === void 0 ? void 0 : ctx.uuid) || (0, uuid_1.v4)();
|
|
186
|
+
shared_1.logger.error({ message: error.message, stack: error.stack, name: error.name, uuid }, 'unexpected error');
|
|
187
|
+
if (res) {
|
|
188
|
+
res.status(shared_1.HttpCode.INTERNAL_SERVER_ERROR).json({
|
|
189
|
+
error: { message: error.message, httpCode: shared_1.HttpCode.INTERNAL_SERVER_ERROR, uuid },
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// eslint-disable-next-line no-console
|
|
194
|
+
console.error('mock server encountered a critical error. exiting');
|
|
195
|
+
process.exit(1);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async proxyRequest(req, mockEntry, logContext) {
|
|
199
|
+
let controller = new AbortController();
|
|
200
|
+
const fetchTimeout = setTimeout(() => {
|
|
201
|
+
if (controller) {
|
|
202
|
+
controller.abort(`timeout after ${this.options.mock.timeout}`);
|
|
203
|
+
}
|
|
204
|
+
}, this.options.mock.timeout);
|
|
205
|
+
req.on('close', () => {
|
|
206
|
+
shared_1.logger.debug(logContext, 'remote client canceled the request');
|
|
207
|
+
clearTimeout(fetchTimeout);
|
|
208
|
+
if (controller) {
|
|
209
|
+
controller.abort('remote client canceled the request');
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
let targetResponse;
|
|
213
|
+
try {
|
|
214
|
+
const requestOptions = {
|
|
215
|
+
headers: mockEntry.modifiedRequest.rawHeaders,
|
|
216
|
+
body: mockEntry.modifiedRequest.body,
|
|
217
|
+
method: mockEntry.modifiedRequest.method.toUpperCase(),
|
|
218
|
+
};
|
|
219
|
+
shared_1.logger.debug({
|
|
220
|
+
...logContext,
|
|
221
|
+
url: mockEntry.modifiedRequest.url,
|
|
222
|
+
...requestOptions,
|
|
223
|
+
}, 'outgoing request attempt');
|
|
224
|
+
targetResponse = await (0, undici_1.request)(mockEntry.modifiedRequest.url, requestOptions);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
shared_1.logger.error({ ...logContext, error, request: mockEntry.modifiedRequest }, 'error fetching');
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
controller = null;
|
|
232
|
+
clearTimeout(fetchTimeout);
|
|
233
|
+
}
|
|
234
|
+
const targetResponseBuffer = Buffer.from(await targetResponse.body.arrayBuffer());
|
|
235
|
+
return {
|
|
236
|
+
timestamp: Date.now(),
|
|
237
|
+
body: targetResponseBuffer.toString('binary'),
|
|
238
|
+
status: targetResponse.statusCode,
|
|
239
|
+
rawHeaders: shared_1.RawHeaders.fromHeadersRecord(targetResponse.headers),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
start() {
|
|
243
|
+
this.init();
|
|
244
|
+
if (!this.mockApp) {
|
|
245
|
+
throw new Error('initialization error');
|
|
246
|
+
}
|
|
247
|
+
if (this.server) {
|
|
248
|
+
throw new Error('mock server already started');
|
|
249
|
+
}
|
|
250
|
+
if (this.options.mock.httpsPort) {
|
|
251
|
+
this.serverHttps = https_1.default
|
|
252
|
+
.createServer({
|
|
253
|
+
key: this.options.mock.httpsKey,
|
|
254
|
+
cert: this.options.mock.httpsCert,
|
|
255
|
+
}, this.mockApp)
|
|
256
|
+
.listen(this.options.mock.httpsPort, () => {
|
|
257
|
+
shared_1.logger.info(`Mock listening on ${this.options.mock.domain}:${this.options.mock.httpsPort}`);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
this.server = this.mockApp.listen(this.options.mock.port, () => {
|
|
261
|
+
var _a;
|
|
262
|
+
shared_1.logger.info(`Mock listening on ${this.options.mock.domain}:${this.options.mock.port}`);
|
|
263
|
+
if (!this.options.api.disabled) {
|
|
264
|
+
(_a = this.apiServer) === null || _a === void 0 ? void 0 : _a.start();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
stop() {
|
|
269
|
+
var _a;
|
|
270
|
+
if (!this.server) {
|
|
271
|
+
throw new Error('mock server not started');
|
|
272
|
+
}
|
|
273
|
+
if (!this.options.api.disabled) {
|
|
274
|
+
(_a = this.apiServer) === null || _a === void 0 ? void 0 : _a.stop();
|
|
275
|
+
}
|
|
276
|
+
this.server.close((error) => {
|
|
277
|
+
shared_1.logger.warn(error, 'problem closing server');
|
|
278
|
+
this.server = null;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
unproxyRequest(req) {
|
|
282
|
+
const protocol = (this.MOCK_DOMAIN_REGEX.exec(req.hostname) || [])[2] || req.protocol;
|
|
283
|
+
const port = (this.MOCK_DOMAIN_REGEX.exec(req.hostname) || [])[1] || undefined;
|
|
284
|
+
// TODO unproxied req might fail if there's a signed url :shrug:
|
|
285
|
+
// but then we can probably switch DNS for some particular 3rd party server to point to mock
|
|
286
|
+
// and in mock have a mapping rule for that domain to point directly to some IP :thinking:
|
|
287
|
+
return {
|
|
288
|
+
url: `${protocol}://${req.hostname.replace(this.MOCK_DOMAIN_REGEX, '')}${port ? `:${port}` : ''}${req.originalUrl}`,
|
|
289
|
+
rawHeaders: new shared_1.RawHeaders(...req.rawHeaders.map((h) => h.replace(this.MOCK_DOMAIN_REGEX, ''))),
|
|
290
|
+
method: req.method,
|
|
291
|
+
...(Buffer.isBuffer(req.body) && { body: req.body.toString('utf-8') }),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
removeProxyPort(req) {
|
|
295
|
+
if (this.URL_PORT_REGEX.test(req.url)) {
|
|
296
|
+
req.url = req.url.replace(this.URL_PORT_REGEX, '$1$2');
|
|
297
|
+
}
|
|
298
|
+
const host = req.rawHeaders.get('host') || '';
|
|
299
|
+
if (host.endsWith(`:${this.options.mock.port}`) ||
|
|
300
|
+
(this.options.mock.httpsPort && host.endsWith(`:${this.options.mock.httpsPort}`))) {
|
|
301
|
+
req.rawHeaders.set('host', host.split(':')[0]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.Mock = Mock;
|
|
306
|
+
//# sourceMappingURL=mock.js.map
|
package/dist/mock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAiD;AAGjD,kDAA0B;AAC1B,sDAA8B;AAC9B,+BAAoC;AACpC,iDAAiD;AACjD,uCAA4C;AAC5C,6CAAoG;AACpG,sEAA8C;AAE9C,uCAAoC;AAEpC,mCAAgC;AAMhC,iCAAiC;AAEjC,MAAa,IAAI;IAYb,IAAI,SAAS;QACT,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAA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|
+
readonly mockUuid: string;
|
|
5
|
+
readonly uuid: string;
|
|
6
|
+
constructor(mockUuid: string);
|
|
7
|
+
static bind(req: Request, mockUuid: string): void;
|
|
8
|
+
static get(req: Request): RequestContext | null;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=requestContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext.d.ts","sourceRoot":"","sources":["../src/requestContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,CAAC,OAAO,OAAO,cAAc;IAC/B,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,CAA0C;IAE5F,SAAgB,QAAQ,SAAC;IACzB,SAAgB,IAAI,SAAC;gBAET,QAAQ,EAAE,MAAM;IAK5B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKjD,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI;CAGlD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uuid_1 = require("uuid");
|
|
4
|
+
class RequestContext {
|
|
5
|
+
constructor(mockUuid) {
|
|
6
|
+
this.uuid = (0, uuid_1.v4)();
|
|
7
|
+
this.mockUuid = mockUuid;
|
|
8
|
+
}
|
|
9
|
+
static bind(req, mockUuid) {
|
|
10
|
+
const ctx = new RequestContext(mockUuid);
|
|
11
|
+
RequestContext._bindings.set(req, ctx);
|
|
12
|
+
}
|
|
13
|
+
static get(req) {
|
|
14
|
+
return RequestContext._bindings.get(req) || null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = RequestContext;
|
|
18
|
+
RequestContext._bindings = new WeakMap();
|
|
19
|
+
//# sourceMappingURL=requestContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext.js","sourceRoot":"","sources":["../src/requestContext.ts"],"names":[],"mappings":";;AACA,+BAAoC;AAEpC,MAAqB,cAAc;IAM/B,YAAY,QAAgB;QACxB,IAAI,CAAC,IAAI,GAAG,IAAA,SAAM,GAAE,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAY,EAAE,QAAgB;QACtC,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzC,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,GAAY;QACnB,OAAO,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACrD,CAAC;;AAlBL,iCAmBC;AAlBU,wBAAS,GAAqC,IAAI,OAAO,EAA2B,CAAC"}
|