Skip to content

Commit

Permalink
fix(verifier): add changeOrigin flag for http-proxy
Browse files Browse the repository at this point in the history
* add changeOrigin flag for http-proxy and update readme
* amend changeOrigin check as it was incorrect

Fixes #282
  • Loading branch information
YOU54F authored and mefellows committed Mar 12, 2019
1 parent 78d1e16 commit 4536be5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

</details>

Expand Down Expand Up @@ -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**

Expand Down
5 changes: 5 additions & 0 deletions src/dsl/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface VerifierOptions {
format?: "json" | "RspecJunitFormatter"
out?: string
validateSSL?: boolean
changeOrigin?: boolean
}

export class Verifier {
Expand Down Expand Up @@ -156,6 +157,7 @@ export class Verifier {
app.all("/*", (req, res) => {
logger.debug("Proxing", req.path)
proxy.web(req, res, {
changeOrigin: this.config.changeOrigin === true,
secure: this.config.validateSSL === true,
target: this.config.providerBaseUrl,
})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4536be5

Please sign in to comment.