-
Notifications
You must be signed in to change notification settings - Fork 561
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
fix: bug with --experimental-dep-graph and wrong auth token #882
Conversation
c690006
to
a511bc5
Compare
export function AuthFailedError( | ||
errorMessage: string = 'Authentication failed. Please check the API token on ' + | ||
config.ROOT, | ||
errorCode = 401, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice refactor
src/cli/commands/monitor/index.ts
Outdated
@@ -83,6 +88,10 @@ async function monitor(...args0: MethodArgs): Promise<any> { | |||
|
|||
apiTokenExists(); | |||
|
|||
if (!(await isAuthed())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other modules perform isAuthed before apiTokenExists, expecting apiTokenExists to throw MissingApiTokenError when auth fails. Seems a bit subtle to me, however we probably have this pattern to support commands that can be run when unauthenticated?
- ignore: https://github.com/snyk/snyk/blob/c965884b69624d7ab293391c0cd9107e3d03c27b/src/cli/commands/ignore.ts#L18-L26
- protect wizard: https://github.com/snyk/snyk/blob/79b792b57407408eb7df71e9cec3efc2605169a8/src/cli/commands/protect/wizard.ts#L99-L108
- test: I couldn't see isAuthed being used in test, but apiTokenExists is called - maybe same bug there?
@@ -133,11 +133,37 @@ test('monitor for package with no name in lockfile', async (t) => { | |||
t.pass('succeed'); | |||
}); | |||
|
|||
test('`monitor npm-package with experimental-dep-graph not enabled`', async (t) => { | |||
test('`monitor npm-package with experimental-dep-graph enabled, but bad auth token`', async (t) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
4af3b20
to
d70b173
Compare
Just want to make sure - did you test this with FF enabled for the group and not the org? (which was the original issue reported, so it would be nice to validate it) |
d70b173
to
89fa972
Compare
Doing a smaller refactor to fix the issue and creating a ticket for later for overall CLI improvement, cos this is much bigger scope that was thought in the beginning. |
89fa972
to
924f10a
Compare
🎉 This PR is included in version 1.251.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What does this PR do?
Fix auth error if experimental-dep-graph exists.
If cli was invoked with experimental-dep-graph flag and invalid token, user will get error message
Feature flag 'experimental-dep-graph' is not currently enabled for your org, to enable please contact snyk support, cos token wasn't checked for validity and line https://github.com/snyk/snyk/blob/master/src/cli/commands/monitor/index.ts#L91 will return actually 401 Not Authorised, but because we do isFFSupported.ok and it was undefined, user will see totally unrelated error message.