From 24c431bb9ee435ca14bafc09c2be670f6a68c362 Mon Sep 17 00:00:00 2001 From: Victor Fierro Date: Wed, 1 Jun 2016 11:42:28 -0700 Subject: [PATCH] POST method added to public endpoints --- src/public_service.js | 1 + tests-acceptance/proxy.feature | 6 ++++-- .../protected_service_definiton.js | 20 +++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/public_service.js b/src/public_service.js index 831e129..47e8859 100644 --- a/src/public_service.js +++ b/src/public_service.js @@ -128,6 +128,7 @@ module.exports = function () { publicEndpoint.replace('*','.*'); const regEx = new RegExp(publicEndpoint); server.get(regEx, prepareOptions,propagateRequest); + server.post(regEx, prepareOptions,propagateRequest); }); } diff --git a/tests-acceptance/proxy.feature b/tests-acceptance/proxy.feature index a960a43..dd20414 100644 --- a/tests-acceptance/proxy.feature +++ b/tests-acceptance/proxy.feature @@ -24,9 +24,9 @@ Feature: reverse proxy protects an applicacion behind cipherlayer | PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD | ALLOWED_HEADER | HEADER_VALUE | | /test/get200 | GET | 200 | | {"m":"GET", "s":"200"} | x-custom-header | test | - @only + @service - Scenario Outline: A call to a public endpoint set on config is allowed to pass + Scenario Outline: A request to a public endpoint set on config is allowed to pass (POST and GET methods) Given a protected service replies to a public request with to with status and a body When the application makes a without credentials to a protected Then the response status code is @@ -34,3 +34,5 @@ Feature: reverse proxy protects an applicacion behind cipherlayer Examples: | PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD | | /public/path | GET | 200 | | {"m":"GET", "s":"200"} | + | /public/path | POST | 200 | {"key":"value"} | {"m":"GET", "s":"200"} | + diff --git a/tests-acceptance/step_definitions/protected_service_definiton.js b/tests-acceptance/step_definitions/protected_service_definiton.js index 187d9de..4ee7708 100644 --- a/tests-acceptance/step_definitions/protected_service_definiton.js +++ b/tests-acceptance/step_definitions/protected_service_definiton.js @@ -3,13 +3,21 @@ const nock = require('nock'); const config = require('../../config'); module.exports = function(){ - this.Given(/^a protected service replies to a public GET request with (.*) to (.*) with status (.*) and a body (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){ - nock(`http://localhost:${config.private_port}`, { - reqheaders: { - 'Content-Type': 'application/json; charset=utf-8' - } - }).get(PATH).reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD)); + this.Given(/^a protected service replies to a public (.*) request with (.*) to (.*) with status (.*) and a body (.*)$/, function (METHOD, REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){ + if(METHOD === 'GET'){ + nock(`http://localhost:${config.private_port}`, { + reqheaders: { + 'Content-Type': 'application/json; charset=utf-8' + } + }).get(PATH).reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD)); + } else { + nock(`http://localhost:${config.private_port}`, { + reqheaders: { + 'Content-Type': 'application/json; charset=utf-8' + } + }).post(PATH).reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD)); + } callback(); });