@mbtest/mountebank 2.9.2-beta.9050
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/LICENSE +21 -0
- package/README.md +94 -0
- package/bin/mb +136 -0
- package/package.json +71 -0
- package/releases.json +52 -0
- package/src/cli/api.js +112 -0
- package/src/cli/cli.js +420 -0
- package/src/controllers/configController.js +64 -0
- package/src/controllers/feedController.js +115 -0
- package/src/controllers/homeController.js +58 -0
- package/src/controllers/imposterController.js +328 -0
- package/src/controllers/impostersController.js +215 -0
- package/src/controllers/logsController.js +52 -0
- package/src/models/behaviors.js +553 -0
- package/src/models/behaviorsValidator.js +186 -0
- package/src/models/compatibility.js +133 -0
- package/src/models/dryRunValidator.js +261 -0
- package/src/models/filesystemBackedImpostersRepository.js +908 -0
- package/src/models/http/baseHttpServer.js +207 -0
- package/src/models/http/headersMap.js +87 -0
- package/src/models/http/httpProxy.js +230 -0
- package/src/models/http/httpRequest.js +82 -0
- package/src/models/http/httpServer.js +18 -0
- package/src/models/http/index.js +18 -0
- package/src/models/https/cert/mb-cert.pem +20 -0
- package/src/models/https/cert/mb-csr.pem +16 -0
- package/src/models/https/cert/mb-key.pem +27 -0
- package/src/models/https/httpsServer.js +42 -0
- package/src/models/https/index.js +18 -0
- package/src/models/imposter.js +243 -0
- package/src/models/imposterPrinter.js +120 -0
- package/src/models/impostersRepository.js +49 -0
- package/src/models/inMemoryImpostersRepository.js +418 -0
- package/src/models/jsonpath.js +44 -0
- package/src/models/mbConnection.js +107 -0
- package/src/models/predicates.js +438 -0
- package/src/models/protocols.js +242 -0
- package/src/models/responseResolver.js +398 -0
- package/src/models/smtp/index.js +16 -0
- package/src/models/smtp/smtpRequest.js +60 -0
- package/src/models/smtp/smtpServer.js +109 -0
- package/src/models/tcp/index.js +18 -0
- package/src/models/tcp/tcpProxy.js +110 -0
- package/src/models/tcp/tcpRequest.js +23 -0
- package/src/models/tcp/tcpServer.js +156 -0
- package/src/models/tcp/tcpValidator.js +19 -0
- package/src/models/xpath.js +95 -0
- package/src/mountebank.js +245 -0
- package/src/public/images/arrow_down.png +0 -0
- package/src/public/images/arrow_up.png +0 -0
- package/src/public/images/book.jpg +0 -0
- package/src/public/images/dataflow.png +0 -0
- package/src/public/images/favicon.ico +0 -0
- package/src/public/images/forkme_right_orange_ff7600.png +0 -0
- package/src/public/images/mountebank.png +0 -0
- package/src/public/images/overview.gif +0 -0
- package/src/public/images/quote.png +0 -0
- package/src/public/images/tw-logo.png +0 -0
- package/src/public/scripts/jquery/jquery-3.6.1.min.js +2 -0
- package/src/public/scripts/urlHashHandler.js +31 -0
- package/src/public/stylesheets/application.css +424 -0
- package/src/public/stylesheets/ie.css +14 -0
- package/src/public/stylesheets/imposters.css +121 -0
- package/src/public/stylesheets/jqueryui/1.10.4/themes/smoothness/jquery-ui.css +1178 -0
- package/src/util/combinators.js +68 -0
- package/src/util/date.js +51 -0
- package/src/util/errors.js +55 -0
- package/src/util/helpers.js +131 -0
- package/src/util/inherit.js +28 -0
- package/src/util/ip.js +54 -0
- package/src/util/logger.js +83 -0
- package/src/util/middleware.js +256 -0
- package/src/util/scopedLogger.js +47 -0
- package/src/views/_footer.ejs +20 -0
- package/src/views/_header.ejs +113 -0
- package/src/views/_imposter.ejs +8 -0
- package/src/views/config.ejs +71 -0
- package/src/views/docs/api/behaviors/copy.ejs +427 -0
- package/src/views/docs/api/behaviors/decorate.ejs +182 -0
- package/src/views/docs/api/behaviors/lookup.ejs +220 -0
- package/src/views/docs/api/behaviors/shellTransform.ejs +153 -0
- package/src/views/docs/api/behaviors/wait.ejs +121 -0
- package/src/views/docs/api/behaviors.ejs +141 -0
- package/src/views/docs/api/contracts/addStub-description.ejs +10 -0
- package/src/views/docs/api/contracts/addStub.ejs +10 -0
- package/src/views/docs/api/contracts/config-description.ejs +32 -0
- package/src/views/docs/api/contracts/config.ejs +23 -0
- package/src/views/docs/api/contracts/home-description.ejs +18 -0
- package/src/views/docs/api/contracts/home.ejs +13 -0
- package/src/views/docs/api/contracts/imposter-description.ejs +439 -0
- package/src/views/docs/api/contracts/imposter.ejs +182 -0
- package/src/views/docs/api/contracts/imposters-description.ejs +13 -0
- package/src/views/docs/api/contracts/imposters.ejs +13 -0
- package/src/views/docs/api/contracts/logs-description.ejs +3 -0
- package/src/views/docs/api/contracts/logs.ejs +14 -0
- package/src/views/docs/api/contracts/stub-description.ejs +4 -0
- package/src/views/docs/api/contracts/stub.ejs +7 -0
- package/src/views/docs/api/contracts/stubs-description.ejs +4 -0
- package/src/views/docs/api/contracts/stubs.ejs +11 -0
- package/src/views/docs/api/contracts.ejs +133 -0
- package/src/views/docs/api/errors.ejs +64 -0
- package/src/views/docs/api/fault/connectionReset.ejs +31 -0
- package/src/views/docs/api/fault/randomDataThenClose.ejs +31 -0
- package/src/views/docs/api/faults.ejs +57 -0
- package/src/views/docs/api/injection.ejs +426 -0
- package/src/views/docs/api/json.ejs +205 -0
- package/src/views/docs/api/jsonpath.ejs +210 -0
- package/src/views/docs/api/mocks.ejs +130 -0
- package/src/views/docs/api/overview.ejs +968 -0
- package/src/views/docs/api/predicates/and.ejs +62 -0
- package/src/views/docs/api/predicates/contains.ejs +64 -0
- package/src/views/docs/api/predicates/deepEquals.ejs +114 -0
- package/src/views/docs/api/predicates/endsWith.ejs +66 -0
- package/src/views/docs/api/predicates/equals.ejs +125 -0
- package/src/views/docs/api/predicates/exists.ejs +118 -0
- package/src/views/docs/api/predicates/inject.ejs +67 -0
- package/src/views/docs/api/predicates/matches.ejs +66 -0
- package/src/views/docs/api/predicates/not.ejs +52 -0
- package/src/views/docs/api/predicates/or.ejs +79 -0
- package/src/views/docs/api/predicates/startsWith.ejs +62 -0
- package/src/views/docs/api/predicates.ejs +382 -0
- package/src/views/docs/api/proxies.ejs +191 -0
- package/src/views/docs/api/proxy/addDecorateBehavior.ejs +115 -0
- package/src/views/docs/api/proxy/addWaitBehavior.ejs +96 -0
- package/src/views/docs/api/proxy/injectHeaders.ejs +91 -0
- package/src/views/docs/api/proxy/predicateGenerators.ejs +600 -0
- package/src/views/docs/api/proxy/proxyModes.ejs +495 -0
- package/src/views/docs/api/stubs.ejs +391 -0
- package/src/views/docs/api/xpath.ejs +281 -0
- package/src/views/docs/cli/configFiles.ejs +133 -0
- package/src/views/docs/cli/customFormatters.ejs +53 -0
- package/src/views/docs/cli/help.ejs +6 -0
- package/src/views/docs/cli/replay.ejs +42 -0
- package/src/views/docs/cli/restart.ejs +10 -0
- package/src/views/docs/cli/save.ejs +68 -0
- package/src/views/docs/cli/start.ejs +234 -0
- package/src/views/docs/cli/stop.ejs +32 -0
- package/src/views/docs/commandLine.ejs +93 -0
- package/src/views/docs/communityExtensions.ejs +233 -0
- package/src/views/docs/gettingStarted.ejs +146 -0
- package/src/views/docs/mentalModel.ejs +51 -0
- package/src/views/docs/protocols/custom.ejs +231 -0
- package/src/views/docs/protocols/http.ejs +238 -0
- package/src/views/docs/protocols/https.ejs +246 -0
- package/src/views/docs/protocols/smtp.ejs +142 -0
- package/src/views/docs/protocols/tcp.ejs +431 -0
- package/src/views/docs/security.ejs +38 -0
- package/src/views/faqs.ejs +65 -0
- package/src/views/feed.ejs +33 -0
- package/src/views/imposter.ejs +22 -0
- package/src/views/imposters.ejs +33 -0
- package/src/views/index.ejs +89 -0
- package/src/views/license.ejs +30 -0
- package/src/views/logs.ejs +77 -0
- package/src/views/releases/v1.1.0.ejs +55 -0
- package/src/views/releases/v1.1.36.ejs +84 -0
- package/src/views/releases/v1.1.72.ejs +92 -0
- package/src/views/releases/v1.10.0.ejs +108 -0
- package/src/views/releases/v1.11.0.ejs +109 -0
- package/src/views/releases/v1.12.0.ejs +96 -0
- package/src/views/releases/v1.13.0.ejs +118 -0
- package/src/views/releases/v1.14.0.ejs +107 -0
- package/src/views/releases/v1.14.1.ejs +94 -0
- package/src/views/releases/v1.15.0.ejs +113 -0
- package/src/views/releases/v1.16.0.ejs +104 -0
- package/src/views/releases/v1.2.0.ejs +78 -0
- package/src/views/releases/v1.2.103.ejs +86 -0
- package/src/views/releases/v1.2.122.ejs +86 -0
- package/src/views/releases/v1.2.30.ejs +84 -0
- package/src/views/releases/v1.2.45.ejs +84 -0
- package/src/views/releases/v1.2.56.ejs +79 -0
- package/src/views/releases/v1.3.0.ejs +86 -0
- package/src/views/releases/v1.3.1.ejs +100 -0
- package/src/views/releases/v1.4.0.ejs +96 -0
- package/src/views/releases/v1.4.1.ejs +103 -0
- package/src/views/releases/v1.4.2.ejs +100 -0
- package/src/views/releases/v1.4.3.ejs +113 -0
- package/src/views/releases/v1.5.0.ejs +104 -0
- package/src/views/releases/v1.5.1.ejs +91 -0
- package/src/views/releases/v1.6.0.ejs +109 -0
- package/src/views/releases/v1.7.0.ejs +113 -0
- package/src/views/releases/v1.7.1.ejs +90 -0
- package/src/views/releases/v1.7.2.ejs +96 -0
- package/src/views/releases/v1.8.0.ejs +121 -0
- package/src/views/releases/v1.9.0.ejs +111 -0
- package/src/views/releases/v2.0.0.ejs +159 -0
- package/src/views/releases/v2.1.0.ejs +121 -0
- package/src/views/releases/v2.1.1.ejs +106 -0
- package/src/views/releases/v2.1.2.ejs +84 -0
- package/src/views/releases/v2.2.0.ejs +115 -0
- package/src/views/releases/v2.2.1.ejs +102 -0
- package/src/views/releases/v2.3.0.ejs +121 -0
- package/src/views/releases/v2.3.1.ejs +100 -0
- package/src/views/releases/v2.3.2.ejs +102 -0
- package/src/views/releases/v2.3.3.ejs +97 -0
- package/src/views/releases/v2.4.0.ejs +114 -0
- package/src/views/releases/v2.5.0.ejs +51 -0
- package/src/views/releases/v2.6.0.ejs +35 -0
- package/src/views/releases/v2.7.0.ejs +32 -0
- package/src/views/releases/v2.8.0.ejs +36 -0
- package/src/views/releases/v2.8.1.ejs +7 -0
- package/src/views/releases/v2.8.2.ejs +26 -0
- package/src/views/releases/v2.9.0.ejs +32 -0
- package/src/views/releases/v2.9.1.ejs +10 -0
- package/src/views/releases.ejs +26 -0
- package/src/views/sitemap.ejs +36 -0
- package/src/views/support.ejs +14 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<p>The default <code>formatter</code> for mountebank allows you to use EJS (version 2.x) templates
|
|
2
|
+
to split the test data into multiple files. This is particularly useful for separating out JavaScript injection
|
|
3
|
+
functions and XML or JSON HTTP response bodies because you store them as multi-line files and rely on
|
|
4
|
+
templating to turn them into JSON-friendly single line strings. It remains the default for backwards
|
|
5
|
+
compatibility, even though EJS 3.x has made breaking changes.</p>
|
|
6
|
+
|
|
7
|
+
<p>mountebank will pass a <code>stringify</code> function into your templates that allows you to put
|
|
8
|
+
multi-line strings in separate files. The example below is loosely based on the
|
|
9
|
+
<a href='/docs/api/injection#response-injection'>response injection</a> example described on
|
|
10
|
+
the Injection page, and shows the use of the <code>stringify</code> function. The path passed in
|
|
11
|
+
to <code>stringify</code> is relative to the root file referenced in the <code>configfile</code>
|
|
12
|
+
command line parameter. You can also pass a custom object, referenced as <code>data</code> in child
|
|
13
|
+
templates, as the second parameter of <code>stringify</code>. This is useful if you want to reuse
|
|
14
|
+
the same template but add some dynamic data. For an example, look at the <code>stringify</code> call in
|
|
15
|
+
templates/originServer.ejs below, and using the custom field in templates/originXMLResponse.ejs.</p>
|
|
16
|
+
|
|
17
|
+
<p>Assuming the files below are in a relative directory called <code>templates</code>, you can
|
|
18
|
+
initialize <code>mb</code> with the following command:</p>
|
|
19
|
+
|
|
20
|
+
<pre><code>mb --configfile templates/imposters.ejs --allowInjection --localOnly</code></pre>
|
|
21
|
+
|
|
22
|
+
<p>templates/imposters.ejs</p>
|
|
23
|
+
<pre><code>{
|
|
24
|
+
"imposters": [
|
|
25
|
+
<% include originServer.ejs %>,
|
|
26
|
+
<% include proxyServer.ejs %>
|
|
27
|
+
]
|
|
28
|
+
}</code></pre>
|
|
29
|
+
|
|
30
|
+
<p>templates/originServer.ejs</p>
|
|
31
|
+
<pre><code>{
|
|
32
|
+
"port": 5555,
|
|
33
|
+
"protocol": "http",
|
|
34
|
+
"name": "origin",
|
|
35
|
+
"stubs": [
|
|
36
|
+
{
|
|
37
|
+
"predicates": [{ "contains": { "headers": { "Content-Type": "xml" } } }],
|
|
38
|
+
"responses": [{ "is": { "body": "<%- stringify('originXMLResponse.ejs', { value: 'first }) %>" }}]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"responses": [{ "inject": "<%- stringify('originServerResponse.ejs') %>" }]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}</code></pre>
|
|
45
|
+
|
|
46
|
+
<p>templates/originXMLResponse.ejs</p>
|
|
47
|
+
<pre><code><rootNode>
|
|
48
|
+
<childNode><%= '<' + '%= data.value %' + '>' %></childNode>
|
|
49
|
+
</rootNode></code></pre>
|
|
50
|
+
|
|
51
|
+
<p>templates/originServerResponse.ejs</p>
|
|
52
|
+
<pre><code>(request, state, logger) => {
|
|
53
|
+
logger.info('origin called');
|
|
54
|
+
state.requests = state.requests || 0;
|
|
55
|
+
state.requests += 1;
|
|
56
|
+
return {
|
|
57
|
+
headers: {
|
|
58
|
+
'Content-Type': 'application/json'
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({ count: state.requests })
|
|
61
|
+
};
|
|
62
|
+
}</code></pre>
|
|
63
|
+
|
|
64
|
+
<p>templates/proxyServer.ejs</p>
|
|
65
|
+
<pre><code>{
|
|
66
|
+
"port": 4546,
|
|
67
|
+
"protocol": "http",
|
|
68
|
+
"name": "proxy",
|
|
69
|
+
"stubs": [
|
|
70
|
+
{
|
|
71
|
+
"responses": [{ "inject": "<%- stringify('counter.ejs') %>" }],
|
|
72
|
+
"predicates": [{
|
|
73
|
+
"equals": {
|
|
74
|
+
"method": "GET",
|
|
75
|
+
"path": "/counter"
|
|
76
|
+
}
|
|
77
|
+
}]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"responses": [{ "inject": "<%- stringify('proxy.ejs') %>" }]
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}</code></pre>
|
|
84
|
+
|
|
85
|
+
<p>templates/counter.ejs</p>
|
|
86
|
+
<pre><code>function (request, state) {
|
|
87
|
+
var count = state.requests ? Object.keys(state.requests).length : 0;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
body: `There have been ${count} proxied calls`
|
|
91
|
+
};
|
|
92
|
+
}</code></pre>
|
|
93
|
+
|
|
94
|
+
<p>templates/proxy.ejs</p>
|
|
95
|
+
<pre><code>function (request, state, logger, callback) {
|
|
96
|
+
var cacheKey = request.method + ' ' + request.path;
|
|
97
|
+
|
|
98
|
+
if (typeof state.requests === 'undefined') {
|
|
99
|
+
state.requests = {};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (state.requests[cacheKey]) {
|
|
103
|
+
logger.info('Using previous response');
|
|
104
|
+
callback(state.requests[cacheKey]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var http = require('http'),
|
|
108
|
+
options = {
|
|
109
|
+
method: request.method,
|
|
110
|
+
hostname: 'localhost',
|
|
111
|
+
port: 5555,
|
|
112
|
+
path: request.path,
|
|
113
|
+
headers: request.headers
|
|
114
|
+
},
|
|
115
|
+
httpRequest = http.request(options, response => {
|
|
116
|
+
var body = '';
|
|
117
|
+
response.setEncoding('utf8');
|
|
118
|
+
response.on('data', chunk => {
|
|
119
|
+
body += chunk;
|
|
120
|
+
});
|
|
121
|
+
response.on('end', () => {
|
|
122
|
+
var stubResponse = {
|
|
123
|
+
statusCode: response.statusCode,
|
|
124
|
+
headers: response.headers,
|
|
125
|
+
body
|
|
126
|
+
};
|
|
127
|
+
logger.info('Successfully proxied: ' + JSON.stringify(stubResponse));
|
|
128
|
+
state.requests[cacheKey] = stubResponse;
|
|
129
|
+
callback(stubResponse);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
httpRequest.end();
|
|
133
|
+
}</code></pre>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<p>A <code>formatter</code> is a CommonJS module that exports two functions: <code>load</code>, used
|
|
2
|
+
to load the configuration when the <code>configfile</code> option is passed to <code>mb start</code>,
|
|
3
|
+
and <code>save</code>, used to save the configuration for <code>mb save</code>. The formatter
|
|
4
|
+
gives you total control over how the test data is stored, allowing you to improve readability
|
|
5
|
+
(which suffers by default from JSON's single line requirement for strings) or to convert between
|
|
6
|
+
formats of other service virtualization tools.</p>
|
|
7
|
+
|
|
8
|
+
<p>The <a href='https://github.com/mountebank-testing/mountebank-formatters'>default formatter</a> that ships with mountebank is
|
|
9
|
+
described above ("Default config file parsing"). The example below shows a simple (and silly) formatter
|
|
10
|
+
that encodes all data as Base64.</p>
|
|
11
|
+
|
|
12
|
+
<pre><code>'use strict';
|
|
13
|
+
|
|
14
|
+
function encode (obj) {
|
|
15
|
+
return Buffer.from(JSON.stringify(obj)).toString('base64');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function decode (text) {
|
|
19
|
+
return Buffer.from(text, 'base64').toString('utf8');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function load (options) {
|
|
23
|
+
const fs = require('fs'),
|
|
24
|
+
contents = fs.readFileSync(options.configfile, { encoding: 'utf8' });
|
|
25
|
+
return JSON.parse(decode(contents));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function save (options, imposters) {
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
|
|
31
|
+
if (options.customName && imposters.imposters.length > 0) {
|
|
32
|
+
imposters.imposters[0].name = options.customName;
|
|
33
|
+
}
|
|
34
|
+
fs.writeFileSync(options.savefile, encode(imposters));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { load, save };</code></pre>
|
|
38
|
+
|
|
39
|
+
<p class='info-icon'>All CLI options are passed to both the <code>load</code> and <code>save</code> functions, allowing
|
|
40
|
+
you to define custom options specific to your formatter. You can see an example of this in the
|
|
41
|
+
<code>save</code> function, which takes a <code>customName</code> option and makes it the saved
|
|
42
|
+
name of the first imposter.</p>
|
|
43
|
+
|
|
44
|
+
<p class='info-icon'>The code above shows a synchronous implementation, but mountebank will accept
|
|
45
|
+
a promise return value.</p>
|
|
46
|
+
|
|
47
|
+
<p>Assuming the module is saved as 'customFormatter.js', the following commands will use it
|
|
48
|
+
for saving and loading:</p>
|
|
49
|
+
|
|
50
|
+
<pre><code>mb save --savefile mb.json --formatter customFormatter
|
|
51
|
+
mb restart --configfile mb.json --formatter customFormatter</code></pre>
|
|
52
|
+
|
|
53
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<pre><code>mb replay [options]</code></pre>
|
|
2
|
+
|
|
3
|
+
<p>The <code>replay</code> command is a convenience that removes all proxies,
|
|
4
|
+
effectively switching from record mode to replay mode. Assuming
|
|
5
|
+
mountebank is running on port 3000, you would run the following command:</p>
|
|
6
|
+
|
|
7
|
+
<pre><code>mb replay --port 3000</code></pre>
|
|
8
|
+
|
|
9
|
+
<p>That will reset the imposter configuration by sending a <code>PUT</code> command to /imposters
|
|
10
|
+
based on the current configuration, excluding the proxies (using the
|
|
11
|
+
<code>?removeProxies=true</code> query parameter). The following options are available:</p>
|
|
12
|
+
|
|
13
|
+
<table>
|
|
14
|
+
<tr>
|
|
15
|
+
<th style='width: 12em;'>Option</th>
|
|
16
|
+
<th>Description</th>
|
|
17
|
+
<th>Default</th>
|
|
18
|
+
</tr>
|
|
19
|
+
<tr>
|
|
20
|
+
<td><code>--port 2525</code></td>
|
|
21
|
+
<td>The port of the running the mountebank server</td>
|
|
22
|
+
<td><code>2525</code></td>
|
|
23
|
+
</tr>
|
|
24
|
+
<tr>
|
|
25
|
+
<td><code>--host mbserver.local</code></td>
|
|
26
|
+
<td>The hostname of the running mountebank server</td>
|
|
27
|
+
<td><code>localhost</code></td>
|
|
28
|
+
</tr>
|
|
29
|
+
<tr>
|
|
30
|
+
<td><code>--rcfile .mbrc</code></td>
|
|
31
|
+
<td>The run commands file containing startup configuration (a JSON-equivalent representation
|
|
32
|
+
of the command line arguments). When the same option is listed
|
|
33
|
+
in both the <code>rcfile</code> and the command line, the command line option takes
|
|
34
|
+
precedence.</td>
|
|
35
|
+
<td><code>N/A</code></td>
|
|
36
|
+
</tr>
|
|
37
|
+
<tr>
|
|
38
|
+
<td><code>--help</code></td>
|
|
39
|
+
<td>Show help for the command</td>
|
|
40
|
+
<td><code>N/A</code></td>
|
|
41
|
+
</tr>
|
|
42
|
+
</table>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<pre><code>mb restart [options]</code></pre>
|
|
2
|
+
|
|
3
|
+
<p>The <code>restart</code> command is equivalent to running <code>mb stop</code> followed
|
|
4
|
+
by <code>mb start</code>. To ensure a clean <code>stop</code>, the <code>--pidfile</code>
|
|
5
|
+
must match the one passed to the original <code>mb start</code> process. By default,
|
|
6
|
+
this means you must run <code>restart</code> in the same working directory you originally
|
|
7
|
+
ran the <code>start</code> command from.</p>
|
|
8
|
+
|
|
9
|
+
<p>The <code>restart</code> command has all the same command line options as the
|
|
10
|
+
<code>start</code> command.</p>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<pre><code>mb save [options]</code></pre>
|
|
2
|
+
|
|
3
|
+
<p>While you can always use the <a href='/docs/api/overview'>API</a> to capture the current configuration
|
|
4
|
+
of imposters, mountebank provides a convenient command line mechanism to save the configuration
|
|
5
|
+
into a file that can be used to start a subsequent process of <code>mb</code> using the
|
|
6
|
+
<code>--configfile</code> command line option. With a running <code>mb</code> process operating on port
|
|
7
|
+
3000, you can execute the following command:</p>
|
|
8
|
+
|
|
9
|
+
<pre><code>mb save --port 3000 --savefile saved.json --removeProxies</code></pre>
|
|
10
|
+
|
|
11
|
+
<p>All of the parameters are optional with the defaults listed in the table below. You could then
|
|
12
|
+
restart mountebank with the following command:</p>
|
|
13
|
+
|
|
14
|
+
<pre><code>mb restart --port 3000 --configfile saved.json</code></pre>
|
|
15
|
+
|
|
16
|
+
<p>The <code>save</code> command takes the following options:</p>
|
|
17
|
+
|
|
18
|
+
<table>
|
|
19
|
+
<tr>
|
|
20
|
+
<th style='width: 12em;'>Option</th>
|
|
21
|
+
<th>Description</th>
|
|
22
|
+
<th>Default</th>
|
|
23
|
+
</tr>
|
|
24
|
+
<tr>
|
|
25
|
+
<td><code>--port 2525</code></td>
|
|
26
|
+
<td>The port of the running the mountebank server</td>
|
|
27
|
+
<td><code>2525</code></td>
|
|
28
|
+
</tr>
|
|
29
|
+
<tr>
|
|
30
|
+
<td><code>--host mbserver.local</code></td>
|
|
31
|
+
<td>The hostname of the running mountebank server</td>
|
|
32
|
+
<td><code>localhost</code></td>
|
|
33
|
+
</tr>
|
|
34
|
+
<tr>
|
|
35
|
+
<td><code>--savefile saved.json</code></td>
|
|
36
|
+
<td>The file to save imposters to</td>
|
|
37
|
+
<td><code>mb.json</code></td>
|
|
38
|
+
</tr>
|
|
39
|
+
<tr>
|
|
40
|
+
<td><code>--formatter path/to/module</code></td>
|
|
41
|
+
<td>Historically, mountebank was limited to saving all configuration in a single file when
|
|
42
|
+
calling <code>mb save</code>. A custom formatter allows you to save test data in whatever format
|
|
43
|
+
you want (including in ways that convert between other service virtualization products). See
|
|
44
|
+
<a href='#custom-formatters'>below</a> for more details.</td>
|
|
45
|
+
<td><a href='https://github.com/mountebank-testing/mountebank-formatters'>mountebank-formatters</a></td>
|
|
46
|
+
</tr>
|
|
47
|
+
<tr>
|
|
48
|
+
<td><code>--removeProxies</code></td>
|
|
49
|
+
<td>Remove proxies from the saved configuration, useful when you want to switch
|
|
50
|
+
from record to replay mode. Corresponds to the
|
|
51
|
+
<code><a href='/docs/api/overview#get-imposters'>removeProxies</a></code> API
|
|
52
|
+
query parameter</td>
|
|
53
|
+
<td><code>false</code></td>
|
|
54
|
+
</tr>
|
|
55
|
+
<tr>
|
|
56
|
+
<td><code>--rcfile .mbrc</code></td>
|
|
57
|
+
<td>The run commands file containing startup configuration (a JSON-equivalent representation
|
|
58
|
+
of the command line arguments). When the same option is listed
|
|
59
|
+
in both the <code>rcfile</code> and the command line, the command line option takes
|
|
60
|
+
precedence.</td>
|
|
61
|
+
<td><code>N/A</code></td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td><code>--help</code></td>
|
|
65
|
+
<td>Show help for the command</td>
|
|
66
|
+
<td><code>N/A</code></td>
|
|
67
|
+
</tr>
|
|
68
|
+
</table>
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
<p><code>start</code> is the default <code>mb</code> command, meaning:</p>
|
|
2
|
+
|
|
3
|
+
<pre><code>mb start [options]</code></pre>
|
|
4
|
+
|
|
5
|
+
<p>is identical to</p>
|
|
6
|
+
|
|
7
|
+
<pre><code>mb [options]</code></pre>
|
|
8
|
+
|
|
9
|
+
<p>Running <code>mb</code> by itself, without any options, will start up the API
|
|
10
|
+
on port 2525. It will also spin up this website on http://localhost:2525/, giving
|
|
11
|
+
you accurate documentation for the version of mountebank you're running, as the
|
|
12
|
+
official site only contains the latest docs. The following options are available:</p>
|
|
13
|
+
|
|
14
|
+
<table>
|
|
15
|
+
<tr>
|
|
16
|
+
<th style='width: 12em;'>Option</th>
|
|
17
|
+
<th>Description</th>
|
|
18
|
+
<th>Default</th>
|
|
19
|
+
</tr>
|
|
20
|
+
<tr>
|
|
21
|
+
<td><code>--port 2525</code></td>
|
|
22
|
+
<td>The port to run the main mountebank server on</td>
|
|
23
|
+
<td><code>2525</code></td>
|
|
24
|
+
</tr>
|
|
25
|
+
<tr>
|
|
26
|
+
<td><code>--host mbserver.local</code></td>
|
|
27
|
+
<td>The hostname to bind the main mountebank server to</td>
|
|
28
|
+
<td><em>all hosts</em></td>
|
|
29
|
+
</tr>
|
|
30
|
+
<tr>
|
|
31
|
+
<td><code>--datadir .mbdb</code></td>
|
|
32
|
+
<td>The root directory for persisting all imposter changes. When used, mountebank
|
|
33
|
+
will start all imposters saved in the directory initially and persist all operations
|
|
34
|
+
to disk in real time, significantly reducing the memory footprint.
|
|
35
|
+
|
|
36
|
+
<p class='info-icon'>This option allows you to scale imposters with multiple processes
|
|
37
|
+
(running on multiple hosts behind a load balancer to avoid port collision), with the state
|
|
38
|
+
of all processes synced in real time. All mountebank processes will need to share the same volume.</td>
|
|
39
|
+
|
|
40
|
+
<td>Without this option, all configuration will be in memory. Keeping everything in memory can be a
|
|
41
|
+
significant performance hit when there is a lot of test data, for example, during proxy recording.</td>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td><code>--impostersRepository=./impostersRepo.js</code></td>
|
|
45
|
+
<td>Use a custom database instead of the built-in file-based data store that <code>datadir</code>
|
|
46
|
+
creates (when both are used, <code>impostersRepository</code> takes precedence). Creating
|
|
47
|
+
a custom database option is not documented and requires looking at the code, but the community
|
|
48
|
+
have created (or are creating) options. See <a href='//docs/communityExtensions'>community extensions</a>
|
|
49
|
+
for examples.</td>
|
|
50
|
+
</tr>
|
|
51
|
+
<tr>
|
|
52
|
+
<td><code>--configfile imposters.ejs</code></td>
|
|
53
|
+
<td>If present, mountebank will load the contents of the specified file. See
|
|
54
|
+
<a href='#config-files'>below</a> for details.
|
|
55
|
+
|
|
56
|
+
<p class='warning-icon'>If both the <code>datadir</code> and <code>configfile</code> options are
|
|
57
|
+
used, mountebank will initially load all imposters from the <code>datadir</code> and then add all from
|
|
58
|
+
the <code>configfile</code>. This means that when the same imposter port is saved in both places, what
|
|
59
|
+
is in the <code>datadir</code> will be immediately overwritten by what's in the <code>configfile</code>!</p></td>
|
|
60
|
+
<td><code>N/A</code></td>
|
|
61
|
+
</tr>
|
|
62
|
+
<tr>
|
|
63
|
+
<td><code>--formatter path/to/module</code></td>
|
|
64
|
+
<td>Historically, mountebank supported EJS templating when using the <code>configfile</code> option,
|
|
65
|
+
and was limited to saving all configuration in a single file when calling <code>mb save</code>. For
|
|
66
|
+
backwards compatibility, that remains the default option, even though EJS has subsequently made
|
|
67
|
+
breaking changes.
|
|
68
|
+
|
|
69
|
+
<p>A custom formatter allows you to save test data in whatever format you want (including in ways
|
|
70
|
+
that convert between other service virtualization products). See <a href='#custom-formatters'>below</a>
|
|
71
|
+
for more details. In the context of <code>mb start</code>, the formatter will be used to parse the <code>configfile</code>.</p>
|
|
72
|
+
</td>
|
|
73
|
+
<td><a href='https://github.com/mountebank-testing/mountebank-formatters'>mountebank-formatters</a></td>
|
|
74
|
+
</tr>
|
|
75
|
+
<tr>
|
|
76
|
+
<td><code>--noParse</code></td>
|
|
77
|
+
<td>By default, mountebank will render config files through EJS templating to
|
|
78
|
+
allow modularizing rich configuration. Use this flag if you aren't using templating
|
|
79
|
+
and have special character sequences in your configuration that
|
|
80
|
+
cause rendering errors.</td>
|
|
81
|
+
<td><code>false</code></td>
|
|
82
|
+
</tr>
|
|
83
|
+
<tr>
|
|
84
|
+
<td><code>--logfile mb.log</code></td>
|
|
85
|
+
<td>The file for mountebank to store the logs in</td>
|
|
86
|
+
<td><code>mb.log</code></td>
|
|
87
|
+
</tr>
|
|
88
|
+
<tr>
|
|
89
|
+
<td><code>--loglevel debug</code></td>
|
|
90
|
+
<td>The logging level, one of <code>debug, info, warn, error</code></td>
|
|
91
|
+
<td><code>info</code></td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td><code>--nologfile</code></td>
|
|
95
|
+
<td>Prevent logging to the filesystem</td>
|
|
96
|
+
<td><code>false</code></td>
|
|
97
|
+
</tr>
|
|
98
|
+
<tr>
|
|
99
|
+
<td><code>--log</code></td>
|
|
100
|
+
<td>Advanced logging configuration, when you want to customize the log formats. While you
|
|
101
|
+
can pass the JSON string on the command line, it's easier to put it in the <code>rcfile</code>.
|
|
102
|
+
If you pass <code>log</code>, the simpler logging configuration options
|
|
103
|
+
(<code>loglevel</code>, <code>logfile</code>, <code>nologfile</code>) will be ignored.
|
|
104
|
+
|
|
105
|
+
<p>You can set the format to "json" to log all fields as JSON, or set it to a string to
|
|
106
|
+
customize the format. The supported fields are:</p>
|
|
107
|
+
|
|
108
|
+
<ul class='bullet-list'>
|
|
109
|
+
<li>%level</li>
|
|
110
|
+
<li>%timestamp</li>
|
|
111
|
+
<li>%message</li>
|
|
112
|
+
</ul>
|
|
113
|
+
</td>
|
|
114
|
+
<td><pre><code>{
|
|
115
|
+
"level": "info",
|
|
116
|
+
"transports": {
|
|
117
|
+
"console": {
|
|
118
|
+
"colorize": true,
|
|
119
|
+
"format": "%level: %message"
|
|
120
|
+
},
|
|
121
|
+
"file": {
|
|
122
|
+
"path": "mb.log",
|
|
123
|
+
"format": "json"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}</code></pre></td>
|
|
127
|
+
</tr>
|
|
128
|
+
<tr>
|
|
129
|
+
<td><code>--allowInjection</code></td>
|
|
130
|
+
<td>mountebank supports JavaScript injection for <a href='/docs/api/predicates'>predicates</a>,
|
|
131
|
+
<a href='/docs/api/injection'>stub responses</a>, <a href='/docs/api/behaviors'>behavior decoration</a>,
|
|
132
|
+
<a href='/docs/api/behaviors'>wait behavior functions</a> and
|
|
133
|
+
<a href='/docs/protocols/tcp#endOfRequestResolver'>tcp request resolution</a>, but they are
|
|
134
|
+
disabled by default. Including this parameter will enable them.
|
|
135
|
+
|
|
136
|
+
<p class='warning-icon'>Note that allowing injection means that an attacker can run random
|
|
137
|
+
code on the machine running <code>mb</code>. Please see the <a href='/docs/security'>security page</a>
|
|
138
|
+
for tips on securing your system.</p>
|
|
139
|
+
</td>
|
|
140
|
+
<td><code>false</code></td>
|
|
141
|
+
</tr>
|
|
142
|
+
<tr>
|
|
143
|
+
<td><code>--localOnly</code></td>
|
|
144
|
+
<td>Only accept requests from localhost. You should ALWAYS do this when running mountebank with
|
|
145
|
+
<code>allowInjection</code> directly on your developer machine, but will need to use
|
|
146
|
+
<code>ipWhitelist</code> otherwise (or if running in Docker),</td>
|
|
147
|
+
<td><code>false</code></td>
|
|
148
|
+
</tr>
|
|
149
|
+
<tr>
|
|
150
|
+
<td><code>--ipWhitelist</code></td>
|
|
151
|
+
<td>A pipe-delimited string of remote IP addresses to whitelist (local IP addresses will always
|
|
152
|
+
be allowed). Any request to the primary <code>mb</code> socket or an imposter socket that isn't
|
|
153
|
+
whitelisted will be dropped.</td>
|
|
154
|
+
<td><code>*</code>, representing all IP addresses</td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<td><code>--origin</code></td>
|
|
158
|
+
<td>A safe origin for CORS requests. Use the flag multiple times to enable multiple origins.</td>
|
|
159
|
+
<td><code>false</code>, which disables CORS to prevent CSRF attacks.</td>
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td><code>--protofile</code></td>
|
|
163
|
+
<td>File to load custom <a href='/docs/protocols/custom'>protocol implementations</a> from.</td>
|
|
164
|
+
<td><code>protocols.json</code></td>
|
|
165
|
+
</tr>
|
|
166
|
+
<tr>
|
|
167
|
+
<td><code>--rcfile .mbrc</code></td>
|
|
168
|
+
<td>The run commands file containing startup configuration. The <code>rcfile</code>
|
|
169
|
+
format is a JSON-equivalent representation of the command line option. For example,
|
|
170
|
+
the following command line is very complex:
|
|
171
|
+
|
|
172
|
+
<pre><code>mb --port 3000 --allowInjection --origin 'http://first.com' --origin 'http://second.com' \
|
|
173
|
+
--log '{ "level": "warn", "transports": { "console": { "format": "json" } } }'</code></pre>
|
|
174
|
+
|
|
175
|
+
You could simplify it by putting the configuration in a file and running
|
|
176
|
+
|
|
177
|
+
<pre><code>mb start --rcfile .mbrc</code></pre>
|
|
178
|
+
|
|
179
|
+
The file .mbrc would look like the following:
|
|
180
|
+
|
|
181
|
+
<pre><code>{
|
|
182
|
+
"port": 3000,
|
|
183
|
+
"allowInjection": true,
|
|
184
|
+
"origin": ["http://first.com", "http://second.com"],
|
|
185
|
+
"log": {
|
|
186
|
+
"level": "warn",
|
|
187
|
+
"transports": {
|
|
188
|
+
"console": {
|
|
189
|
+
"format": "json"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}</code></pre>
|
|
194
|
+
|
|
195
|
+
When the same option is listed in both the <code>rcfile</code> and the command line,
|
|
196
|
+
the command line option takes precedence.
|
|
197
|
+
</td>
|
|
198
|
+
<td><code>N/A</code></td>
|
|
199
|
+
</tr>
|
|
200
|
+
<tr>
|
|
201
|
+
<td><code>--debug</code></td>
|
|
202
|
+
<td>Include a <code>matches</code> array with each stub in the body of a
|
|
203
|
+
<a href='/docs/api/overview#get-imposter'>GET imposter</a> response
|
|
204
|
+
for debugging why a particular stub did or did not match a request.
|
|
205
|
+
Every time a response from the stub is used, a match will be added containing
|
|
206
|
+
the request, the response configuration, the actual generated response (even
|
|
207
|
+
if it is proxied), and the overall processing time.
|
|
208
|
+
<td><code>false</code></td>
|
|
209
|
+
</tr>
|
|
210
|
+
<tr>
|
|
211
|
+
<td><code>--pidfile</code></td>
|
|
212
|
+
<td>The file where the process id is stored for the <code>mb stop</code> command</td>
|
|
213
|
+
<td><code>mb.pid</code></td>
|
|
214
|
+
</tr>
|
|
215
|
+
<tr>
|
|
216
|
+
<td><code>--apikey myapikey</code></td>
|
|
217
|
+
<td>
|
|
218
|
+
An optional API key. When this is provided,
|
|
219
|
+
the Mountebank API will require that the x-api-key
|
|
220
|
+
header be supplied with a matching key.
|
|
221
|
+
</td>
|
|
222
|
+
<td><code>null</code></td>
|
|
223
|
+
</tr>
|
|
224
|
+
<tr>
|
|
225
|
+
<td><code>--version</code></td>
|
|
226
|
+
<td>Print the version out to the console and exit.</td>
|
|
227
|
+
<td><code>N/A</code></td>
|
|
228
|
+
</tr>
|
|
229
|
+
<tr>
|
|
230
|
+
<td><code>--help</code></td>
|
|
231
|
+
<td>Show help for the command</td>
|
|
232
|
+
<td><code>N/A</code></td>
|
|
233
|
+
</tr>
|
|
234
|
+
</table>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<pre><code>mb stop [options]</code></pre>
|
|
2
|
+
|
|
3
|
+
<p>Stops <code>mb</code>, shutting down all open sockets. Generally, <code>mb stop</code>
|
|
4
|
+
must be run from the same directory as the <code>mb start</code> command, although
|
|
5
|
+
that is configurable with the <code>pidfile</code> option:</p>
|
|
6
|
+
|
|
7
|
+
<table>
|
|
8
|
+
<tr>
|
|
9
|
+
<th style='width: 12em;'>Option</th>
|
|
10
|
+
<th>Description</th>
|
|
11
|
+
<th>Default</th>
|
|
12
|
+
</tr>
|
|
13
|
+
<tr>
|
|
14
|
+
<td><code>--pidfile</code></td>
|
|
15
|
+
<td>The path to the pidfile, which stores the process id of the running <code>mb</code> process.
|
|
16
|
+
Must match the pidfile passed in the <code>mb start</code> command.</td>
|
|
17
|
+
<td><code>mb.pid</code></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<tr>
|
|
20
|
+
<td><code>--rcfile .mbrc</code></td>
|
|
21
|
+
<td>The run commands file containing startup configuration (a JSON-equivalent representation
|
|
22
|
+
of the command line arguments). When the same option is listed
|
|
23
|
+
in both the <code>rcfile</code> and the command line, the command line option takes
|
|
24
|
+
precedence.</td>
|
|
25
|
+
<td><code>N/A</code></td>
|
|
26
|
+
</tr>
|
|
27
|
+
<tr>
|
|
28
|
+
<td><code>--help</code></td>
|
|
29
|
+
<td>Show help for the command</td>
|
|
30
|
+
<td><code>N/A</code></td>
|
|
31
|
+
</tr>
|
|
32
|
+
</table>
|