Socket
Socket
Sign inDemoInstall

mockttp

Package Overview
Dependencies
33
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 3.3.1

18

dist/rules/requests/request-handlers.js

@@ -357,10 +357,13 @@ "use strict";

const { body: realBody } = yield (0, request_utils_1.waitForCompletedRequest)(clientReq);
let replacedBody = yield realBody.getText();
if (replacedBody === undefined) {
const originalBody = yield realBody.getText();
if (originalBody === undefined) {
throw new Error("Can't match & replace non-decodeable request body");
}
let replacedBody = originalBody;
for (let [match, result] of matchReplaceBody) {
replacedBody = replacedBody.replace(match, result);
}
reqBodyOverride = (0, buffer_utils_1.asBuffer)(replacedBody);
if (replacedBody !== originalBody) {
reqBodyOverride = (0, buffer_utils_1.asBuffer)(replacedBody);
}
}

@@ -541,10 +544,13 @@ if (reqBodyOverride) {

const realBody = (0, request_utils_1.buildBodyReader)(rawBody, serverRes.headers);
let replacedBody = yield realBody.getText();
if (replacedBody === undefined) {
const originalBody = yield realBody.getText();
if (originalBody === undefined) {
throw new Error("Can't match & replace non-decodeable response body");
}
let replacedBody = originalBody;
for (let [match, result] of matchReplaceBody) {
replacedBody = replacedBody.replace(match, result);
}
resBodyOverride = (0, buffer_utils_1.asBuffer)(replacedBody);
if (replacedBody !== originalBody) {
resBodyOverride = (0, buffer_utils_1.asBuffer)(replacedBody);
}
}

@@ -551,0 +557,0 @@ if (resBodyOverride) {

@@ -133,2 +133,16 @@ "use strict";

return this.certCache[domain];
if (domain.includes('_')) {
// TLS certificates cannot cover domains with underscores, bizarrely. More info:
// https://www.digicert.com/kb/ssl-support/underscores-not-allowed-in-fqdns.htm
// To fix this, we use wildcards instead. This is only possible for one level of
// certificate, and only for subdomains, so our options are a little limited, but
// this should be very rare (because it's not supported elsewhere either).
const [, ...otherParts] = domain.split('.');
if (otherParts.length <= 1 || // *.com is never valid
otherParts.some(p => p.includes('_'))) {
throw new Error(`Cannot generate certificate for domain due to underscores: ${domain}`);
}
// Replace the first part with a wildcard to solve the problem:
domain = `*.${otherParts.join('.')}`;
}
let cert = pki.createCertificate();

@@ -144,3 +158,5 @@ cert.publicKey = KEY_PAIR.publicKey;

cert.setSubject([
{ name: 'commonName', value: domain },
...(domain[0] === '*'
? [] // We skip the CN (deprecated, rarely used) for wildcards, since they can't be used here.
: [{ name: 'commonName', value: domain }]),
{ name: 'countryName', value: 'XX' },

@@ -147,0 +163,0 @@ { name: 'localityName', value: 'Unknown' },

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

@@ -197,3 +197,3 @@ "exports": {

"performance-now": "^2.1.0",
"portfinder": "^1.0.23",
"portfinder": "1.0.28",
"typed-error": "^3.0.2",

@@ -200,0 +200,0 @@ "uuid": "^8.3.2",

@@ -505,7 +505,9 @@ import _ = require('lodash');

const { body: realBody } = await waitForCompletedRequest(clientReq);
let replacedBody = await realBody.getText();
if (replacedBody === undefined) {
const originalBody = await realBody.getText();
if (originalBody === undefined) {
throw new Error("Can't match & replace non-decodeable request body");
}
let replacedBody = originalBody;
for (let [match, result] of matchReplaceBody) {

@@ -515,3 +517,5 @@ replacedBody = replacedBody!.replace(match, result);

reqBodyOverride = asBuffer(replacedBody);
if (replacedBody !== originalBody) {
reqBodyOverride = asBuffer(replacedBody);
}
}

@@ -771,7 +775,8 @@

let replacedBody = await realBody.getText();
if (replacedBody === undefined) {
const originalBody = await realBody.getText();
if (originalBody === undefined) {
throw new Error("Can't match & replace non-decodeable response body");
}
let replacedBody = originalBody;
for (let [match, result] of matchReplaceBody) {

@@ -781,3 +786,5 @@ replacedBody = replacedBody!.replace(match, result);

resBodyOverride = asBuffer(replacedBody);
if (replacedBody !== originalBody) {
resBodyOverride = asBuffer(replacedBody);
}
}

@@ -784,0 +791,0 @@

@@ -177,2 +177,20 @@ import * as _ from 'lodash';

if (domain.includes('_')) {
// TLS certificates cannot cover domains with underscores, bizarrely. More info:
// https://www.digicert.com/kb/ssl-support/underscores-not-allowed-in-fqdns.htm
// To fix this, we use wildcards instead. This is only possible for one level of
// certificate, and only for subdomains, so our options are a little limited, but
// this should be very rare (because it's not supported elsewhere either).
const [ , ...otherParts] = domain.split('.');
if (
otherParts.length <= 1 || // *.com is never valid
otherParts.some(p => p.includes('_'))
) {
throw new Error(`Cannot generate certificate for domain due to underscores: ${domain}`);
}
// Replace the first part with a wildcard to solve the problem:
domain = `*.${otherParts.join('.')}`;
}
let cert = pki.createCertificate();

@@ -192,3 +210,6 @@

cert.setSubject([
{ name: 'commonName', value: domain },
...(domain[0] === '*'
? [] // We skip the CN (deprecated, rarely used) for wildcards, since they can't be used here.
: [{ name: 'commonName', value: domain }]
),
{ name: 'countryName', value: 'XX' }, // ISO-3166-1 alpha-2 'unknown country' code

@@ -195,0 +216,0 @@ { name: 'localityName', value: 'Unknown' },

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc