From 34c4555f625e9e34bde34aaf25fa4abe920cfc6e Mon Sep 17 00:00:00 2001 From: Aniket Panse Date: Wed, 24 Aug 2016 18:58:57 +0530 Subject: [PATCH] ensure that we parse the url again after resolving variables, which is a solution for: * postmanlabs/postman-app-support#2276 * postmanlabs/postman-app-support#2285 --- lib/runner/extensions/request.command.js | 2 + .../url-sanity-before-request.spec.js | 53 +++++++++++++++++++ .../url-sanity-before-request.test.js | 24 +++++++++ 3 files changed, 79 insertions(+) create mode 100644 test/integration-sinon/url-sanity-before-request.spec.js create mode 100644 test/integration-sinon/url-sanity-before-request.test.js diff --git a/lib/runner/extensions/request.command.js b/lib/runner/extensions/request.command.js index ad9e5bd16..6657bf6e6 100644 --- a/lib/runner/extensions/request.command.js +++ b/lib/runner/extensions/request.command.js @@ -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 diff --git a/test/integration-sinon/url-sanity-before-request.spec.js b/test/integration-sinon/url-sanity-before-request.spec.js new file mode 100644 index 000000000..a7039dd0c --- /dev/null +++ b/test/integration-sinon/url-sanity-before-request.spec.js @@ -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": [] + } + ] + } +}; diff --git a/test/integration-sinon/url-sanity-before-request.test.js b/test/integration-sinon/url-sanity-before-request.test.js new file mode 100644 index 000000000..5581d70f9 --- /dev/null +++ b/test/integration-sinon/url-sanity-before-request.test.js @@ -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); + }); +});