How to use largeRequest method in mountebank

Best JavaScript code snippet using mountebank

tcpInjectionTest.js

Source:tcpInjectionTest.js Github

copy

Full Screen

1'use strict';2var assert = require('assert'),3 api = require('../api').create(),4 tcp = require('./tcpClient'),5 promiseIt = require('../../testHelpers').promiseIt,6 port = api.port + 1,7 timeout = parseInt(process.env.MB_SLOW_TEST_TIMEOUT || 4000);8describe('tcp imposter', function () {9 this.timeout(timeout);10 describe('POST /imposters with injections', function () {11 promiseIt('should allow javascript predicate for matching', function () {12 var fn = function (request) { return request.data.toString() === 'test'; },13 stub = {14 predicates: [{ inject: fn.toString() }],15 responses: [{ is: { data: 'MATCHED' } }]16 };17 return api.post('/imposters', { protocol: 'tcp', port: port, stubs: [stub] }).then(function (response) {18 assert.strictEqual(response.statusCode, 201, JSON.stringify(response.body));19 return tcp.send('test', port);20 }).then(function (response) {21 assert.strictEqual(response.toString(), 'MATCHED');22 }).finally(function () {23 return api.del('/imposters');24 });25 });26 promiseIt('should allow synchronous javascript injection for responses', function () {27 var fn = function (request) { return { data: request.data + ' INJECTED' }; },28 stub = { responses: [{ inject: fn.toString() }] },29 request = { protocol: 'tcp', port: port, stubs: [stub], name: this.name };30 return api.post('/imposters', request).then(function () {31 return tcp.send('request', port);32 }).then(function (response) {33 assert.strictEqual(response.toString(), 'request INJECTED');34 }).finally(function () {35 return api.del('/imposters');36 });37 });38 promiseIt('should allow javascript injection to keep state between requests', function () {39 var fn = function (request, state) {40 if (!state.calls) { state.calls = 0; }41 state.calls += 1;42 return { data: state.calls.toString() };43 },44 stub = { responses: [{ inject: fn.toString() }] },45 request = { protocol: 'tcp', port: port, stubs: [stub], name: this.name };46 return api.post('/imposters', request).then(function (response) {47 assert.strictEqual(response.statusCode, 201, JSON.stringify(response.body));48 return tcp.send('request', port);49 }).then(function (response) {50 assert.strictEqual(response.toString(), '1');51 return tcp.send('request', port);52 }).then(function (response) {53 assert.deepEqual(response.toString(), '2');54 }).finally(function () {55 return api.del('/imposters');56 });57 });58 promiseIt('should allow asynchronous injection', function () {59 var originServerPort = port + 1,60 originServerStub = { responses: [{ is: { body: 'origin server' } }] },61 originServerRequest = {62 protocol: 'http',63 port: originServerPort,64 stubs: [originServerStub],65 name: this.name + ' origin'66 },67 fn = function (request, state, logger, callback) {68 var net = require('net'),69 options = {70 host: '127.0.0.1',71 port: '$PORT'72 },73 socket = net.connect(options, function () {74 socket.end(request.data + '\n');75 });76 socket.once('data', function (data) {77 callback({ data: data });78 });79 // No return value!!!80 },81 stub = { responses: [{ inject: fn.toString().replace("'$PORT'", originServerPort) }] };82 return api.post('/imposters', originServerRequest).then(function (response) {83 assert.strictEqual(response.statusCode, 201, JSON.stringify(response.body, null, 4));84 return api.post('/imposters', { protocol: 'tcp', port: port, stubs: [stub] });85 }).then(function (response) {86 assert.strictEqual(response.statusCode, 201, JSON.stringify(response.body));87 return tcp.send('GET / HTTP/1.1\r\nHost: www.google.com\r\n\r', port);88 }).then(function (response) {89 assert.strictEqual(response.toString().indexOf('HTTP/1.1'), 0);90 }).finally(function () {91 return api.del('/imposters');92 });93 });94 promiseIt('should allow binary requests extending beyond a single packet using endOfRequestResolver', function () {95 // We'll simulate a protocol that has a 4 byte message length at byte 0 indicating how many bytes follow96 var getRequest = function (length) {97 var buffer = new Buffer(length + 4);98 buffer.writeUInt32LE(length, 0);99 for (var i = 0; i < length; i += 1) {100 buffer.writeInt8(0, i + 4);101 }102 return buffer;103 },104 largeRequest = getRequest(100000),105 responseBuffer = new Buffer([0, 1, 2, 3]),106 stub = { responses: [{ is: { data: responseBuffer.toString('base64') } }] },107 resolver = function (requestData) {108 var messageLength = requestData.readUInt32LE(0);109 return requestData.length === messageLength + 4;110 },111 request = {112 protocol: 'tcp',113 port: port,114 stubs: [stub],115 mode: 'binary',116 name: this.name,117 endOfRequestResolver: { inject: resolver.toString() }118 };119 return api.post('/imposters', request).then(function (response) {120 assert.strictEqual(response.statusCode, 201);121 return tcp.send(largeRequest, port);122 }).then(function () {123 return api.get('/imposters/' + port);124 }).then(function (response) {125 assert.strictEqual(response.body.requests.length, 1);126 assert.strictEqual(response.body.requests[0].data, largeRequest.toString('base64'));127 }).finally(function () {128 return api.del('/imposters');129 });130 });131 promiseIt('should allow text requests extending beyond a single packet using endOfRequestResolver', function () {132 // We'll simulate HTTP133 // The last 'x' is added because new Array(5).join('x') creates 'xxxx' in JavaScript...134 var largeRequest = 'Content-Length: 100000\n\n' + new Array(100000).join('x') + 'x',135 stub = { responses: [{ is: { data: 'success' } }] },136 resolver = function (requestData) {137 var bodyLength = parseInt(/Content-Length: (\d+)/.exec(requestData)[1]),138 body = /\n\n(.*)/.exec(requestData)[1];139 return body.length === bodyLength;140 },141 request = {142 protocol: 'tcp',143 port: port,144 stubs: [stub],145 mode: 'text',146 name: this.name,147 endOfRequestResolver: { inject: resolver.toString() }148 };149 return api.post('/imposters', request).then(function (response) {150 assert.strictEqual(response.statusCode, 201);151 return tcp.send(largeRequest, port);152 }).then(function () {153 return api.get('/imposters/' + port);154 }).then(function (response) {155 assert.strictEqual(response.body.requests.length, 1);156 assert.strictEqual(response.body.requests[0].data, largeRequest);157 }).finally(function () {158 return api.del('/imposters');159 });160 });161 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import React, { useState, useEffect } from 'react';2import PropTypes from 'prop-types';3import ModalImage from 'react-modal-image';4import btoa from 'btoa';5const S3Modal = ({ imgKey, sWidth, lWidth }) => {6 const [smallSrc, setSmallSrc] = useState('');7 const [largeSrc, setLargeSrc] = useState('');8 useEffect(() => {9 getImageSources(imgKey);10 }, []);11 const domain = 'https://d3l78fpbbpsayf.cloudfront.net/';12 const smallRequest = {13 bucket: 'fastlab-master-20190705141744-storage164059-master',14 key: imgKey,15 edits: {16 normalize: true,17 sharpen: true,18 resize: {19 width: sWidth,20 fit: 'inside',21 },22 },23 };24 const largeRequest = {25 bucket: 'fastlab-master-20190705141744-storage164059-master',26 key: imgKey,27 edits: {28 normalize: true,29 sharpen: true,30 resize: {31 width: lWidth,32 fit: 'inside',33 },34 },35 };36 const getImageSources = () => {37 const smallStrRequest = JSON.stringify(smallRequest);38 const largeStrRequest = JSON.stringify(largeRequest);39 const smallEncRequest = btoa(smallStrRequest);40 const largeEncRequest = btoa(largeStrRequest);41 const smallUrl = `${domain}${smallEncRequest}`;42 const largeUrl = `${domain}${largeEncRequest}`;43 setSmallSrc(smallUrl);44 setLargeSrc(largeUrl);45 };46 if (!smallSrc || !largeSrc) {47 return null;48 }49 return (50 <ModalImage51 className="smallImage"52 hideDownload53 small={smallSrc}54 large={largeSrc}55 alt="Gallery Image"56 />57 );58};59S3Modal.propTypes = {60 sWidth: PropTypes.number,61 lWidth: PropTypes.number,62 imgKey: PropTypes.string,63};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 headers: {4 },5 body: {6 {7 {8 equals: {9 }10 }11 {12 is: {13 }14 }15 }16 },17};18request(options, function (error, response, body) {19 if (error) throw new Error(error);20 console.log(body);21});22var request = require('request');23var options = {24 headers: {25 },26 body: {27 headers: {28 },29 body: {30 }31 },32};33request(options, function (error, response, body) {34 if (error) throw new Error(error);35 console.log(body);36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 headers: {4 },5 body: {6 {7 {8 is: {9 }10 }11 }12 },13};14request(options, function (error, response, body) {15 if (error) throw new Error(error);16 console.log(body);17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 headers: {4 },5 json: {6 {7 {8 equals: {9 }10 }11 {12 is: {13 headers: {14 },15 }16 }17 }18 }19};20request(options, function(error, response, body) {21 if (!error && response.statusCode == 201) {22 console.log(body);23 }24});25var request = require('request');26var options = {27 headers: {28 },29 json: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const request = require('request');2const options = {3 json: {4 {5 {6 is: {7 }8 }9 }10 }11};12request(options, (error, response, body) => {13 if (!error && response.statusCode === 201) {14 const options = {15 };16 request(options, (error, response, body) => {17 if (!error && response.statusCode === 200) {18 console.log(body);19 }20 });21 }22});23{24 "scripts": {25 },26 "dependencies": {27 }28}

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 json: {4 {5 {6 "is": {7 }8 }9 }10 }11};12request(options, function (error, response, body) {13 if (!error && response.statusCode == 201) {14 console.log(body);15 }16});17var request = require('request');18var options = {19 json: {20 {21 {22 "is": {23 }24 }25 }26 }27};28request(options, function (error, response, body) {29 if (!error && response.statusCode == 201) {30 console.log(body);31 }32});33var request = require('request');34var options = {35};36request(options, function (error, response, body) {37 if (!error && response.statusCode == 201) {38 console.log(body);39 }40});41var request = require('request');42var options = {43};44request(options, function (error, response, body) {45 if (!error && response.statusCode == 201) {46 console.log(body);47 }48});49var request = require('request');50var options = {51 json: {52 {53 "is": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2 {3 {4 {5 is: {6 headers: { 'Content-Type': 'application/json' },7 body: JSON.stringify({ status: 'ok' })8 }9 }10 }11 }12];13mb.create({ imposters: imposters }, function (error, server) {14 console.log('Server started on port ' + server.port);15 var options = {16 body: 'a'.repeat(1000000),17 };18 mb.http.send(options, function (error, response) {19 console.log(response.body);20 });21});22var mb = require('mountebank');23 {24 {25 {26 is: {27 headers: { 'Content-Type': 'application/json' },28 body: 'a'.repeat(1000000)29 }30 }31 }32 }33];34mb.create({ imposters: imposters }, function (error, server) {35 console.log('Server started on port ' + server.port);36 var options = {37 };38 mb.http.send(options, function (error, response) {39 console.log(response.body.length);40 });41});

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var mb = require('mountebank');3var port = 2525;4var imposter = {5 stubs: [{6 predicates: [{7 equals: { method: 'POST', path: '/large' }8 }],9 responses: [{10 is: { body: 'OK' }11 }]12 }]13};14mb.create({ port: port }, function (error) {15 if (error) {16 console.log('Error creating mountebank instance: ' + error);17 } else {18 mb.post('/imposters', imposter, function (error) {19 if (error) {20 console.log('Error creating imposter: ' + error);21 } else {22 var options = {23 body: {24 data: 'x'.repeat(1000000)25 }26 };27 request(options, function (error, response, body) {28 if (error) {29 console.log('Error sending request: ' + error);30 } else {31 console.log('Response: ' + response.statusCode + ' ' + response.statusMessage);32 }33 });34 }35 });36 }37});38The request library is very convenient for making HTTP requests, but it has a limitation that is important to consider. By

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var options = {3};4mb.create(options, function (error, mbServer) {5 var imposter = {6 {7 {8 is: {9 headers: {10 },11 }12 }13 }14 };15 mbServer.createImposter(imposter, function (error, imposter) {16 console.log('Imposter created at %s', imposter.url);17 });18});19var mb = require('mountebank');20var options = {21};22mb.create(options, function (error, mbServer) {23 var imposter = {24 {25 {26 is: {27 headers: {28 },29 }30 }31 }32 };33 mbServer.createImposter(imposter, function (error, imposter) {34 console.log('Imposter created at %s', imposter.url);35 });36});37var mb = require('mountebank');38var options = {39};40mb.create(options, function (error, mbServer) {41 var imposter = {42 {43 {44 is: {45 headers: {46 },47 }48 }49 }50 };51 mbServer.createImposter(imposter, function (error, imposter) {52 console.log('Imposter created at %s', im

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var fs = require('fs');3var data = fs.readFileSync('data.json');4var options = {5 headers: {6 },7};8request.post(options, function(err, res, body) {9 if (err) {10 console.log(err);11 } else {12 console.log(body);13 }14});15{16 {17 {18 "is": {19 }20 }21 }22}23import requests24import json25data = json.load(open("data.json"))26r = requests.post(url, json=data)27var request = require('request');28var fs = require('fs');29var data = fs.readFileSync('data.json');30var options = {31 headers: {32 },33};34request.post(options, function(err, res, body) {35 if (err) {36 console.log(err);37 } else {38 console.log(body);39 }40});41import java.net.URL;42import java.net.HttpURLConnection;43import java.io.File;44import java.io.BufferedReader;45import java.io.FileReader;46import java.io.InputStreamReader;47import java.io.OutputStream;48import java.io.IOException;49import java.io.InputStream;50public class HttpClient {51 public static void main(String[] args) throws IOException {52 String data = readFile("data.json");53 URL obj = new URL(url);54 HttpURLConnection con = (HttpURLConnection) obj.openConnection();55 con.setRequestMethod("POST");56 con.setRequestProperty("Content-Type", "application/json");57 con.setDoOutput(true);

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