Skip to content

Commit

Permalink
fix: correct credential auth failure error text
Browse files Browse the repository at this point in the history
Container registries can return an error which we dont currently catch as a Docker one, resulting in user getting shown JSON in the terminal. This fixes that by replacing it with a human-readable message, as well as clarifying that the same error can also result from bad credentials
  • Loading branch information
michael-c-snyk committed Nov 20, 2020
1 parent c92502e commit f63c30a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/errors/docker-image-not-found-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class DockerImageNotFoundError extends CustomError {
private static ERROR_CODE = 404;

constructor(image: string) {
const message = `Failed to scan image "${image}". Please make sure the image and/or repository exist.`;
const message = `Failed to scan image "${image}". Please make sure the image and/or repository exist, and that you are using the correct credentials.`;
super(message);
this.code = DockerImageNotFoundError.ERROR_CODE;
this.userMessage = message;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ export async function runTest(
if (
getEcosystem(options) === 'docker' &&
error.statusCode === 401 &&
error.message === 'authentication required'
[
'authentication required',
'{"details":"incorrect username or password"}\n',
].includes(error.message)
) {
throw new DockerImageNotFoundError(root);
}
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/cli-monitor/cli-monitor.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ if (!isWindows) {
} catch (err) {
t.match(
err.message,
'Failed to scan image "doesnotexist". Please make sure the image and/or repository exist.',
'Failed to scan image "doesnotexist". Please make sure the image and/or repository exist, and that you are using the correct credentials.',
'show err message',
);
t.pass('throws err');
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/cli-test/cli-test.docker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export const DockerTests: AcceptanceTests = {
const msg = err.message;
t.match(
msg,
'Failed to scan image "doesnotexist". Please make sure the image and/or repository exist.',
'Failed to scan image "doesnotexist". Please make sure the image and/or repository exist, and that you are using the correct credentials.',
);
}
},
Expand Down

0 comments on commit f63c30a

Please sign in to comment.