feat: allow resolving Postman API resources against a self-hosted deployment - #3381
Open
kavyansh-pancholi wants to merge 1 commit into
Open
feat: allow resolving Postman API resources against a self-hosted deployment#3381kavyansh-pancholi wants to merge 1 commit into
kavyansh-pancholi wants to merge 1 commit into
Conversation
…loyment Newman hardcoded the Postman API host in two places, which made it unusable against self-hosted (Postman Private Cloud) deployments: - a bare resource `uid` was always expanded to `https://api.postman.com`, so `--postman-api-key` silently targeted public SaaS; - the `X-Api-Key` header was only attached when the URL host was on a fixed allowlist, so passing a self-hosted URL caused the key to be dropped and the fetch to fail with `Invalid API Key`. The only working alternative was embedding `?apikey=` in the URL, which puts the credential in argv, shell history and every access log along the path. Adds a configurable base URL, resolved as: `postmanApiBaseUrl` run option > `POSTMAN_API_BASE_URL` environment variable > the public Postman API. The variable name matches the one already used by the Postman CLI. The host allowlist is widened only to the host the user explicitly configured, never to arbitrary URLs — it exists to stop the API key being sent to a third-party host named on the command line, and that property is preserved. Covers both `collections` and `environments` uid resolution.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (92.30%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #3381 +/- ##
===========================================
+ Coverage 81.85% 82.27% +0.41%
===========================================
Files 21 21
Lines 1152 1162 +10
Branches 352 357 +5
===========================================
+ Hits 943 956 +13
+ Misses 114 111 -3
Partials 95 95
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Newman hardcodes the Postman API host in
lib/util.js, in two separate places:This makes
--postman-api-keyunusable against a self-hosted (Postman Private Cloud) deployment, in two different ways:newman run <uid> --postman-api-key <key>https://api.postman.com/...— silently targets public SaaSnewman run https://api.self-hosted…/collections/<uid> --postman-api-key <key>X-Api-Keyis never attachedBoth surface the same
Invalid API Keyerror, and nothing indicates the flag was ignored.The only method that works today is embedding
?apikey=in the URL — which places the credential in argv, shell history, and every access log between the client and the server. For CI that is materially worse than a header.Change
A configurable base URL, resolved as:
postmanApiBaseUrlrun option →POSTMAN_API_BASE_URLenv var → the public Postman APIThe environment variable name matches the one the Postman CLI already uses, so a self-hosted user configures one variable for both tools.
bin/newman.js— new--postman-api-base-url <url>optionlib/util.js—resolveApiUrl()andisPostmanApiHost()helpers;fetchJsonuses themlib/config/index.js— thread the new key through the common-options pickcollectionsandenvironmentsuid resolution (POSTMAN_API_PATH_MAP)Default behaviour is unchanged when no override is set.
Security note
The host allowlist exists to stop the API key being sent to an arbitrary host named on the command line. That property is preserved: the allowlist is widened only to the single host the user explicitly configured, never to any URL passed in. There is an explicit test for this:
Usage
or
Tests
8 new cases in
test/library/postman-api-key.test.js, following the existing nock/sinon pattern: uid resolution for collections and environments, env-var support, option-over-env precedence, trailing-slash tolerance, header attached for the configured host, header not attached for an unrelated host, and unchanged default behaviour.test-lintclean.test-unit128 passing,test-library77 passing.test-systemhas one pre-existing failure (npm publish > should not publish unnecessary files) that also fails on a cleandevelopcheckout and is unrelated to this change.Also verified end to end against a real self-hosted deployment — bare uid via env var, bare uid via flag, and a full self-hosted URL with
--postman-api-keyall fetch and execute; with no override set the run still goes to the public API and fails as before.Docs
README gains a Self-hosted Postman deployments subsection, plus a note that the uid form sends the key as a header rather than a query parameter.