From 86be0f35fa383868f9b8c37e2a8bcf584c22e084 Mon Sep 17 00:00:00 2001 From: YOU54F Date: Tue, 12 Mar 2019 17:42:55 +0000 Subject: [PATCH 1/2] add changeOrigin flag for http-proxy and update readme --- README.md | 4 +++- src/dsl/verifier.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b4ce2f72..f8866733b 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,8 @@ new Verifier().verifyProvider(opts).then(function () { | `timeout` | false | number | The duration in ms we should wait to confirm verification process was successful. Defaults to 30000. | | `requestFilter` | false | object | An Express middleware handler (See https://expressjs.com/en/guide/writing-middleware.html) to modify requests and responses from the provider. See below for more details. | | `stateHandlers` | false | object | Provider state handlers. A map of `string` -> `() => Promise`, where each string is the state to setup, and the function is used to configure the state in the Provider. See below for detail. | +| `validateSSL` | false | boolean | Allow self-signed certificates. Defaults to true, if not set. | +| `changeOrigin` | false | boolean | Changes the origin of the host header to the target URL. Defaults to false, if not set. | @@ -341,7 +343,7 @@ Sometimes you may need to add things to the requests that can't be persisted in For these cases, we have two facilities that should be carefully used during verification: 1. the ability to specify custom headers to be sent during provider verification. The flag to achieve this is `customProviderHeaders`. -1. the ability to modify a request/response and modify the payload. The flag to achieve this is `requestFilter`. +2. the ability to modify a request/response and modify the payload. The flag to achieve this is `requestFilter`. **Example API with Authorization** diff --git a/src/dsl/verifier.ts b/src/dsl/verifier.ts index eff411e53..1eccb5968 100644 --- a/src/dsl/verifier.ts +++ b/src/dsl/verifier.ts @@ -48,6 +48,7 @@ export interface VerifierOptions { format?: "json" | "RspecJunitFormatter" out?: string validateSSL?: boolean + changeOrigin?: boolean } export class Verifier { @@ -156,6 +157,7 @@ export class Verifier { app.all("/*", (req, res) => { logger.debug("Proxing", req.path) proxy.web(req, res, { + changeOrigin: this.config.changeOrigin === false, secure: this.config.validateSSL === true, target: this.config.providerBaseUrl, }) @@ -209,6 +211,9 @@ export class Verifier { if (this.config.validateSSL === undefined) { this.config.validateSSL = true } + if (this.config.changeOrigin === undefined) { + this.config.changeOrigin = false + } if (this.config.logLevel && !isEmpty(this.config.logLevel)) { serviceFactory.logLevel(this.config.logLevel) From a9196a490365744705944a9fb7e549e8e732bc57 Mon Sep 17 00:00:00 2001 From: YOU54F Date: Tue, 12 Mar 2019 22:54:57 +0000 Subject: [PATCH 2/2] amend changeOrigin check as it was incorrect --- src/dsl/verifier.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsl/verifier.ts b/src/dsl/verifier.ts index 1eccb5968..271c59335 100644 --- a/src/dsl/verifier.ts +++ b/src/dsl/verifier.ts @@ -157,7 +157,7 @@ export class Verifier { app.all("/*", (req, res) => { logger.debug("Proxing", req.path) proxy.web(req, res, { - changeOrigin: this.config.changeOrigin === false, + changeOrigin: this.config.changeOrigin === true, secure: this.config.validateSSL === true, target: this.config.providerBaseUrl, })