Skip to content

Commit

Permalink
ensure that we parse the url again after resolving variables, which
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket Panse committed Aug 24, 2016
1 parent ccd72f1 commit 34c4555
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/runner/extensions/request.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ module.exports = {
async.waterfall([
// Process any authentication helpers in the request.
function (cb) {
// Re-parse the URL, because variables have been resolved now, and things might be moved around
item.request.url = new (sdk.Url)(item.request.url.toString());
cb(null, item.request.authorize());
},
// Handle file resolution
Expand Down
53 changes: 53 additions & 0 deletions test/integration-sinon/url-sanity-before-request.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = {
options: {},

collection: {
"variables": [],
"info": {
"name": "url-vars",
"_postman_id": "cc88d146-720e-af9a-d530-9ee84ae2ec94",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "{{url}}/:verb",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": "postman.setGlobalVariable(\"url\", \"http://httpbin.org\");"
}
}
],
"request": {
"url": {
"raw": "{{url}}/:verb",
"auth": {},
"host": [
"{{url}}"
],
"path": [
":verb"
],
"variable": [
{
"value": "get",
"id": "verb"
}
]
},
"method": "GET",
"header": [],
"body": {
"mode": "formdata",
"formdata": []
},
"description": ""
},
"response": []
}
]
}
};
24 changes: 24 additions & 0 deletions test/integration-sinon/url-sanity-before-request.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('sanity test', function () {
it('must have started and completed the test run', function () {
expect(testrun).be.ok();
expect(testrun.done.calledOnce).be.ok();
expect(testrun.start.calledOnce).be.ok();
});

it('must parse the url after variable resolution', function () {
var request = testrun.beforeRequest.getCall(0).args[2];

expect(testrun.beforeRequest.calledOnce).be.ok(); // one request
expect(request).be.ok();
expect(request.url.host).to.not.match(/^http:\/\/.*/);
expect(request.url.toString()).eql('http://httpbin.org/get');
expect(request.method).be('GET');
});

it('must receive response with status code 200 OK', function () {
var response = testrun.request.getCall(0).args[2];

expect(testrun.request.calledOnce).be.ok(); // one request
expect(response.code).to.be(200);
});
});

0 comments on commit 34c4555

Please sign in to comment.