How to use proxyServer method in mountebank

Best JavaScript code snippet using mountebank

lib-http-proxy-passes-web-incoming-test.js

Source:lib-http-proxy-passes-web-incoming-test.js Github

copy

Full Screen

1var webPasses = require('../lib/http-proxy/passes/web-incoming'),2 httpProxy = require('../lib/http-proxy'),3 expect = require('expect.js'),4 concat = require('concat-stream'),5 async = require('async'),6 url = require('url'),7 http = require('http');8[1, 2].forEach(() =>9{10 describe('lib/http-proxy/passes/web.js', function ()11 {12 describe('#deleteLength', function ()13 {14 it('should change `content-length` for DELETE requests', function ()15 {16 var stubRequest = {17 method: 'DELETE',18 headers: {}19 };20 webPasses.deleteLength(stubRequest, {}, {});21 expect(stubRequest.headers['content-length']).to.eql('0');22 });23 it('should change `content-length` for OPTIONS requests', function ()24 {25 var stubRequest = {26 method: 'OPTIONS',27 headers: {}28 };29 webPasses.deleteLength(stubRequest, {}, {});30 expect(stubRequest.headers['content-length']).to.eql('0');31 });32 it('should remove `transfer-encoding` from empty DELETE requests', function ()33 {34 var stubRequest = {35 method: 'DELETE',36 headers: {37 'transfer-encoding': 'chunked'38 }39 };40 webPasses.deleteLength(stubRequest, {}, {});41 expect(stubRequest.headers['content-length']).to.eql('0');42 expect(stubRequest.headers).to.not.have.key('transfer-encoding');43 });44 });45 describe('#timeout', function ()46 {47 it('should set timeout on the socket', function ()48 {49 var done = false, stubRequest = {50 socket: {51 setTimeout: function (value) {done = value;}52 }53 };54 webPasses.timeout(stubRequest, {}, {timeout: 5000});55 expect(done).to.eql(5000);56 });57 });58 describe('#XHeaders', function ()59 {60 var stubRequest = {61 connection: {62 remoteAddress: '192.168.1.2',63 remotePort: '8080'64 },65 headers: {66 host: '192.168.1.2:8080'67 }68 };69 it('set the correct x-forwarded-* headers', function ()70 {71 webPasses.XHeaders(stubRequest, {}, {xfwd: true});72 expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');73 expect(stubRequest.headers['x-forwarded-port']).to.be('8080');74 expect(stubRequest.headers['x-forwarded-proto']).to.be('http');75 });76 });77 });78 describe('#createProxyServer.web() using own http server', function ()79 {80 it('should proxy the request using the web proxy handler', function (done)81 {82 var proxy = httpProxy.createProxyServer({83 target: 'http://127.0.0.1:8080'84 });85 function requestHandler(req, res)86 {87 proxy.web(req, res);88 }89 var proxyServer = http.createServer(requestHandler);90 var source = http.createServer(function (req, res)91 {92 source.close();93 proxyServer.close();94 expect(req.method).to.eql('GET');95 expect(req.headers.host.split(':')[1]).to.eql('8081');96 done();97 });98 proxyServer.listen('8081');99 source.listen('8080');100 http.request('http://127.0.0.1:8081', function () { }).end();101 });102 it('should detect a proxyReq event and modify headers', function (done)103 {104 var proxy = httpProxy.createProxyServer({105 target: 'http://127.0.0.1:8080',106 });107 proxy.on('proxyReq', function (proxyReq, req, res, options)108 {109 proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');110 });111 function requestHandler(req, res)112 {113 proxy.web(req, res);114 }115 var proxyServer = http.createServer(requestHandler);116 var source = http.createServer(function (req, res)117 {118 source.close();119 proxyServer.close();120 expect(req.headers['x-special-proxy-header']).to.eql('foobar');121 done();122 });123 proxyServer.listen('8081');124 source.listen('8080');125 http.request('http://127.0.0.1:8081', function () { }).end();126 });127 it('should skip proxyReq event when handling a request with header "expect: 100-continue" [https://www.npmjs.com/advisories/1486]', function (done)128 {129 var proxy = httpProxy.createProxyServer({130 target: 'http://127.0.0.1:8080',131 });132 proxy.on('proxyReq', function (proxyReq, req, res, options)133 {134 proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');135 });136 function requestHandler(req, res)137 {138 proxy.web(req, res);139 }140 var proxyServer = http.createServer(requestHandler);141 var source = http.createServer(function (req, res)142 {143 source.close();144 proxyServer.close();145 expect(req.headers['x-special-proxy-header']).to.not.eql('foobar');146 done();147 });148 proxyServer.listen('8081');149 source.listen('8080');150 const postData = ''.padStart(1025, 'x');151 const postOptions = {152 hostname: '127.0.0.1',153 port: 8081,154 path: '/',155 method: 'POST',156 headers: {157 'Content-Type': 'application/x-www-form-urlencoded',158 'Content-Length': Buffer.byteLength(postData),159 'expect': '100-continue'160 }161 };162 const req = http.request(postOptions, function () { });163 req.write(postData);164 req.end();165 });166 it('should proxy the request and handle error via callback', function (done)167 {168 var proxy = httpProxy.createProxyServer({169 target: 'http://127.0.0.1:8080'170 });171 var proxyServer = http.createServer(requestHandler);172 function requestHandler(req, res)173 {174 proxy.web(req, res, function (err)175 {176 proxyServer.close();177 expect(err).to.be.an(Error);178 expect(err.code).to.be('ECONNREFUSED');179 done();180 });181 }182 proxyServer.listen('8082');183 http.request({184 hostname: '127.0.0.1',185 port: '8082',186 method: 'GET',187 }, function () { }).end();188 });189 it('should proxy the request and handle error via event listener', function (done)190 {191 var proxy = httpProxy.createProxyServer({192 target: 'http://127.0.0.1:8080'193 });194 var proxyServer = http.createServer(requestHandler);195 function requestHandler(req, res)196 {197 proxy.once('error', function (err, errReq, errRes)198 {199 proxyServer.close();200 expect(err).to.be.an(Error);201 expect(errReq).to.be.equal(req);202 expect(errRes).to.be.equal(res);203 expect(err.code).to.be('ECONNREFUSED');204 done();205 });206 proxy.web(req, res);207 }208 proxyServer.listen('8083');209 http.request({210 hostname: '127.0.0.1',211 port: '8083',212 method: 'GET',213 }, function () { }).end();214 });215 it('should forward the request and handle error via event listener', function (done)216 {217 var proxy = httpProxy.createProxyServer({218 forward: 'http://127.0.0.1:8080'219 });220 var proxyServer = http.createServer(requestHandler);221 function requestHandler(req, res)222 {223 proxy.once('error', function (err, errReq, errRes)224 {225 proxyServer.close();226 expect(err).to.be.an(Error);227 expect(errReq).to.be.equal(req);228 expect(errRes).to.be.equal(res);229 expect(err.code).to.be('ECONNREFUSED');230 done();231 });232 proxy.web(req, res);233 }234 proxyServer.listen('8083');235 http.request({236 hostname: '127.0.0.1',237 port: '8083',238 method: 'GET',239 }, function () { }).end();240 });241 it('should proxy the request and handle timeout error (proxyTimeout)', function (done)242 {243 var proxy = httpProxy.createProxyServer({244 target: 'http://127.0.0.1:45000',245 proxyTimeout: 100246 });247 require('net').createServer().listen(45000);248 var proxyServer = http.createServer(requestHandler);249 var started = new Date().getTime();250 function requestHandler(req, res)251 {252 proxy.once('error', function (err, errReq, errRes)253 {254 proxyServer.close();255 expect(err).to.be.an(Error);256 expect(errReq).to.be.equal(req);257 expect(errRes).to.be.equal(res);258 expect(new Date().getTime() - started).to.be.greaterThan(99);259 expect(err.code).to.be('ECONNRESET');260 done();261 });262 proxy.web(req, res);263 }264 proxyServer.listen('8084');265 http.request({266 hostname: '127.0.0.1',267 port: '8084',268 method: 'GET',269 }, function () { }).end();270 });271 it('should proxy the request and handle timeout error', function (done)272 {273 var proxy = httpProxy.createProxyServer({274 target: 'http://127.0.0.1:45001',275 timeout: 100276 });277 require('net').createServer().listen(45001);278 var proxyServer = http.createServer(requestHandler);279 var cnt = 0;280 var doneOne = function ()281 {282 cnt += 1;283 if (cnt === 2) done();284 };285 var started = new Date().getTime();286 function requestHandler(req, res)287 {288 proxy.once('econnreset', function (err, errReq, errRes)289 {290 proxyServer.close();291 expect(err).to.be.an(Error);292 expect(errReq).to.be.equal(req);293 expect(errRes).to.be.equal(res);294 expect(err.code).to.be('ECONNRESET');295 doneOne();296 });297 proxy.web(req, res);298 }299 proxyServer.listen('8085');300 var req = http.request({301 hostname: '127.0.0.1',302 port: '8085',303 method: 'GET',304 }, function () { });305 req.on('error', function (err)306 {307 expect(err).to.be.an(Error);308 expect(err.code).to.be('ECONNRESET');309 expect(new Date().getTime() - started).to.be.greaterThan(99);310 doneOne();311 });312 req.end();313 });314 it('should proxy the request and provide a proxyRes event with the request and response parameters', function (done)315 {316 var proxy = httpProxy.createProxyServer({317 target: 'http://127.0.0.1:8080'318 });319 function requestHandler(req, res)320 {321 proxy.once('proxyRes', function (proxyRes, pReq, pRes)322 {323 source.close();324 proxyServer.close();325 expect(pReq).to.be.equal(req);326 expect(pRes).to.be.equal(res);327 done();328 });329 proxy.web(req, res);330 }331 var proxyServer = http.createServer(requestHandler);332 var source = http.createServer(function (req, res)333 {334 res.end('Response');335 });336 proxyServer.listen('8086');337 source.listen('8080');338 http.request('http://127.0.0.1:8086', function () { }).end();339 });340 it('should proxy the request and provide and respond to manual user response when using modifyResponse', function (done)341 {342 var proxy = httpProxy.createProxyServer({343 target: 'http://127.0.0.1:8080',344 selfHandleResponse: true345 });346 function requestHandler(req, res)347 {348 proxy.once('proxyRes', function (proxyRes, pReq, pRes)349 {350 proxyRes.pipe(concat(function (body)351 {352 expect(body.toString('utf8')).eql('Response');353 pRes.end(Buffer.from('my-custom-response'));354 }));355 });356 proxy.web(req, res);357 }358 var proxyServer = http.createServer(requestHandler);359 var source = http.createServer(function (req, res)360 {361 res.end('Response');362 });363 async.parallel([364 next => proxyServer.listen(8086, next),365 next => source.listen(8080, next)366 ], function (err)367 {368 http.get('http://127.0.0.1:8086', function (res)369 {370 res.pipe(concat(function (body)371 {372 expect(body.toString('utf8')).eql('my-custom-response');373 source.close();374 proxyServer.close();375 done();376 }));377 }).once('error', done);378 });379 });380 it('should proxy the request and handle changeOrigin option', function (done)381 {382 var proxy = httpProxy.createProxyServer({383 target: 'http://127.0.0.1:8080',384 changeOrigin: true385 });386 function requestHandler(req, res)387 {388 proxy.web(req, res);389 }390 var proxyServer = http.createServer(requestHandler);391 var source = http.createServer(function (req, res)392 {393 source.close();394 proxyServer.close();395 expect(req.method).to.eql('GET');396 expect(req.headers.host.split(':')[1]).to.eql('8080');397 done();398 });399 proxyServer.listen('8081');400 source.listen('8080');401 http.request('http://127.0.0.1:8081', function () { }).end();402 });403 it('should proxy the request with the Authorization header set', function (done)404 {405 var proxy = httpProxy.createProxyServer({406 target: 'http://127.0.0.1:8080',407 auth: 'user:pass'408 });409 function requestHandler(req, res)410 {411 proxy.web(req, res);412 }413 var proxyServer = http.createServer(requestHandler);414 var source = http.createServer(function (req, res)415 {416 source.close();417 proxyServer.close();418 var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64');419 expect(req.method).to.eql('GET');420 expect(auth.toString()).to.eql('user:pass');421 done();422 });423 proxyServer.listen('8081');424 source.listen('8080');425 http.request('http://127.0.0.1:8081', function () { }).end();426 });427 it('should proxy requests to multiple servers with different options', function (done)428 {429 var proxy = httpProxy.createProxyServer();430 // proxies to two servers depending on url, rewriting the url as well431 // http://127.0.0.1:8080/s1/ -> http://127.0.0.1:8081/432 // http://127.0.0.1:8080/ -> http://127.0.0.1:8082/433 function requestHandler(req, res)434 {435 if (req.url.indexOf('/s1/') === 0)436 {437 proxy.web(req, res, {438 ignorePath: true,439 target: 'http://127.0.0.1:8081' + req.url.substring(3)440 });441 } else442 {443 proxy.web(req, res, {444 target: 'http://127.0.0.1:8082'445 });446 }447 }448 var proxyServer = http.createServer(requestHandler);449 var source1 = http.createServer(function (req, res)450 {451 expect(req.method).to.eql('GET');452 expect(req.headers.host.split(':')[1]).to.eql('8080');453 expect(req.url).to.eql('/test1');454 });455 var source2 = http.createServer(function (req, res)456 {457 source1.close();458 source2.close();459 proxyServer.close();460 expect(req.method).to.eql('GET');461 expect(req.headers.host.split(':')[1]).to.eql('8080');462 expect(req.url).to.eql('/test2');463 done();464 });465 proxyServer.listen('8080');466 source1.listen('8081');467 source2.listen('8082');468 http.request('http://127.0.0.1:8080/s1/test1', function () { }).end();469 http.request('http://127.0.0.1:8080/test2', function () { }).end();470 });471 });472 describe('#followRedirects', function ()473 {474 it('should proxy the request follow redirects', function (done)475 {476 var proxy = httpProxy.createProxyServer({477 target: 'http://127.0.0.1:8080',478 followRedirects: true479 });480 function requestHandler(req, res)481 {482 proxy.web(req, res);483 }484 var proxyServer = http.createServer(requestHandler);485 var source = http.createServer(function (req, res)486 {487 if (url.parse(req.url).pathname === '/redirect')488 {489 res.writeHead(200, {'Content-Type': 'text/plain'});490 res.end('ok');491 }492 res.writeHead(301, {'Location': '/redirect'});493 res.end();494 });495 proxyServer.listen('8081');496 source.listen('8080');497 http.request('http://127.0.0.1:8081', function (res)498 {499 source.close();500 proxyServer.close();501 expect(res.statusCode).to.eql(200);502 done();503 }).end();504 });505 });...

Full Screen

Full Screen

browsercontext-proxy.spec.ts

Source:browsercontext-proxy.spec.ts Github

copy

Full Screen

1/**2 * Copyright (c) Microsoft Corporation.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import { browserTest as it, expect } from './config/browserTest';17it.use({18 launchOptions: async ({ launchOptions }, use) => {19 await use({20 ...launchOptions,21 proxy: { server: 'per-context' }22 });23 }24});25it.beforeEach(({ server }) => {26 server.setRoute('/target.html', async (req, res) => {27 res.end('<html><title>Served by the proxy</title></html>');28 });29});30it('should throw for missing global proxy on Chromium Windows', async ({ browserName, platform, browserType, server }) => {31 it.skip(browserName !== 'chromium' || platform !== 'win32');32 let browser;33 try {34 browser = await browserType.launch({35 proxy: undefined,36 });37 const error = await browser.newContext({ proxy: { server: `localhost:${server.PORT}` } }).catch(e => e);38 expect(error.toString()).toContain('Browser needs to be launched with the global proxy');39 } finally {40 await browser.close();41 }42});43it('should work when passing the proxy only on the context level', async ({ browserName, platform, browserType, server, proxyServer }) => {44 // Currently an upstream bug in the network stack of Chromium which leads that45 // the wrong proxy gets used in the BrowserContext.46 it.fixme(browserName === 'chromium' && platform === 'win32');47 proxyServer.forwardTo(server.PORT);48 let browser;49 try {50 browser = await browserType.launch({51 proxy: undefined,52 });53 const context = await browser.newContext({54 proxy: { server: `localhost:${proxyServer.PORT}` }55 });56 const page = await context.newPage();57 await page.goto('http://non-existent.com/target.html');58 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');59 expect(await page.title()).toBe('Served by the proxy');60 } finally {61 await browser.close();62 }63});64it('should throw for bad server value', async ({ contextFactory }) => {65 const error = await contextFactory({66 // @ts-expect-error server must be a string67 proxy: { server: 123 }68 }).catch(e => e);69 expect(error.message).toContain('proxy.server: expected string, got number');70});71it('should use proxy', async ({ contextFactory, server, proxyServer }) => {72 proxyServer.forwardTo(server.PORT);73 const context = await contextFactory({74 proxy: { server: `localhost:${proxyServer.PORT}` }75 });76 const page = await context.newPage();77 await page.goto('http://non-existent.com/target.html');78 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');79 expect(await page.title()).toBe('Served by the proxy');80 await context.close();81});82it.describe('should proxy local network requests', () => {83 for (const additionalBypass of [false, true]) {84 it.describe(additionalBypass ? 'with other bypasses' : 'by default', () => {85 for (const params of [86 {87 target: 'localhost',88 description: 'localhost',89 },90 {91 target: '127.0.0.1',92 description: 'loopback address',93 },94 {95 target: '169.254.3.4',96 description: 'link-local'97 }98 ]) {99 it(`${params.description}`, async ({ platform, browserName, contextFactory, server, proxyServer }) => {100 it.fail(browserName === 'webkit' && platform === 'darwin' && additionalBypass && ['localhost', '127.0.0.1'].includes(params.target), 'WK fails to proxy 127.0.0.1 and localhost if additional bypasses are present');101 const path = `/target-${additionalBypass}-${params.target}.html`;102 server.setRoute(path, async (req, res) => {103 res.end('<html><title>Served by the proxy</title></html>');104 });105 const url = `http://${params.target}:${server.PORT}${path}`;106 proxyServer.forwardTo(server.PORT);107 const context = await contextFactory({108 proxy: { server: `localhost:${proxyServer.PORT}`, bypass: additionalBypass ? '1.non.existent.domain.for.the.test' : undefined }109 });110 const page = await context.newPage();111 await page.goto(url);112 expect(proxyServer.requestUrls).toContain(url);113 expect(await page.title()).toBe('Served by the proxy');114 await page.goto('http://1.non.existent.domain.for.the.test/foo.html').catch(() => {});115 if (additionalBypass)116 expect(proxyServer.requestUrls).not.toContain('http://1.non.existent.domain.for.the.test/foo.html');117 else118 expect(proxyServer.requestUrls).toContain('http://1.non.existent.domain.for.the.test/foo.html');119 await context.close();120 });121 }122 });123 }124});125it('should use ipv6 proxy', async ({ contextFactory, server, proxyServer, browserName }) => {126 it.fail(browserName === 'firefox', 'page.goto: NS_ERROR_UNKNOWN_HOST');127 it.fail(!!process.env.INSIDE_DOCKER, 'docker does not support IPv6 by default');128 proxyServer.forwardTo(server.PORT);129 const context = await contextFactory({130 proxy: { server: `[0:0:0:0:0:0:0:1]:${proxyServer.PORT}` }131 });132 const page = await context.newPage();133 await page.goto('http://non-existent.com/target.html');134 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');135 expect(await page.title()).toBe('Served by the proxy');136 await context.close();137});138it('should use proxy twice', async ({ contextFactory, server, proxyServer }) => {139 proxyServer.forwardTo(server.PORT);140 const context = await contextFactory({141 proxy: { server: `localhost:${proxyServer.PORT}` }142 });143 const page = await context.newPage();144 await page.goto('http://non-existent.com/target.html');145 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');146 await page.goto('http://non-existent-2.com/target.html');147 expect(proxyServer.requestUrls).toContain('http://non-existent-2.com/target.html');148 expect(await page.title()).toBe('Served by the proxy');149 await context.close();150});151it('should use proxy for second page', async ({ contextFactory, server, proxyServer }) => {152 proxyServer.forwardTo(server.PORT);153 const context = await contextFactory({154 proxy: { server: `localhost:${proxyServer.PORT}` }155 });156 const page = await context.newPage();157 await page.goto('http://non-existent.com/target.html');158 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');159 expect(await page.title()).toBe('Served by the proxy');160 const page2 = await context.newPage();161 proxyServer.requestUrls = [];162 await page2.goto('http://non-existent.com/target.html');163 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');164 expect(await page2.title()).toBe('Served by the proxy');165 await context.close();166});167it('should use proxy for https urls', async ({ contextFactory, server, httpsServer, proxyServer }) => {168 httpsServer.setRoute('/target.html', async (req, res) => {169 res.end('<html><title>Served by https server via proxy</title></html>');170 });171 proxyServer.forwardTo(httpsServer.PORT);172 const context = await contextFactory({173 ignoreHTTPSErrors: true,174 proxy: { server: `localhost:${proxyServer.PORT}` }175 });176 const page = await context.newPage();177 await page.goto('https://non-existent.com/target.html');178 expect(proxyServer.connectHosts).toContain('non-existent.com:443');179 expect(await page.title()).toBe('Served by https server via proxy');180 await context.close();181});182it('should work with IP:PORT notion', async ({ contextFactory, server, proxyServer }) => {183 proxyServer.forwardTo(server.PORT);184 const context = await contextFactory({185 proxy: { server: `127.0.0.1:${proxyServer.PORT}` }186 });187 const page = await context.newPage();188 await page.goto('http://non-existent.com/target.html');189 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');190 expect(await page.title()).toBe('Served by the proxy');191 await context.close();192});193it('should throw for socks5 authentication', async ({ contextFactory }) => {194 const error = await contextFactory({195 proxy: { server: `socks5://localhost:1234`, username: 'user', password: 'secret' }196 }).catch(e => e);197 expect(error.message).toContain('Browser does not support socks5 proxy authentication');198});199it('should throw for socks4 authentication', async ({ contextFactory }) => {200 const error = await contextFactory({201 proxy: { server: `socks4://localhost:1234`, username: 'user', password: 'secret' }202 }).catch(e => e);203 expect(error.message).toContain('Socks4 proxy protocol does not support authentication');204});205it('should authenticate', async ({ contextFactory, server, proxyServer }) => {206 proxyServer.forwardTo(server.PORT);207 let auth;208 proxyServer.setAuthHandler(req => {209 auth = req.headers['proxy-authorization'];210 return !!auth;211 });212 const context = await contextFactory({213 proxy: { server: `localhost:${proxyServer.PORT}`, username: 'user', password: 'secret' }214 });215 const page = await context.newPage();216 await page.goto('http://non-existent.com/target.html');217 expect(proxyServer.requestUrls).toContain('http://non-existent.com/target.html');218 expect(auth).toBe('Basic ' + Buffer.from('user:secret').toString('base64'));219 expect(await page.title()).toBe('Served by the proxy');220 await context.close();221});222it('should authenticate with empty password', async ({ contextFactory, server, proxyServer }) => {223 proxyServer.forwardTo(server.PORT);224 let auth;225 proxyServer.setAuthHandler(req => {226 auth = req.headers['proxy-authorization'];227 return !!auth;228 });229 const context = await contextFactory({230 proxy: { server: `localhost:${proxyServer.PORT}`, username: 'user', password: '' }231 });232 const page = await context.newPage();233 await page.goto('http://non-existent.com/target.html');234 expect(auth).toBe('Basic ' + Buffer.from('user:').toString('base64'));235 expect(await page.title()).toBe('Served by the proxy');236 await context.close();237});238it('should isolate proxy credentials between contexts', async ({ contextFactory, server, browserName, proxyServer }) => {239 it.fixme(browserName === 'firefox', 'Credentials from the first context stick around');240 proxyServer.forwardTo(server.PORT);241 let auth;242 proxyServer.setAuthHandler(req => {243 auth = req.headers['proxy-authorization'];244 return !!auth;245 });246 {247 const context = await contextFactory({248 proxy: { server: `localhost:${proxyServer.PORT}`, username: 'user1', password: 'secret1' }249 });250 const page = await context.newPage();251 await page.goto('http://non-existent.com/target.html');252 expect(auth).toBe('Basic ' + Buffer.from('user1:secret1').toString('base64'));253 expect(await page.title()).toBe('Served by the proxy');254 await context.close();255 }256 auth = undefined;257 {258 const context = await contextFactory({259 proxy: { server: `localhost:${proxyServer.PORT}`, username: 'user2', password: 'secret2' }260 });261 const page = await context.newPage();262 await page.goto('http://non-existent.com/target.html');263 expect(await page.title()).toBe('Served by the proxy');264 expect(auth).toBe('Basic ' + Buffer.from('user2:secret2').toString('base64'));265 await context.close();266 }267});268it('should exclude patterns', async ({ contextFactory, server, browserName, headless, proxyServer }) => {269 it.fixme(browserName === 'chromium' && !headless, 'Chromium headed crashes with CHECK(!in_frame_tree_) in RenderFrameImpl::OnDeleteFrame.');270 proxyServer.forwardTo(server.PORT);271 // FYI: using long and weird domain names to avoid ATT DNS hijacking272 // that resolves everything to some weird search results page.273 //274 // @see https://gist.github.com/CollinChaffin/24f6c9652efb3d6d5ef2f5502720ef00275 const context = await contextFactory({276 proxy: { server: `localhost:${proxyServer.PORT}`, bypass: '1.non.existent.domain.for.the.test, 2.non.existent.domain.for.the.test, .another.test' }277 });278 const page = await context.newPage();279 await page.goto('http://0.non.existent.domain.for.the.test/target.html');280 expect(proxyServer.requestUrls).toContain('http://0.non.existent.domain.for.the.test/target.html');281 expect(await page.title()).toBe('Served by the proxy');282 proxyServer.requestUrls = [];283 {284 const error = await page.goto('http://1.non.existent.domain.for.the.test/target.html').catch(e => e);285 expect(proxyServer.requestUrls).toEqual([]);286 expect(error.message).toBeTruthy();287 }288 {289 const error = await page.goto('http://2.non.existent.domain.for.the.test/target.html').catch(e => e);290 expect(proxyServer.requestUrls).toEqual([]);291 expect(error.message).toBeTruthy();292 }293 {294 const error = await page.goto('http://foo.is.the.another.test/target.html').catch(e => e);295 expect(proxyServer.requestUrls).toEqual([]);296 expect(error.message).toBeTruthy();297 }298 {299 await page.goto('http://3.non.existent.domain.for.the.test/target.html');300 expect(proxyServer.requestUrls).toContain('http://3.non.existent.domain.for.the.test/target.html');301 expect(await page.title()).toBe('Served by the proxy');302 }303 await context.close();304});305it('should use socks proxy', async ({ contextFactory, socksPort }) => {306 const context = await contextFactory({307 proxy: { server: `socks5://localhost:${socksPort}` }308 });309 const page = await context.newPage();310 await page.goto('http://non-existent.com');311 expect(await page.title()).toBe('Served by the SOCKS proxy');312 await context.close();313});314it('should use socks proxy in second page', async ({ contextFactory, socksPort }) => {315 const context = await contextFactory({316 proxy: { server: `socks5://localhost:${socksPort}` }317 });318 const page = await context.newPage();319 await page.goto('http://non-existent.com');320 expect(await page.title()).toBe('Served by the SOCKS proxy');321 const page2 = await context.newPage();322 await page2.goto('http://non-existent.com');323 expect(await page2.title()).toBe('Served by the SOCKS proxy');324 await context.close();325});326it('does launch without a port', async ({ contextFactory }) => {327 const context = await contextFactory({328 proxy: { server: 'http://localhost' }329 });330 await context.close();...

Full Screen

Full Screen

test.proxy-websocket.js

Source:test.proxy-websocket.js Github

copy

Full Screen

1const httpProxy = require('../lib/proxy');2const helper = require('../lib/helper.js');3const http = require('http');4const ws = require('ws');5const ioServer = require('socket.io').Server;6const ioClient = require('socket.io-client');7describe('proxy with websocket', function () {8 it('should proxy the websockets stream', function (done) {9 var proxyServer = http.createServer();10 proxyServer.listen(3000);11 proxyServer.on('upgrade', (req, socket, head) => {12 httpProxy.ws(req, socket, head, {13 protocol : 'ws',14 hostname : '127.0.0.1',15 port : 102416 });17 });18 var destiny = new ws.Server({ port : 1024 }, function () {19 var client = new ws('ws://127.0.0.1:' + 3000);20 client.on('open', function () {21 client.send('hello there');22 });23 client.on('message', function (msg) {24 helper.eq(msg, 'Hello over websockets');25 client.close();26 proxyServer.close();27 destiny.close();28 done();29 });30 });31 destiny.on('connection', function (socket) {32 socket.on('message', function (msg) {33 helper.eq(msg, 'hello there');34 socket.send('Hello over websockets');35 });36 });37 });38 it('should return error on proxy error and end client connection', function (done) {39 const proxyServer = http.createServer();40 proxyServer.listen(3000);41 proxyServer.on('upgrade', (req, socket, head) => {42 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 }, onProxyEndCallback);43 });44 function onProxyEndCallback (err, req, res) {45 helper.eq(err instanceof Error, true);46 helper.eq(err.code, 'ECONNREFUSED');47 res.end();48 proxyServer.close();49 maybeDone();50 }51 var client = new ws('ws://127.0.0.1:' + 3000);52 client.on('open', function () {53 client.send('hello there');54 });55 var count = 0;56 function maybeDone () {57 count += 1;58 if (count === 2) {59 done();60 }61 }62 client.on('error', function (err) {63 helper.eq(err instanceof Error, true);64 helper.eq(err.code, 'ECONNRESET');65 maybeDone();66 });67 });68 it('should close client socket if upstream is closed before upgrade', function (done) {69 const proxyServer = http.createServer();70 proxyServer.listen(3000);71 proxyServer.on('upgrade', (req, socket, head) => {72 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });73 });74 var server = http.createServer();75 server.on('upgrade', function (req, socket) {76 var response = [77 'HTTP/1.1 404 Not Found',78 'Content-type: text/html',79 '',80 ''81 ];82 socket.write(response.join('\r\n'));83 socket.end();84 });85 server.listen(1024);86 var client = new ws('ws://127.0.0.1:' + 3000);87 client.on('open', function () {88 client.send('hello there');89 });90 client.on('error', function (err) {91 helper.eq(err instanceof Error, true);92 proxyServer.close();93 server.close();94 done();95 });96 });97 it('should proxy a socket.io stream', function (done) {98 var nbHttpRequest = 0;99 const proxyServer = http.createServer((req, res) => {100 nbHttpRequest++; // we should receive no requests101 httpProxy.web(req, res, { protocol : 'http', hostname : '127.0.0.1', port : 1024 });102 });103 proxyServer.listen(3000);104 // accept websocket proxy105 proxyServer.on('upgrade', (req, socket, head) => {106 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });107 });108 var server = http.createServer();109 var destiny = new ioServer(server);110 function startSocketIo () {111 const client = ioClient('ws://127.0.0.1:' + 3000, { transports : ['websocket'] });112 client.on('connect', function () {113 client.emit('incoming', 'hello there');114 });115 client.on('outgoing', function (data) {116 helper.eq(data, 'Hello over websockets');117 helper.eq(nbHttpRequest, 0);118 proxyServer.close();119 server.close();120 done();121 });122 }123 server.listen(1024);124 server.on('listening', startSocketIo);125 destiny.on('connection', function (socket) {126 socket.on('incoming', function (msg) {127 helper.eq(msg, 'hello there');128 socket.emit('outgoing', 'Hello over websockets');129 });130 });131 });132 it.skip('should emit open and close events when socket.io client connects and disconnects', function (done) {133 const proxyServer = http.createServer((req, res) => {134 httpProxy.web(req, res, { protocol : 'http', hostname : '127.0.0.1', port : 1024 });135 });136 proxyServer.listen(3000);137 // accept websocket proxy138 proxyServer.on('upgrade', (req, socket, head) => {139 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });140 });141 var server = http.createServer();142 var destiny = new ioServer(server);143 function startSocketIo () {144 const client = ioClient.connect('ws://127.0.0.1:' + 3000, { transports : ['websocket'] , rejectUnauthorized : null });145 // var client = ioClient.connect('ws://127.0.0.1:' + 3000, {rejectUnauthorized : null});146 client.on('connect', function () {147 client.disconnect();148 });149 }150 var count = 0;151 proxyServer.on('open', function () {152 count += 1;153 });154 proxyServer.on('close', function () {155 proxyServer.close();156 server.close();157 destiny.close();158 if (count == 1) {159 done();160 }161 });162 server.listen(1024);163 server.on('listening', startSocketIo);164 });165 it('should pass all set-cookie headers to client', function (done) {166 const proxyServer = http.createServer();167 proxyServer.listen(3000);168 // accept websocket proxy169 proxyServer.on('upgrade', (req, socket, head) => {170 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });171 });172 var destiny = new ws.Server({ port : 1024 }, function () {173 var key = Buffer.from(Math.random().toString()).toString('base64');174 var requestOptions = {175 port : 3000,176 host : '127.0.0.1',177 headers : {178 Connection : 'Upgrade',179 Upgrade : 'websocket',180 Host : 'ws://127.0.0.1',181 'Sec-WebSocket-Version' : 13,182 'Sec-WebSocket-Key' : key183 }184 };185 var req = http.request(requestOptions);186 req.on('upgrade', function (res) {187 helper.eq(res.headers['set-cookie'].length, 2);188 proxyServer.close();189 destiny.close();190 done();191 });192 req.end();193 });194 destiny.on('headers', function (headers) {195 headers.push('Set-Cookie: test1=test1');196 headers.push('Set-Cookie: test2=test2');197 });198 });199 it('should modify headers', function (done) {200 var destiny;201 const proxyServer = http.createServer();202 proxyServer.listen(3000);203 // accept websocket proxy204 proxyServer.on('upgrade', (req, socket, head) => {205 httpProxy.ws(req, socket, head, {206 protocol : 'ws',207 hostname : '127.0.0.1',208 port : 1024,209 headers : {210 'X-Special-Proxy-Header' : 'foobar'211 }212 });213 });214 destiny = new ws.Server({ port : 1024 }, function () {215 var client = new ws('ws://127.0.0.1:' + 3000);216 client.on('open', function () {217 client.send('hello there');218 });219 client.on('message', function (msg) {220 helper.eq(msg, 'Hello over websockets');221 client.close();222 proxyServer.close();223 destiny.close();224 done();225 });226 });227 destiny.on('connection', function (socket, upgradeReq) {228 helper.eq(upgradeReq.headers['x-special-proxy-header'], 'foobar');229 socket.on('message', function (msg) {230 helper.eq(msg, 'hello there');231 socket.send('Hello over websockets');232 });233 });234 });235 it('should forward frames with single frame payload', function (done) {236 var payload = Array(65529).join('0');237 const proxyServer = http.createServer();238 proxyServer.listen(3000);239 // accept websocket proxy240 proxyServer.on('upgrade', (req, socket, head) => {241 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });242 });243 var destiny = new ws.Server({ port : 1024 }, function () {244 var client = new ws('ws://127.0.0.1:' + 3000);245 client.on('open', function () {246 client.send(payload);247 });248 client.on('message', function (msg) {249 helper.eq(msg, 'Hello over websockets');250 client.close();251 proxyServer.close();252 destiny.close();253 done();254 });255 });256 destiny.on('connection', function (socket) {257 socket.on('message', function (msg) {258 helper.eq(msg, payload);259 socket.send('Hello over websockets');260 });261 });262 });263 it('should forward continuation frames with big payload', function (done) {264 var payload = Array(65530).join('0');265 const proxyServer = http.createServer();266 proxyServer.listen(3000);267 // accept websocket proxy268 proxyServer.on('upgrade', (req, socket, head) => {269 httpProxy.ws(req, socket, head, { protocol : 'ws', hostname : '127.0.0.1', port : 1024 });270 });271 var destiny = new ws.Server({ port : 1024 }, function () {272 var client = new ws('ws://127.0.0.1:' + 3000);273 client.on('open', function () {274 client.send(payload);275 });276 client.on('message', function (msg) {277 helper.eq(msg, 'Hello over websockets');278 client.close();279 proxyServer.close();280 destiny.close();281 done();282 });283 });284 destiny.on('connection', function (socket) {285 socket.on('message', function (msg) {286 helper.eq(msg, payload);287 socket.send('Hello over websockets');288 });289 });290 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3mb.create({4}, function (error) {5 if (error) {6 console.error('Could not start server', error);7 } else {8 console.log('Server started on port', port);9 }10});11mb.start({12}, function (error) {13 if (error) {14 console.error('Could not start server', error);15 } else {16 console.log('Server started on port', port);17 }18});19var proxy = mb.create({20}, function (error) {21 if (error) {22 console.error('Could not start server', error);23 } else {24 console.log('Server started on port', port);25 }26});27var proxy = mb.start({28}, function (error) {29 if (error) {30 console.error('Could not start server', error);31 } else {32 console.log('Server started on port', port);33 }34});35mb.start({36}, function (error) {37 if (error) {38 console.error('Could not start server', error);39 } else {40 console.log('Server started on port', port);41 }42});43mb.create({44}, function (error) {45 if (error) {46 console.error('Could not start server', error);47 } else {48 console.log('Server started on port', port);49 }50});51mb.start({

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function (error, server) {3 if (error) {4 console.error(error);5 }6 else {7 console.log('mb server started');8 server.get('/imposters', function (request, response) {9 response.send({hello: 'world'});10 });11 }12});13var mb = require('mountebank');14mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function (error, server) {15 if (error) {16 console.error(error);17 }18 else {19 console.log('mb server started');20 server.get('/imposters', function (request, response) {21 response.send({hello: 'world'});22 });23 }24});25var mb = require('mountebank');26mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function (error, server) {27 if (error) {28 console.error(error);29 }30 else {31 console.log('mb server started');32 server.get('/imposters', function (request, response) {33 response.send({hello: 'world'});34 });35 }36});37var mb = require('mountebank');38mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function (error, server) {39 if (error) {40 console.error(error);41 }42 else {43 console.log('mb server started');44 server.get('/imposters', function (request, response) {45 response.send({hello: 'world'});46 });47 }48});49var mb = require('mountebank');50mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function (error, server) {51 if (error) {52 console.error(error);53 }54 else {55 console.log('mb server started');

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var proxy = require('http-proxy');3var server = http.createServer(function(req, res) {4 proxyServer.web(req, res);5});6server.listen(3000);7{"imposters":[{"port":2525,"protocol":"http","numberOfRequests":0}]}

Full Screen

Using AI Code Generation

copy

Full Screen

1var proxy = require('mountebank-proxy');2var mb = proxy.create({ port: 2525, host: 'localhost' });3mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {4 if (err) {5 console.log(err);6 }7 console.log(res.statusCode);8});9var proxy = require('mountebank-proxy');10var mb = proxy.create({ port: 2525, host: 'localhost' });11mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {12 if (err) {13 console.log(err);14 }15 console.log(res.statusCode);16});17var proxy = require('mountebank-proxy');18var mb = proxy.create({ port: 2525, host: 'localhost' });19mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {20 if (err) {21 console.log(err);22 }23 console.log(res.statusCode);24});25var proxy = require('mountebank-proxy');26var mb = proxy.create({ port: 2525, host: 'localhost' });27mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {28 if (err) {29 console.log(err);30 }31 console.log(res.statusCode);32});33var proxy = require('mountebank-proxy');34var mb = proxy.create({ port: 2525, host: 'localhost' });35mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {36 if (err) {37 console.log(err);38 }39 console.log(res.statusCode);40});41var proxy = require('mountebank-proxy');42var mb = proxy.create({ port: 2525, host: 'localhost' });43mb.post('/imposters', { port: 3000, protocol: 'http' }, function (err, res) {44 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const proxyServer = require('mountebank').proxyServer;2const port = 2525;3proxyServer({4}).then(() => {5 console.log(`Proxy running on port ${port}`);6}).catch(error => {7 console.error(`Failed to start proxy: ${error.message}`);8});9const imposterServer = require('mountebank').imposterServer;10const port = 2525;11imposterServer({12}).then(() => {13 console.log(`Imposter running on port ${port}`);14}).catch(error => {15 console.error(`Failed to start imposter: ${error.message}`);16});17const mountebankServer = require('mountebank').mountebankServer;18const port = 2525;19mountebankServer({20}).then(() => {21 console.log(`Mountebank running on port ${port}`);22}).catch(error => {23 console.error(`Failed to start mountebank: ${error.message}`);24});25const mountebankServer = require('mountebank').mountebankServer;26const port = 2525;27mountebankServer({28}).then(() => {29 console.log(`Mountebank running on port ${port}`);30}).catch(error => {31 console.error(`Failed to start mountebank: ${error.message}`);32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var proxy = mb.create({ port: 2525, allowInjection: true });3proxy.then(function (proxyServer) {4 proxyServer.create({ port: 2526, stubs: [{ responses: [{ is: { body: 'Hello World' } }] }] });5 proxyServer.create({ port: 2527, stubs: [{ responses: [{ is: { body: 'Hi World' } }] }] });6 proxyServer.create({ port: 2528, stubs: [{ responses: [{ is: { body: 'Hola World' } }] }] });7 proxyServer.create({ port: 2529, stubs: [{ responses: [{ is: { body: 'Bonjour World' } }] }] });8 proxyServer.create({ port: 2530, stubs: [{ responses: [{ is: { body: 'Ciao World' } }] }] });9 proxyServer.create({ port: 2531, stubs: [{ responses: [{ is: { body: 'Hallo World' } }] }] });10 proxyServer.create({ port: 2532, stubs: [{ responses: [{ is: { body: 'Namaste World' } }] }] });11 proxyServer.create({ port: 2533, stubs: [{ responses: [{ is: { body: 'Aloha World' } }] }] });12 proxyServer.create({ port: 2534, stubs: [{ responses: [{ is: { body: 'Konnichiwa World' } }] }] });13 proxyServer.create({ port: 2535, stubs: [{ responses: [{ is: { body: 'Hej World' } }] }] });14 proxyServer.create({ port: 2536, stubs: [{ responses: [{ is: { body: 'Guten Tag World' } }] }] });15 proxyServer.create({ port: 2537, stubs: [{ responses: [{ is: { body: 'Salaam World' } }] }] });16 proxyServer.create({ port: 2538, stubs: [{ responses: [{ is: { body: 'Shalom World' } }] }] });17 proxyServer.create({ port: 2539, stubs: [{ responses: [{ is: { body: 'Nǐ hǎo World' } }] }] });18 proxyServer.create({ port

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var mbHelper = require('mountebank-helper');3var mbProxy = mbHelper.mbProxy;4var port = 2525;5var proxyPort = 2526;6var proxyHost = 'localhost';7var proxyProtocol = 'http';8var proxyStub = {9 {10 equals: {11 }12 }13 {14 is: {15 headers: {16 },17 body: JSON.stringify({message: 'hello world'})18 }19 }20};21mb.create(port, function (error) {22 if (error) {23 console.log(error);24 }25 else {26 mbProxy.create(proxyPort, proxyHost, proxyProtocol, function (error) {27 if (error) {28 console.log(error);29 }30 else {31 mbProxy.addStub(proxyStub, function (error) {32 if (error) {33 console.log(error);34 }35 else {36 console.log('Proxy stub added successfully');37 }38 });39 }40 });41 }42});43var mb = require('mountebank');44var mbHelper = require('mountebank-helper');45var mbProxy = mbHelper.mbProxy;46var port = 2525;47var proxyPort = 2526;48var proxyHost = 'localhost';49var proxyProtocol = 'http';50var proxyStub = {51 {52 equals: {53 }54 }55 {56 is: {57 headers: {58 },59 body: JSON.stringify({message: 'hello world'})60 }61 }62};63mb.create(port, function (error) {64 if (error) {65 console.log(error);66 }67 else {68 mbProxy.create(proxyPort, proxyHost, proxyProtocol, function (error) {69 if (error) {70 console.log(error);71 }72 else {73 mbProxy.addStub(proxyStub, function (error) {74 if (error) {75 console.log(error);76 }77 else {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank'),2http = require('http'),3fs = require('fs'),4path = require('path');5var proxy = mb.create({6});7proxy.start();8var jsonFile = {9 "predicates": [{10 "equals": {11 }12 }],13 "responses": [{14 "proxy": {15 }16 }]17};18fs.writeFile('proxy.json', JSON.stringify(jsonFile), function(err) {19 if (err) {20 console.log(err);21 } else {22 console.log("JSON saved to proxy.json");23 }24});25var options = {26 headers: {27 }28};29var req = http.request(options, function(res) {30 res.setEncoding('utf8');31 res.on('data', function(chunk) {32 console.log("body: " + chunk);33 });34});35fs.readFile('proxy.json', function(err, data) {36 if (err) {37 console.log(err);38 } else {39 req.write(data);40 req.end();41 }42});43var options = {44};45var req = http.request(options, function(res) {46 res.setEncoding('utf8');47 res.on('data', function(chunk) {48 console.log("body: " + chunk);49 });50});51req.end();52var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var proxyServer = require('mountebank').proxyServer;2var proxy = proxyServer.create({3});4proxy.start();5proxy.stop();6var proxyServer = require('mountebank').proxyServer;7var proxy = proxyServer.create({8});9proxy.start();10proxy.createImposter({11 stubs: [{12 predicates: [{13 equals: {14 }15 }],16 responses: [{17 is: {18 }19 }]20 }]21});22proxy.stop();23var proxyServer = require('mountebank').proxyServer;24var proxy = proxyServer.create({25});26proxy.start();27proxy.createImposter({28 stubs: [{29 predicates: [{30 equals: {31 }32 }],33 responses: [{34 is: {35 }36 }]37 }]38});39proxy.deleteImposter(3001);40proxy.stop();41var proxyServer = require('mountebank').proxyServer;42var proxy = proxyServer.create({

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var options = {3 headers: {4 }5};6var req = http.request(options, function (res) {7 res.setEncoding('utf8');8 res.on('data', function (chunk) {9 console.log("body: " + chunk);10 });11});12req.on('error', function (e) {13 console.log('problem with request: ' + e.message);14});15req.write(JSON.stringify({16 stubs: [{17 responses: [{18 is: {19 }20 }]21 }],22 _links: {23 self: {24 }25 }26}));27req.end();28var http = require('http');29var options = {30 headers: {31 }32};33var req = http.request(options, function (res) {34 res.setEncoding('utf8');35 res.on('data', function (chunk) {36 console.log("body: " + chunk);37 });38});39req.on('error', function (e) {40 console.log('problem with request: ' + e.message);41});42req.write(JSON.stringify({43 stubs: [{44 responses: [{45 is: {46 }47 }]48 }],49 _links: {50 self: {51 }52 }53}));54req.end();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful