@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.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/bin/mb +136 -0
  4. package/package.json +71 -0
  5. package/releases.json +52 -0
  6. package/src/cli/api.js +112 -0
  7. package/src/cli/cli.js +420 -0
  8. package/src/controllers/configController.js +64 -0
  9. package/src/controllers/feedController.js +115 -0
  10. package/src/controllers/homeController.js +58 -0
  11. package/src/controllers/imposterController.js +328 -0
  12. package/src/controllers/impostersController.js +215 -0
  13. package/src/controllers/logsController.js +52 -0
  14. package/src/models/behaviors.js +553 -0
  15. package/src/models/behaviorsValidator.js +186 -0
  16. package/src/models/compatibility.js +133 -0
  17. package/src/models/dryRunValidator.js +261 -0
  18. package/src/models/filesystemBackedImpostersRepository.js +908 -0
  19. package/src/models/http/baseHttpServer.js +207 -0
  20. package/src/models/http/headersMap.js +87 -0
  21. package/src/models/http/httpProxy.js +230 -0
  22. package/src/models/http/httpRequest.js +82 -0
  23. package/src/models/http/httpServer.js +18 -0
  24. package/src/models/http/index.js +18 -0
  25. package/src/models/https/cert/mb-cert.pem +20 -0
  26. package/src/models/https/cert/mb-csr.pem +16 -0
  27. package/src/models/https/cert/mb-key.pem +27 -0
  28. package/src/models/https/httpsServer.js +42 -0
  29. package/src/models/https/index.js +18 -0
  30. package/src/models/imposter.js +243 -0
  31. package/src/models/imposterPrinter.js +120 -0
  32. package/src/models/impostersRepository.js +49 -0
  33. package/src/models/inMemoryImpostersRepository.js +418 -0
  34. package/src/models/jsonpath.js +44 -0
  35. package/src/models/mbConnection.js +107 -0
  36. package/src/models/predicates.js +438 -0
  37. package/src/models/protocols.js +242 -0
  38. package/src/models/responseResolver.js +398 -0
  39. package/src/models/smtp/index.js +16 -0
  40. package/src/models/smtp/smtpRequest.js +60 -0
  41. package/src/models/smtp/smtpServer.js +109 -0
  42. package/src/models/tcp/index.js +18 -0
  43. package/src/models/tcp/tcpProxy.js +110 -0
  44. package/src/models/tcp/tcpRequest.js +23 -0
  45. package/src/models/tcp/tcpServer.js +156 -0
  46. package/src/models/tcp/tcpValidator.js +19 -0
  47. package/src/models/xpath.js +95 -0
  48. package/src/mountebank.js +245 -0
  49. package/src/public/images/arrow_down.png +0 -0
  50. package/src/public/images/arrow_up.png +0 -0
  51. package/src/public/images/book.jpg +0 -0
  52. package/src/public/images/dataflow.png +0 -0
  53. package/src/public/images/favicon.ico +0 -0
  54. package/src/public/images/forkme_right_orange_ff7600.png +0 -0
  55. package/src/public/images/mountebank.png +0 -0
  56. package/src/public/images/overview.gif +0 -0
  57. package/src/public/images/quote.png +0 -0
  58. package/src/public/images/tw-logo.png +0 -0
  59. package/src/public/scripts/jquery/jquery-3.6.1.min.js +2 -0
  60. package/src/public/scripts/urlHashHandler.js +31 -0
  61. package/src/public/stylesheets/application.css +424 -0
  62. package/src/public/stylesheets/ie.css +14 -0
  63. package/src/public/stylesheets/imposters.css +121 -0
  64. package/src/public/stylesheets/jqueryui/1.10.4/themes/smoothness/jquery-ui.css +1178 -0
  65. package/src/util/combinators.js +68 -0
  66. package/src/util/date.js +51 -0
  67. package/src/util/errors.js +55 -0
  68. package/src/util/helpers.js +131 -0
  69. package/src/util/inherit.js +28 -0
  70. package/src/util/ip.js +54 -0
  71. package/src/util/logger.js +83 -0
  72. package/src/util/middleware.js +256 -0
  73. package/src/util/scopedLogger.js +47 -0
  74. package/src/views/_footer.ejs +20 -0
  75. package/src/views/_header.ejs +113 -0
  76. package/src/views/_imposter.ejs +8 -0
  77. package/src/views/config.ejs +71 -0
  78. package/src/views/docs/api/behaviors/copy.ejs +427 -0
  79. package/src/views/docs/api/behaviors/decorate.ejs +182 -0
  80. package/src/views/docs/api/behaviors/lookup.ejs +220 -0
  81. package/src/views/docs/api/behaviors/shellTransform.ejs +153 -0
  82. package/src/views/docs/api/behaviors/wait.ejs +121 -0
  83. package/src/views/docs/api/behaviors.ejs +141 -0
  84. package/src/views/docs/api/contracts/addStub-description.ejs +10 -0
  85. package/src/views/docs/api/contracts/addStub.ejs +10 -0
  86. package/src/views/docs/api/contracts/config-description.ejs +32 -0
  87. package/src/views/docs/api/contracts/config.ejs +23 -0
  88. package/src/views/docs/api/contracts/home-description.ejs +18 -0
  89. package/src/views/docs/api/contracts/home.ejs +13 -0
  90. package/src/views/docs/api/contracts/imposter-description.ejs +439 -0
  91. package/src/views/docs/api/contracts/imposter.ejs +182 -0
  92. package/src/views/docs/api/contracts/imposters-description.ejs +13 -0
  93. package/src/views/docs/api/contracts/imposters.ejs +13 -0
  94. package/src/views/docs/api/contracts/logs-description.ejs +3 -0
  95. package/src/views/docs/api/contracts/logs.ejs +14 -0
  96. package/src/views/docs/api/contracts/stub-description.ejs +4 -0
  97. package/src/views/docs/api/contracts/stub.ejs +7 -0
  98. package/src/views/docs/api/contracts/stubs-description.ejs +4 -0
  99. package/src/views/docs/api/contracts/stubs.ejs +11 -0
  100. package/src/views/docs/api/contracts.ejs +133 -0
  101. package/src/views/docs/api/errors.ejs +64 -0
  102. package/src/views/docs/api/fault/connectionReset.ejs +31 -0
  103. package/src/views/docs/api/fault/randomDataThenClose.ejs +31 -0
  104. package/src/views/docs/api/faults.ejs +57 -0
  105. package/src/views/docs/api/injection.ejs +426 -0
  106. package/src/views/docs/api/json.ejs +205 -0
  107. package/src/views/docs/api/jsonpath.ejs +210 -0
  108. package/src/views/docs/api/mocks.ejs +130 -0
  109. package/src/views/docs/api/overview.ejs +968 -0
  110. package/src/views/docs/api/predicates/and.ejs +62 -0
  111. package/src/views/docs/api/predicates/contains.ejs +64 -0
  112. package/src/views/docs/api/predicates/deepEquals.ejs +114 -0
  113. package/src/views/docs/api/predicates/endsWith.ejs +66 -0
  114. package/src/views/docs/api/predicates/equals.ejs +125 -0
  115. package/src/views/docs/api/predicates/exists.ejs +118 -0
  116. package/src/views/docs/api/predicates/inject.ejs +67 -0
  117. package/src/views/docs/api/predicates/matches.ejs +66 -0
  118. package/src/views/docs/api/predicates/not.ejs +52 -0
  119. package/src/views/docs/api/predicates/or.ejs +79 -0
  120. package/src/views/docs/api/predicates/startsWith.ejs +62 -0
  121. package/src/views/docs/api/predicates.ejs +382 -0
  122. package/src/views/docs/api/proxies.ejs +191 -0
  123. package/src/views/docs/api/proxy/addDecorateBehavior.ejs +115 -0
  124. package/src/views/docs/api/proxy/addWaitBehavior.ejs +96 -0
  125. package/src/views/docs/api/proxy/injectHeaders.ejs +91 -0
  126. package/src/views/docs/api/proxy/predicateGenerators.ejs +600 -0
  127. package/src/views/docs/api/proxy/proxyModes.ejs +495 -0
  128. package/src/views/docs/api/stubs.ejs +391 -0
  129. package/src/views/docs/api/xpath.ejs +281 -0
  130. package/src/views/docs/cli/configFiles.ejs +133 -0
  131. package/src/views/docs/cli/customFormatters.ejs +53 -0
  132. package/src/views/docs/cli/help.ejs +6 -0
  133. package/src/views/docs/cli/replay.ejs +42 -0
  134. package/src/views/docs/cli/restart.ejs +10 -0
  135. package/src/views/docs/cli/save.ejs +68 -0
  136. package/src/views/docs/cli/start.ejs +234 -0
  137. package/src/views/docs/cli/stop.ejs +32 -0
  138. package/src/views/docs/commandLine.ejs +93 -0
  139. package/src/views/docs/communityExtensions.ejs +233 -0
  140. package/src/views/docs/gettingStarted.ejs +146 -0
  141. package/src/views/docs/mentalModel.ejs +51 -0
  142. package/src/views/docs/protocols/custom.ejs +231 -0
  143. package/src/views/docs/protocols/http.ejs +238 -0
  144. package/src/views/docs/protocols/https.ejs +246 -0
  145. package/src/views/docs/protocols/smtp.ejs +142 -0
  146. package/src/views/docs/protocols/tcp.ejs +431 -0
  147. package/src/views/docs/security.ejs +38 -0
  148. package/src/views/faqs.ejs +65 -0
  149. package/src/views/feed.ejs +33 -0
  150. package/src/views/imposter.ejs +22 -0
  151. package/src/views/imposters.ejs +33 -0
  152. package/src/views/index.ejs +89 -0
  153. package/src/views/license.ejs +30 -0
  154. package/src/views/logs.ejs +77 -0
  155. package/src/views/releases/v1.1.0.ejs +55 -0
  156. package/src/views/releases/v1.1.36.ejs +84 -0
  157. package/src/views/releases/v1.1.72.ejs +92 -0
  158. package/src/views/releases/v1.10.0.ejs +108 -0
  159. package/src/views/releases/v1.11.0.ejs +109 -0
  160. package/src/views/releases/v1.12.0.ejs +96 -0
  161. package/src/views/releases/v1.13.0.ejs +118 -0
  162. package/src/views/releases/v1.14.0.ejs +107 -0
  163. package/src/views/releases/v1.14.1.ejs +94 -0
  164. package/src/views/releases/v1.15.0.ejs +113 -0
  165. package/src/views/releases/v1.16.0.ejs +104 -0
  166. package/src/views/releases/v1.2.0.ejs +78 -0
  167. package/src/views/releases/v1.2.103.ejs +86 -0
  168. package/src/views/releases/v1.2.122.ejs +86 -0
  169. package/src/views/releases/v1.2.30.ejs +84 -0
  170. package/src/views/releases/v1.2.45.ejs +84 -0
  171. package/src/views/releases/v1.2.56.ejs +79 -0
  172. package/src/views/releases/v1.3.0.ejs +86 -0
  173. package/src/views/releases/v1.3.1.ejs +100 -0
  174. package/src/views/releases/v1.4.0.ejs +96 -0
  175. package/src/views/releases/v1.4.1.ejs +103 -0
  176. package/src/views/releases/v1.4.2.ejs +100 -0
  177. package/src/views/releases/v1.4.3.ejs +113 -0
  178. package/src/views/releases/v1.5.0.ejs +104 -0
  179. package/src/views/releases/v1.5.1.ejs +91 -0
  180. package/src/views/releases/v1.6.0.ejs +109 -0
  181. package/src/views/releases/v1.7.0.ejs +113 -0
  182. package/src/views/releases/v1.7.1.ejs +90 -0
  183. package/src/views/releases/v1.7.2.ejs +96 -0
  184. package/src/views/releases/v1.8.0.ejs +121 -0
  185. package/src/views/releases/v1.9.0.ejs +111 -0
  186. package/src/views/releases/v2.0.0.ejs +159 -0
  187. package/src/views/releases/v2.1.0.ejs +121 -0
  188. package/src/views/releases/v2.1.1.ejs +106 -0
  189. package/src/views/releases/v2.1.2.ejs +84 -0
  190. package/src/views/releases/v2.2.0.ejs +115 -0
  191. package/src/views/releases/v2.2.1.ejs +102 -0
  192. package/src/views/releases/v2.3.0.ejs +121 -0
  193. package/src/views/releases/v2.3.1.ejs +100 -0
  194. package/src/views/releases/v2.3.2.ejs +102 -0
  195. package/src/views/releases/v2.3.3.ejs +97 -0
  196. package/src/views/releases/v2.4.0.ejs +114 -0
  197. package/src/views/releases/v2.5.0.ejs +51 -0
  198. package/src/views/releases/v2.6.0.ejs +35 -0
  199. package/src/views/releases/v2.7.0.ejs +32 -0
  200. package/src/views/releases/v2.8.0.ejs +36 -0
  201. package/src/views/releases/v2.8.1.ejs +7 -0
  202. package/src/views/releases/v2.8.2.ejs +26 -0
  203. package/src/views/releases/v2.9.0.ejs +32 -0
  204. package/src/views/releases/v2.9.1.ejs +10 -0
  205. package/src/views/releases.ejs +26 -0
  206. package/src/views/sitemap.ejs +36 -0
  207. package/src/views/support.ejs +14 -0
