Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sign): add cli option to be specified when a submission only includes human readable source code #2940

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/cmd/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function sign(
channel,
amoMetadata,
uploadSourceCode,
onlyHumanReadableSourceCode,
webextVersion,
},
{
Expand All @@ -43,6 +44,20 @@ export default function sign(
} = {},
) {
return withTempDir(async function (tmpDir) {
if (!uploadSourceCode && !onlyHumanReadableSourceCode) {
throw new UsageError(
'Incomplete command. Either --upload-source-code or --only-human-readable-source-code ' +
'CLI options should be explicitly included in the sign command.'
);
}

if (uploadSourceCode && onlyHumanReadableSourceCode) {
throw new UsageError(
'Invalid options. Only one of --upload-source-code or --only-human-readable-source-code ' +
'CLI options should be included in the sign command.'
);
}

await prepareArtifactsDir(artifactsDir);

let manifestData;
Expand Down
14 changes: 13 additions & 1 deletion src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,22 @@ Example: $0 --help run.
describe:
'Path to an archive file containing human readable source code of this submission, ' +
'if the code in --source-dir has been processed to make it unreadable. ' +
'Use --only-human-readable-source-code option if source code assets ' +
'in the submission are all human readable.' +
'See https://extensionworkshop.com/documentation/publish/source-code-submission/ for ' +
'details. Only used with `use-submission-api`',
'details.',
type: 'string',
},
'only-human-readable-source-code': {
describe:
'Signal that all source code assets in the xpi file are already human readable ' +
'and uploading a separate source code archive is not necessary.' +
'See https://extensionworkshop.com/documentation/publish/source-code-submission/ for ' +
'details.',
type: 'boolean',
demandOption: false,
default: null,
},
},
)
.command('run', 'Run the extension', commands.run, {
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/test.cli.sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('web-ext sign', () => {
'--verbose',
'--channel',
'listed',
'--only-human-readable-source-code',
'--amo-base-url',
'http://localhost:8989/fake/api/v5',
'--api-key',
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('web-ext sign', () => {
sign: {
amoBaseUrl: 'http://localhost:8989/fake/api/v5',
channel: 'listed',
onlyHumanReadableSourceCode: true,
},
sourceDir: srcDir,
},
Expand Down
39 changes: 31 additions & 8 deletions tests/unit/test-cmd/test.sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,22 @@ describe('sign', () => {
* Run the sign command with stubs for all dependencies.
*/
function sign(tmpDir, stubs, { extraArgs = {}, extraOptions = {} } = {}) {
const signCLIOptions = {
verbose: false,
artifactsDir: path.join(tmpDir.path(), 'artifacts-dir'),
sourceDir: tmpDir.path(),
channel: 'listed',
...stubs.signingConfig,
...extraArgs,
};
if (
!('uploadSourceCode' in signCLIOptions) &&
!('onlyHumanReadableSourceCode' in signCLIOptions)
) {
signCLIOptions.onlyHumanReadableSourceCode = true;
}
return completeSignCommand(
{
verbose: false,
artifactsDir: path.join(tmpDir.path(), 'artifacts-dir'),
sourceDir: tmpDir.path(),
channel: 'listed',
...stubs.signingConfig,
...extraArgs,
},
signCLIOptions,
{
...stubs.signingOptions,
...extraOptions,
Expand All @@ -89,6 +96,7 @@ describe('sign', () => {
sourceDir,
artifactsDir: path.join(tmpDir.path(), 'artifacts'),
channel: 'listed',
onlyHumanReadableSourceCode: true,
...stubs.signingConfig,
apiProxy,
},
Expand Down Expand Up @@ -223,6 +231,21 @@ describe('sign', () => {
});
}));

it('rejects an UsageError if --upload-source-code or --only-human-readable-source-code are both falsey', async () => {
const signPromise = completeSignCommand({});
await assert.isRejected(signPromise, UsageError);
await assert.isRejected(signPromise, /Incomplete command. Either .* CLI options should be explicitly included/);
});

it('rejects an UsageError if --upload-source-code and --only-human-readable-source-code are both truthy', async () => {
const signPromise = completeSignCommand({
uploadSourceCode: 'fake-source-code-path.zip',
onlyHumanReadableSourceCode: true,
});
await assert.isRejected(signPromise, UsageError);
await assert.isRejected(signPromise, /Invalid options. Only one of .* CLI options should be included/);
});

it('passes the uploadSourceCode parameter to submissionAPI signer as submissionSource', () =>
withTempDir((tmpDir) => {
const stubs = getStubs();
Expand Down