From 9efdc9d0b7d5b19aa54a51bd6c454415969ffbb6 Mon Sep 17 00:00:00 2001 From: Saksham Date: Mon, 28 Oct 2024 15:57:38 +0530 Subject: [PATCH] Fix domain regex to match doimains with or without port (#1480) --- lib/runner/util.js | 2 +- test/integration/sanity/vaultSecrets.test.js | 81 ++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/lib/runner/util.js b/lib/runner/util.js index 471a8b35b..9ee4573bb 100644 --- a/lib/runner/util.js +++ b/lib/runner/util.js @@ -201,7 +201,7 @@ module.exports = { const url = new Url(domain); // @note URL path is ignored - return `${url.protocol || 'https'}://${url.getRemote()}/*`; + return `${url.protocol || 'https'}://${url.getRemote()}:*/*`; })); }); diff --git a/test/integration/sanity/vaultSecrets.test.js b/test/integration/sanity/vaultSecrets.test.js index 6687d69bc..f6319f2a7 100644 --- a/test/integration/sanity/vaultSecrets.test.js +++ b/test/integration/sanity/vaultSecrets.test.js @@ -705,6 +705,87 @@ describe('vaultSecrets', function () { }); }); + describe('should resolve secrets when port is part of url', function () { + var testrun; + + before(function (done) { + this.run({ + vaultSecrets: { + id: 'vault', + prefix: 'vault:', + _allowScriptAccess: true, + values: [ + { + key: 'vault:var1', + value: 'basic-auth', + _domains: ['https://postman-echo.com'] + }, + { + key: 'vault:var2', + value: 'postman', + _domains: ['https://postman-echo.com'] + }, + { + key: 'vault:var3', + value: 'password' + } + ] + }, + collection: { + item: [{ + event: [ + { + listen: 'prerequest', + script: { + exec: 'pm.vault.set(\'var4\', \'http://postman-echo.com\')' + } + } + ], + request: { + url: 'https://postman-echo.com:80/{{vault:var1}}', + method: 'GET', + auth: { + type: 'basic', + basic: [ + { key: 'username', value: '{{vault:var2}}' }, + { key: 'password', value: '{{vault:var3}}' } + ] + } + } + }] + } + }, function (err, results) { + testrun = results; + done(err); + }); + }); + + it('should have completed the run', function () { + expect(testrun).to.be.ok; + expect(testrun.done.getCall(0).args[0]).to.be.null; + expect(testrun).to.nested.include({ + 'done.calledOnce': true, + 'start.calledOnce': true + }); + }); + + it('should handle protocol for a resolved domain', function () { + var url = testrun.request.getCall(0).args[3].url.toString(); + + expect(url).to.equal('https://postman-echo.com:80/basic-auth'); + }); + + it('should resolve vault secrets in auth', function () { + var request = testrun.response.getCall(0).args[3], + auth = request.auth.parameters().toObject(); + + expect(auth).to.deep.include({ + username: 'postman', + password: 'password' + }); + }); + }); + describe('scripts', function () { describe('should be able to get vault secrets using pm.vault.get', function () { var testrun;