@@ -0,0 +1,191 @@
1
+ <%
2
+ title = 'proxies'
3
+ description = 'Using mountebank to record and playback through proxying to a real network dependency'
4
+ %>
5
+
6
+ <%- include('../../_header') -%>
7
+
8
+ <h1>Proxies</h1>
9
+
10
+ <p>Proxies are one of the most powerful features of mountebank, rivaled only by the
11
+ mighty <a href='/docs/api/injection'>injection.</a> Proxies support record/replay
12
+ behavior to easily capture a rich set of test data for your test scenarios.
13
+ Each proxy definition allows you to define the fields which should be included
14
+ in newly created <code>predicates</code>.</p>
15
+
16
+ <p><code>proxy</code> response types take the following parameters:</p>
17
+
18
+ <table>
19
+ <tr>
20
+ <th>Parameter</th>
21
+ <th style='min-width: 4em;'>Default</th>
22
+ <th>Type</th>
23
+ <th>Description</th>
24
+ </tr>
25
+ <tr>
26
+ <td><code>to</code></td>
27
+ <td>required</td>
28
+ <td>A URL without the path (e.g. http://someserver:3000 or tcp://someserver:3000)</td>
29
+ <td>Defines the origin server that the request should proxy to.</td>
30
+ </tr>
31
+ <tr>
32
+ <td><code>predicateGenerators</code></td>
33
+ <td><code>[]</code></td>
34
+ <td>array</td>
35
+ <td>An array of objects that defines how the predicates for new stubs are created. Each object in
36
+ the array defines the fields to generate predicates from. See <a href='#proxy-predicate-generators'>below</a>
37
+ for examples.</td>
38
+ </tr>
39
+ <tr>
40
+ <td><code>mode</code></td>
41
+ <td><code>proxyOnce</code></td>
42
+ <td>string, one of <code>proxyOnce</code>, <code>proxyAlways</code> or <code>proxyTransparent</code>.</td>
43
+ <td>Defines the replay behavior of the proxy. The default <code>proxyOnce</code> mode
44
+ doesn't require you to explicitly do anything to replay the proxied responses. The
45
+ <code>proxyAlways</code> mode requires you to run the
46
+ <a href='/docs/commandLine'><code>mb replay</code></a> command (or equivalent) to
47
+ switch from record mode to replay mode, but allows a richer set of data to be
48
+ recorded. The <code>proxyTransparent</code> mode proxies the request but does not record any data.
49
+ See <a href='#proxy-modes'>below</a> for details.</td>
50
+ </tr>
51
+ <tr>
52
+ <td><code>addWaitBehavior</code></td>
53
+ <td><code>false</code></td>
54
+ <td>boolean</td>
55
+ <td>If true, mountebank will add a <a href='/docs/api/behaviors#behavior-wait'><code>wait</code></a>
56
+ behavior to the response with the same latency that the proxied call took. This is useful in performance
57
+ testing scenarios where you want to simulate the actual latency of downstream services that you're
58
+ virtualizing.</td>
59
+ </tr>
60
+ <tr>
61
+ <td><code>addDecorateBehavior</code></td>
62
+ <td><code>null</code></td>
63
+ <td>string, JavaScript</td>
64
+ <td>If defined, mountebank will add a <a href='/docs/api/behaviors#behavior-decorate'><code>decorate</code></a>
65
+ behavior to the saved response.</td>
66
+ </tr>
67
+ </table>
68
+
69
+ <p>http and https proxies add additional optional parameters:</p>
70
+
71
+ <table>
72
+ <tr>
73
+ <th>Parameter</th>
74
+ <th style='min-width: 4em;'>Default</th>
75
+ <th>Type</th>
76
+ <th>Description</th>
77
+ </tr>
78
+ <tr>
79
+ <td><code>cert</code></td>
80
+ <td><code>null</code></td>
81
+ <td>A PEM-formatted string</td>
82
+ <td>The SSL client certificate</td>
83
+ </tr>
84
+ <tr>
85
+ <td><code>key</code></td>
86
+ <td><code>null</code></td>
87
+ <td>A PEM-formatted string</td>
88
+ <td>The SSL client private key</td>
89
+ </tr>
90
+ <tr>
91
+ <td><code>ciphers</code></td>
92
+ <td><a href='https://nodejs.org/dist/latest-v14.x/docs/api/tls.html#tls_tls_getciphers'>Here</a></td>
93
+ <td>A valid cipher (see <a href='https://nodejs.org/api/tls.html#tls_modifying_the_default_tls_cipher_suite'>this page</a> for formats)</td>
94
+ <td>For older (and insecure) https servers, this field allows you to override the cipher used to communicate</td>
95
+ </tr>
96
+ <tr>
97
+ <td><code>secureProtocol</code></td>
98
+ <td><code>TLS_method</code></td>
99
+ <td>A valid <a href='https://www.openssl.org/docs/man1.1.0/man7/ssl.html#Dealing-with-Protocol-Methods'>
100
+ OpenSSL protocol method name</a></td>
101
+ <td>The SSL method to use</td>
102
+ </tr>
103
+ <tr>
104
+ <td><code>passphrase</code></td>
105
+ <td><code>null</code></td>
106
+ <td>string</td>
107
+ <td>Shared passphrase used for a single private key</td>
108
+ </tr>
109
+ <tr>
110
+ <td><code>injectHeaders</code></td>
111
+ <td><code>{}</code></td>
112
+ <td>object</td>
113
+ <td>Key-value pairs of headers to inject into the proxied <i>request</i>.</td>
114
+ </tr>
115
+ </table>
116
+
117
+ <p>tcp proxies support the following optional configuration:</p>
118
+
119
+ <table>
120
+ <tr>
121
+ <th>Parameter</th>
122
+ <th style='min-width: 4em;'>Default</th>
123
+ <th>Type</th>
124
+ <th>Description</th>
125
+ </tr>
126
+ <tr>
127
+ <td><code>keepalive</code></td>
128
+ <td><code>false</code></td>
129
+ <td>boolean</td>
130
+ <td>If true, mountebank will not close the connection on each proxied request</td>
131
+ </tr>
132
+ </table>
133
+
134
+ <p>It is occasionally useful to capture how long the original proxied request takes. mountebank
135
+ stores the number of milliseconds for the request in the <code>_proxyResponseTime</code> field in the
136
+ response. Setting the <code>addWaitBehavior</code> flag will add that latency to the saved response.</p>
137
+
138
+ <p class='info-icon'>Note, if you use a corporate proxy, then the standard shell
139
+ <code>http_proxy</code> or <code>https_proxy</code> environment variables will be honored.</p>
140
+
141
+ <p>Select the behavior of the proxy below for a relevant example:</p>
142
+
143
+ <section class='accordion'>
144
+ <div>
145
+ <a class='section-toggler'
146
+ id='proxy-predicate-generators' name='proxy-predicate-generators' href='#proxy-predicate-generators'>
147
+ Understanding predicateGenerators
148
+ </a>
149
+ <section>
150
+ <%- include('proxy/predicateGenerators') -%>
151
+ </section>
152
+ </div>
153
+ <div>
154
+ <a class='section-toggler'
155
+ id='proxy-modes' name='proxy-modes' href='#proxy-modes'>
156
+ Understanding proxy modes
157
+ </a>
158
+ <section>
159
+ <%- include('proxy/proxyModes') -%>
160
+ </section>
161
+ </div>
162
+ <div>
163
+ <a class='section-toggler'
164
+ id='proxy-add-wait-behavior' name='proxy-add-wait-behavior' href='#proxy-add-wait-behavior'>
165
+ Adding latency to the saved responses with addWaitBehavior
166
+ </a>
167
+ <section>
168
+ <%- include('proxy/addWaitBehavior') -%>
169
+ </section>
170
+ </div>
171
+ <div>
172
+ <a class='section-toggler'
173
+ id='proxy-add-decorate-behavior' name='proxy-add-decorate-behavior' href='#proxy-add-decorate-behavior'>
174
+ Decorating saved responses with addDecorateBehavior
175
+ </a>
176
+ <section>
177
+ <%- include('proxy/addDecorateBehavior') -%>
178
+ </section>
179
+ </div>
180
+ <div>
181
+ <a class='section-toggler'
182
+ id='proxy-inject-headers' name='proxy-inject-headers' href='#proxy-inject-headers'>
183
+ Changing the proxied request headers with injectHeaders
184
+ </a>
185
+ <section>
186
+ <%- include('proxy/injectHeaders') -%>
187
+ </section>
188
+ </div>
189
+ </section>
190
+
191
+ <%- include('../../_footer') -%>
@@ -0,0 +1,115 @@
1
+ <p>A <a href='/docs/api/behaviors#behavior-decorate'><code>decorate</code> behavior</a> on a
2
+ <code>proxy</code> response affects the proxy response itself, not the saved response
3
+ that the proxy creates. If you want to add a <code>decorate</code> behavior on the saved
4
+ response, you do so with the <code>addDecorateBehavior</code> field.</p>
5
+
6
+ <testScenario name='decorateBehavior'>
7
+ <step type='http'>
8
+ <code class='hidden'>POST /imposters HTTP/1.1
9
+ Host: localhost:<%= port %>
10
+ Content-Type: application/json
11
+
12
+ {
13
+ "port": 5002,
14
+ "protocol": "http",
15
+ "stubs": [{
16
+ "responses": [{
17
+ "is": { "body": "downstream service response" }
18
+ }]
19
+ }]
20
+ }</code>
21
+ </step>
22
+
23
+ <p>We'll decorate our saved responses with the following JavaScript function:</p>
24
+
25
+ <pre><code>config => {
26
+ config.response.body = config.response.body + ' DECORATED!';
27
+ }</code></pre>
28
+
29
+ <p>Add that function in the <code>addDecorateBehavior</code> field of the proxy
30
+ configuration:</p>
31
+
32
+ <step type='http'>
33
+ <pre><code><span class='hidden'>POST /imposters HTTP/1.1
34
+ Host: localhost:<%= port %>
35
+ Content-Type: application/json
36
+
37
+ {
38
+ "port": 5000,
39
+ "protocol": "http",
40
+ </span>"stubs": [{
41
+ "responses": [{
42
+ "proxy": {
43
+ "to": "<change to='http://localhost:5002'>http://origin-server.com</change>",
44
+ <strong class='highlight1'>"addDecorateBehavior": "config => { config.response.body = config.response.body + ' DECORATED!'; }"</strong>
45
+ }
46
+ }]
47
+ }]<span class='hidden'>}</span></code></pre>
48
+ </step>
49
+
50
+ <p>Next we'll send a request to our proxy imposter to create a new saved response. Notice
51
+ that the decorator doesn't affect the proxied response (to do that, we'd have to add the
52
+ same function as a <code>decorate</code> behavior on the <code>proxy</code> response too):</p>
53
+
54
+ <step type='http'>
55
+ <pre><code>GET / HTTP/1.1
56
+ Host: <change to='localhost:5000'>origin-server.com</change></code></pre>
57
+
58
+ <assertResponse>
59
+ <pre><code>HTTP/1.1 200 OK
60
+ Connection: close
61
+ Date: <volatile>Fri, 19 May 2017 19:39:02 GMT</volatile>
62
+ Transfer-Encoding: chunked
63
+
64
+ downstream service response</code></pre>
65
+ </assertResponse>
66
+ </step>
67
+
68
+ <p>If you look at the imposter configuration, you'll notice the new <code>decorate</code>
69
+ behavior. </p>
70
+
71
+ <step type='http'>
72
+ <code class='hidden'>GET /imposters/5000 HTTP/1.1
73
+ Host: localhost:<%= port %></code>
74
+
75
+ <assertResponse partial='true'>
76
+ <pre><code><span class='hidden'>{
77
+ </span>"stubs": [
78
+ {
79
+ "predicates": [],
80
+ "responses": [{
81
+ "is": {
82
+ "body": "downstream service response"<change to=''>,</change>
83
+ <change to=''>...</change>
84
+ },
85
+ <strong class='highlight1'>"behaviors": [
86
+ {
87
+ "decorate": "config => { config.response.body = config.response.body + ' DECORATED!'; }"
88
+ }
89
+ ]</strong>
90
+ }]
91
+ },
92
+ {
93
+ "responses": [{
94
+ "proxy": {
95
+ "to": "<change to='http://localhost:5002'>http://origin-server.com</change>",
96
+ "addDecorateBehavior": "config => { config.response.body = config.response.body + ' DECORATED!'; }"
97
+ }
98
+ }]
99
+ }
100
+ ]<span class='hidden'>}</span></code></pre>
101
+ </assertResponse>
102
+ </step>
103
+
104
+ <step type='http'>
105
+ <code class='hidden'>DELETE /imposters/5002 HTTP/1.1
106
+ Host: localhost:<%= port %>
107
+ Accept: application/json</code>
108
+ </step>
109
+
110
+ <step type='http'>
111
+ <code class='hidden'>DELETE /imposters/5000 HTTP/1.1
112
+ Host: localhost:<%= port %>
113
+ Accept: application/json</code>
114
+ </step>
115
+ </testScenario>
@@ -0,0 +1,96 @@
1
+ <p>Every response saves the time it took to call the downstream service in the
2
+ <code>_proxyResponseTime</code> field. You can tell mountebank to automatically
3
+ translate that into a <a href='/docs/api/behaviors#behavior-wait'>wait behavior</a>,
4
+ which will add the same latency to the saved response. This is a useful technique
5
+ during performance testing, where you want to virtualize downstream services but
6
+ still want realistic latencies.</p>
7
+
8
+ <testScenario name='waitBehavior'>
9
+ <step type='http'>
10
+ <code class='hidden'>POST /imposters HTTP/1.1
11
+ Host: localhost:<%= port %>
12
+ Content-Type: application/json
13
+
14
+ {
15
+ "port": 6001,
16
+ "protocol": "http"
17
+ }</code>
18
+ </step>
19
+
20
+ <p>Let's create the following proxy configuration:</p>
21
+
22
+ <step type='http'>
23
+ <pre><code><span class='hidden'>POST /imposters HTTP/1.1
24
+ Host: localhost:<%= port %>
25
+ Content-Type: application/json
26
+
27
+ {
28
+ "port": 6000,
29
+ "protocol": "http",
30
+ </span>"stubs": [{
31
+ "responses": [{
32
+ "proxy": {
33
+ "to": "<change to='http://localhost:6001'>http://origin-server.com</change>",
34
+ <strong class='highlight1'>"addWaitBehavior": true</strong>
35
+ }
36
+ }]
37
+ }]<span class='hidden'>}</span></code></pre>
38
+ </step>
39
+
40
+ <p>Next we'll send a request to our proxy imposter to create a new saved response:</p>
41
+
42
+ <step type='http'>
43
+ <pre><code>GET / HTTP/1.1
44
+ Host: <change to='localhost:6000'>origin-server.com</change></code></pre>
45
+ </step>
46
+
47
+ <p>If you look at the imposter configuration, you'll notice the new <code>wait</code>
48
+ behavior. The value will be the same as the <code>_proxyResponseTime</code> field, which
49
+ means that the saved response will add the same latency as the real service.</p>
50
+
51
+ <step type='http'>
52
+ <code class='hidden'>GET /imposters/6000 HTTP/1.1
53
+ Host: localhost:<%= port %></code>
54
+
55
+ <assertResponse partial='true'>
56
+ <pre><code><span class='hidden'>{
57
+ </span>"stubs": [
58
+ {
59
+ "predicates": [],
60
+ "responses": [{
61
+ "is": {
62
+ "statusCode": 200,
63
+ <change to=''>...</change>
64
+ <strong class='highlight2'>"_proxyResponseTime": <volatile>219</volatile></strong>
65
+ },
66
+ <strong class='highlight1'>"behaviors": [
67
+ {
68
+ "wait": <volatile>219</volatile>
69
+ }
70
+ ]</strong>
71
+ }]
72
+ },
73
+ {
74
+ "responses": [{
75
+ "proxy": {
76
+ "to": "<change to='http://localhost:6001'>http://origin-server.com</change>",
77
+ "addWaitBehavior": true
78
+ }
79
+ }]
80
+ }
81
+ ]<span class='hidden'>}</span></code></pre>
82
+ </assertResponse>
83
+ </step>
84
+
85
+ <step type='http'>
86
+ <code class='hidden'>DELETE /imposters/6001 HTTP/1.1
87
+ Host: localhost:<%= port %>
88
+ Accept: application/json</code>
89
+ </step>
90
+
91
+ <step type='http'>
92
+ <code class='hidden'>DELETE /imposters/6000 HTTP/1.1
93
+ Host: localhost:<%= port %>
94
+ Accept: application/json</code>
95
+ </step>
96
+ </testScenario>
@@ -0,0 +1,91 @@
1
+ <p>The <code>injectHeaders</code> field allows you to modify the request headers before
2
+ passing them on to the downstream service. To demonstrate, let's create a mirror imposter
3
+ so we can see what headers are sent. This imposter just takes the request
4
+ headers it receives and sends them back in the response:</p>
5
+
6
+ <p class='info-icon'><code>injectHeaders</code> only work for http/s proxies</p>
7
+
8
+ <testScenario name='injectHeaders'>
9
+ <step type='http'>
10
+ <pre><code>POST /imposters HTTP/1.1
11
+ Host: localhost:<%= port %>
12
+ Content-Type: application/json
13
+
14
+ {
15
+ "port": 7002,
16
+ "protocol": "http",
17
+ "name": "Mirror",
18
+ "stubs": [{
19
+ "responses": [{
20
+ "is": { "body": "The body." },
21
+ "behaviors": [
22
+ { "decorate": "function (req, res) { res.headers = req.headers; }" }
23
+ ]
24
+ }]
25
+ }]
26
+ }</code></pre>
27
+ </step>
28
+
29
+ <p>Now let's set up another imposter that will proxy requests to the mirror imposter.
30
+ We'll also set up the inject headers field to insert some custom headers in the outgoing request:</p>
31
+
32
+ <step type='http'>
33
+ <pre><code>POST /imposters HTTP/1.1
34
+ Host: localhost:<%= port %>
35
+ Content-Type: application/json
36
+
37
+ {
38
+ "port": 7001,
39
+ "protocol": "http",
40
+ "name": "Inject Headers",
41
+ "stubs": [{
42
+ "responses": [{
43
+ "proxy": {
44
+ "to": "http://localhost:7002",
45
+ <strong class='highlight1'>"injectHeaders": {
46
+ "X-My-Custom-Header-One": "my first value",
47
+ "X-My-Custom-Header-Two": "my second value"
48
+ }</strong>
49
+ }
50
+ }]
51
+ }]
52
+ }</code></pre>
53
+ </step>
54
+
55
+ <p>Then we send a request to our proxy imposter:</p>
56
+
57
+ <step type='http'>
58
+ <pre><code>GET / HTTP/1.1
59
+ Host: localhost:7001</code></pre>
60
+
61
+ <assertResponse>
62
+ <pre><code>HTTP/1.1 200 OK
63
+ Host: localhost:7002
64
+ Accept: application/json
65
+ Connection: keep-alive
66
+ <strong class='highlight1'>X-My-Custom-Header-One: my first value
67
+ X-My-Custom-Header-Two: my second value</strong>
68
+ Date: <volatile>Thu, 09 Jan 2014 02:30:31 GMT</volatile>
69
+ Transfer-Encoding: chunked
70
+
71
+ The body.
72
+ </code></pre>
73
+ </assertResponse>
74
+ </step>
75
+
76
+ <p>Now we can see that the X-My-Custom-Header-One and Two headers were returned
77
+ back to us, reflected back from the mirror imposter after being injected into
78
+ the <i>outgoing</i> request.</p>
79
+
80
+ <step type='http'>
81
+ <code class='hidden'>DELETE /imposters/7001 HTTP/1.1
82
+ Host: localhost:<%= port %>
83
+ Accept: application/json</code>
84
+ </step>
85
+
86
+ <step type='http'>
87
+ <code class='hidden'>DELETE /imposters/7002 HTTP/1.1
88
+ Host: localhost:<%= port %>
89
+ Accept: application/json</code>
90
+ </step>
91
+ </testScenario>