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

fix: bug with --experimental-dep-graph and wrong auth token #882

Merged
merged 1 commit into from
Nov 27, 2019

Conversation

dkontorovskyy
Copy link
Contributor

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

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.

@dkontorovskyy dkontorovskyy requested a review from a team as a code owner November 26, 2019 13:11
@dkontorovskyy dkontorovskyy self-assigned this Nov 26, 2019
@ghost ghost requested review from lili2311 and lwywoo November 26, 2019 13:11
@dkontorovskyy dkontorovskyy force-pushed the fix/monitor-auth-bug branch 2 times, most recently from c690006 to a511bc5 Compare November 26, 2019 14:34
@dkontorovskyy dkontorovskyy requested review from shaninja and gitphill and removed request for lwywoo November 26, 2019 14:39
export function AuthFailedError(
errorMessage: string = 'Authentication failed. Please check the API token on ' +
config.ROOT,
errorCode = 401,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice refactor

@@ -83,6 +88,10 @@ async function monitor(...args0: MethodArgs): Promise<any> {

apiTokenExists();

if (!(await isAuthed())) {
Copy link
Contributor

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?

@@ -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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dkontorovskyy dkontorovskyy force-pushed the fix/monitor-auth-bug branch 2 times, most recently from 4af3b20 to d70b173 Compare November 26, 2019 15:57
@shaninja
Copy link
Contributor

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)

@dkontorovskyy
Copy link
Contributor Author

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.

@dkontorovskyy dkontorovskyy merged commit 96d62d5 into master Nov 27, 2019
@dkontorovskyy dkontorovskyy deleted the fix/monitor-auth-bug branch November 27, 2019 11:22
@snyksec
Copy link

snyksec commented Nov 27, 2019

🎉 This PR is included in version 1.251.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants