You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

mockttp

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.19.0 to 0.19.1

11

dist/rules/handlers.d.ts

@@ -80,2 +80,12 @@ /**

}
export declare class FileHandler extends Serializable implements RequestHandler {
status: number;
statusMessage: string | undefined;
filePath: string;
headers?: Headers | undefined;
readonly type = "file";
constructor(status: number, statusMessage: string | undefined, filePath: string, headers?: Headers | undefined);
explain(): string;
handle(_request: OngoingRequest, response: OngoingResponse): Promise<void>;
}
export interface PassThroughResponse {

@@ -150,2 +160,3 @@ id: string;

'stream': typeof StreamHandler;
'file': typeof FileHandler;
'passthrough': typeof PassThroughHandler;

@@ -152,0 +163,0 @@ 'close-connection': typeof CloseConnectionHandler;

@@ -25,2 +25,3 @@ "use strict";

const serialization_1 = require("../util/serialization");
const fs_1 = require("../util/fs");
// An error that indicates that the handler is aborting the request.

@@ -210,2 +211,29 @@ // This could be intentional, or an upstream server aborting the request.

exports.StreamHandler = StreamHandler;
class FileHandler extends serialization_1.Serializable {
constructor(status, statusMessage, filePath, headers) {
super();
this.status = status;
this.statusMessage = statusMessage;
this.filePath = filePath;
this.headers = headers;
this.type = 'file';
}
explain() {
return `respond with status ${this.status}` +
(this.statusMessage ? ` (${this.statusMessage})` : "") +
(this.headers ? `, headers ${JSON.stringify(this.headers)}` : "") +
(this.filePath ? ` and body from file ${this.filePath}` : "");
}
handle(_request, response) {
return __awaiter(this, void 0, void 0, function* () {
// Read the file first, to ensure we error cleanly if it's unavailable
const fileContents = yield fs_1.readFile(this.filePath, null);
if (this.headers)
request_utils_1.setHeaders(response, this.headers);
response.writeHead(this.status, this.statusMessage);
response.end(fileContents);
});
}
}
exports.FileHandler = FileHandler;
// Used to drop `undefined` headers, which cause problems

@@ -640,2 +668,3 @@ function dropUndefinedValues(obj) {

'stream': StreamHandler,
'file': FileHandler,
'passthrough': PassThroughHandler,

@@ -642,0 +671,0 @@ 'close-connection': CloseConnectionHandler,

24

dist/rules/mock-rule-builder.d.ts

@@ -117,3 +117,3 @@ /**

/**
* Reply to matched with with given status code and (optionally) status message,
* Reply to matched requests with a given status code and (optionally) status message,
* body and headers.

@@ -203,2 +203,24 @@ *

/**
* Reply to matched requests with a given status code and the current contents
* of a given file. The status message and headers can also be optionally
* provided here.
*
* The file is read near-fresh for each request, and external changes to its
* content will be immediately appear in all subsequent requests.
*
* If one string argument is provided, it's used as the body file path.
* If two are provided (even if one is empty), then 1st is the status message,
* and the 2nd the body. This matches the argument order of thenReply().
*
* Calling this method registers the rule with the server, so it
* starts to handle requests.
*
* This method returns a promise that resolves with a mocked endpoint.
* Wait for the promise to confirm that the rule has taken effect
* before sending requests to be matched. The mocked endpoint
* can be used to assert on the requests matched by this rule.
*/
thenFromFile(status: number, filePath: string, headers?: Headers): Promise<MockedEndpoint>;
thenFromFile(status: number, statusMessage: string, filePath: string, headers?: Headers): Promise<MockedEndpoint>;
/**
* Pass matched requests through to their real destination. This works

@@ -205,0 +227,0 @@ * for proxied requests only, direct requests will be rejected with

@@ -274,2 +274,20 @@ "use strict";

}
thenFromFile(status, pathOrMessage, pathOrHeaders, headers) {
let path;
let statusMessage;
if (lodash_1.isString(pathOrHeaders)) {
path = pathOrHeaders;
statusMessage = pathOrMessage;
}
else {
path = pathOrMessage;
headers = pathOrHeaders;
}
const rule = {
matchers: this.matchers,
completionChecker: this.completionChecker,
handler: new handlers_1.FileHandler(status, statusMessage, path, headers)
};
return this.addRule(rule);
}
/**

@@ -276,0 +294,0 @@ * Pass matched requests through to their real destination. This works

2

dist/util/tls.js

@@ -50,3 +50,3 @@ "use strict";

// Valid for the next year by default.
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
cert.validity.notAfter.setFullYear(cert.validity.notAfter.getFullYear() + 1);
cert.setSubject([{ name: 'commonName', value: options.commonName }]);

@@ -53,0 +53,0 @@ cert.setExtensions([{

{
"name": "mockttp",
"version": "0.19.0",
"version": "0.19.1",
"description": "Mock HTTP server for testing HTTP clients and stubbing webservices",

@@ -106,3 +106,3 @@ "main": "dist/main.js",

"@types/node": "^10.12.9",
"@types/node-forge": "^0.8.2",
"@types/node-forge": "^0.8.7",
"apollo-server-express": "^1.1.0",

@@ -122,3 +122,3 @@ "base64-arraybuffer": "^0.1.5",

"native-duplexpair": "^1.0.0",
"node-forge": "^0.8.2",
"node-forge": "^0.9.0",
"normalize-url": "^1.9.1",

@@ -125,0 +125,0 @@ "performance-now": "^2.1.0",

@@ -36,2 +36,3 @@ /**

import { MaybePromise, Replace } from '../util/type-utils';
import { readFile } from '../util/fs';

@@ -332,2 +333,31 @@ import {

export class FileHandler extends Serializable implements RequestHandler {
readonly type = 'file';
constructor(
public status: number,
public statusMessage: string | undefined,
public filePath: string,
public headers?: Headers
) {
super();
}
explain() {
return `respond with status ${this.status}` +
(this.statusMessage ? ` (${this.statusMessage})`: "") +
(this.headers ? `, headers ${JSON.stringify(this.headers)}` : "") +
(this.filePath ? ` and body from file ${this.filePath}` : "");
}
async handle(_request: OngoingRequest, response: OngoingResponse) {
// Read the file first, to ensure we error cleanly if it's unavailable
const fileContents = await readFile(this.filePath, null);
if (this.headers) setHeaders(response, this.headers);
response.writeHead(this.status, this.statusMessage);
response.end(fileContents);
}
}
export interface PassThroughResponse {

@@ -921,2 +951,3 @@ id: string;

'stream': StreamHandler,
'file': FileHandler,
'passthrough': PassThroughHandler,

@@ -923,0 +954,0 @@ 'close-connection': CloseConnectionHandler,

@@ -48,2 +48,3 @@ /**

PassThroughHandlerOptions,
FileHandler,
} from "./handlers";

@@ -241,3 +242,3 @@ import { MaybePromise } from "../util/type-utils";

/**
* Reply to matched with with given status code and (optionally) status message,
* Reply to matched requests with a given status code and (optionally) status message,
* body and headers.

@@ -385,2 +386,49 @@ *

/**
* Reply to matched requests with a given status code and the current contents
* of a given file. The status message and headers can also be optionally
* provided here.
*
* The file is read near-fresh for each request, and external changes to its
* content will be immediately appear in all subsequent requests.
*
* If one string argument is provided, it's used as the body file path.
* If two are provided (even if one is empty), then 1st is the status message,
* and the 2nd the body. This matches the argument order of thenReply().
*
* Calling this method registers the rule with the server, so it
* starts to handle requests.
*
* This method returns a promise that resolves with a mocked endpoint.
* Wait for the promise to confirm that the rule has taken effect
* before sending requests to be matched. The mocked endpoint
* can be used to assert on the requests matched by this rule.
*/
thenFromFile(status: number, filePath: string, headers?: Headers): Promise<MockedEndpoint>;
thenFromFile(status: number, statusMessage: string, filePath: string, headers?: Headers): Promise<MockedEndpoint>
thenFromFile(
status: number,
pathOrMessage: string,
pathOrHeaders?: string | Headers,
headers?: Headers
): Promise<MockedEndpoint> {
let path: string;
let statusMessage: string | undefined;
if (isString(pathOrHeaders)) {
path = pathOrHeaders;
statusMessage = pathOrMessage as string;
} else {
path = pathOrMessage;
headers = pathOrHeaders as Headers | undefined;
}
const rule: MockRuleData = {
matchers: this.matchers,
completionChecker: this.completionChecker,
handler: new FileHandler(status, statusMessage, path, headers)
};
return this.addRule(rule);
}
/**
* Pass matched requests through to their real destination. This works

@@ -387,0 +435,0 @@ * for proxied requests only, direct requests will be rejected with

@@ -67,3 +67,3 @@ /**

// Valid for the next year by default.
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
cert.validity.notAfter.setFullYear(cert.validity.notAfter.getFullYear() + 1);

@@ -70,0 +70,0 @@ cert.setSubject([{ name: 'commonName', value: options.commonName }]);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc