Skip to content

Commit

Permalink
POST method added to public endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
IGZvictorfierro committed Jun 1, 2016
1 parent 200e474 commit 24c431b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/public_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = function () {
publicEndpoint.replace('*','.*');
const regEx = new RegExp(publicEndpoint);
server.get(regEx, prepareOptions,propagateRequest);
server.post(regEx, prepareOptions,propagateRequest);
});
}

Expand Down
6 changes: 4 additions & 2 deletions tests-acceptance/proxy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ 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 <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a body <RESPONSE_PAYLOAD>
When the application makes a <METHOD> without credentials <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
And the response body must be <RESPONSE_PAYLOAD>
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"} |

20 changes: 14 additions & 6 deletions tests-acceptance/step_definitions/protected_service_definiton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 24c431b

Please sign in to comment.