Skip to content

Commit

Permalink
feat: allow any 403 response to continue verification (#662)
Browse files Browse the repository at this point in the history
* feat: allow any 403 response to continue verification

* refactor: optional chaining

---------

Co-authored-by: Shane McLaughlin <[email protected]>
  • Loading branch information
kyle-blair and mshanemc authored Dec 1, 2023
1 parent ceda9ea commit 84fff9e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shared/installationVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export async function doInstallationCodeSigningVerification(
verificationConfig.log(`Successfully validated digital signature for ${plugin.plugin}.`);
} catch (err) {
if (err instanceof Error) {
if (err.name === 'NotSigned' || err.message === 'Response code 403 (Forbidden)') {
if (err.name === 'NotSigned' || err.message?.includes('Response code 403')) {
if (!verificationConfig.verifier) {
throw new Error('VerificationConfig.verifier is not set.');
}
Expand Down
50 changes: 50 additions & 0 deletions test/shared/installationVerification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,5 +685,55 @@ describe('InstallationVerification Tests', () => {
throw err;
}
});

it('continues installation when error message is response code 403 (forbidden)', async () => {
const vConfig = new VerificationConfig();
vConfig.verifier = {
async verify() {
const err = new Error();
err.message = 'Response code 403 (Forbidden)';
throw err;
},
async isAllowListed() {
return false;
},
} as Verifier;

stubMethod(sandbox, Prompter.prototype, 'confirm').resolves(true);

try {
await doInstallationCodeSigningVerification({}, BLANK_PLUGIN, vConfig);
} catch (e) {
assert(e instanceof Error);
const err = new Error("this test shouldn't fail.");
err.stack = e.stack;
throw err;
}
});

it('continues installation when error message contains response code 403', async () => {
const vConfig = new VerificationConfig();
vConfig.verifier = {
async verify() {
const err = new Error();
err.message = 'Response code 403 (OtherReason)';
throw err;
},
async isAllowListed() {
return false;
},
} as Verifier;

stubMethod(sandbox, Prompter.prototype, 'confirm').resolves(true);

try {
await doInstallationCodeSigningVerification({}, BLANK_PLUGIN, vConfig);
} catch (e) {
assert(e instanceof Error);
const err = new Error("this test shouldn't fail.");
err.stack = e.stack;
throw err;
}
});
});
});

0 comments on commit 84fff9e

Please sign in to comment.