Skip to content

fix(sign): Defaulted amoBaseUrl when signing from the Node API - #3833

Open
MaxFreedomPollard wants to merge 1 commit into
mozilla:masterfrom
MaxFreedomPollard:fix/amo-base-url
Open

MaxFreedomPollard wants to merge 1 commit into
mozilla:masterfrom
MaxFreedomPollard:fix/amo-base-url

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown

Fixes #3164.

Calling webExt.cmd.sign({apiKey, apiSecret, artifactsDir, channel, sourceDir}) from Node fails with Invalid AMO API base URL: undefined. The default only exists as a yargs default in the CLI option table (src/program.js:527), so it is applied on the command line and nowhere else. src/cmd/sign.js:23 destructures amoBaseUrl with no default, and signAddon rejects a missing value at src/util/submit-addon.js:500-503. The reporter hit this moving from 7.x to 8.x and worked around it by hardcoding amoBaseUrl: 'https://addons.mozilla.org/api/v5/', which pins them to an API version web-ext is meant to manage for them.

This moves the constant into a new dependency-free module, src/util/constants.js. src/program.js imports it and re-exports it, so import { AMO_BASE_URL } from './program.js' keeps working for existing callers and tests, and the CLI option table is untouched. src/cmd/sign.js imports it from the new module rather than from src/program.js, so a Node API caller does not pull yargs and the rest of the CLI in behind it. No command module imports src/program.js today, and src/cmd/index.js loads commands lazily for the same start-up reason (#1302).

One scope note: signAddon() in src/util/submit-addon.js still takes amoBaseUrl explicitly. It is public API, since package.json exports ./util/submit-addon, so this is a real choice rather than an oversight. I kept the change to the entry point the issue reports, but signAddon() can get the same default here if you would rather have it in one place.

The new test is "defaults the AMO base URL when it is not passed in" in tests/unit/test-cmd/test.sign.js. getStubs() always supplies amoBaseUrl, so the test copies the stub config, deletes that key, and asserts that submitAddon was called with the default. Reverting the one line in src/cmd/sign.js makes it fail with amoBaseUrl: undefined. The README example for webExt.cmd.sign() also drops the hardcoded amoBaseUrl; the signAddon() example below it keeps it, because that entry point still needs it.

Unit tests, eslint and prettier pass locally.

The documented default for amoBaseUrl only existed as a yargs default in
the CLI option table, so it was applied on the command line and nowhere
else. Calling webExt.cmd.sign() from Node without that option passed
undefined down to signAddon(), which rejected it with "Invalid AMO API
base URL: undefined". The constant now lives in src/util/constants.js,
program.js imports and re-exports it so existing imports keep working,
and src/cmd/sign.js uses it as the parameter default. The README example
for webExt.cmd.sign() no longer passes amoBaseUrl, because it is no
longer needed there.

Fixes mozilla#3164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"AMO API base URL" must be specified even though docs say it has a default

1 participant