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(auth): Autodetect IDE usage and fallback to API token based authentication #5241

Merged
merged 3 commits into from
May 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/snyk/cli-extension-iac-rules v0.0.0-20240422133948-ae17a4306672
github.com/snyk/cli-extension-sbom v0.0.0-20240426130148-b83c2ebc75c4
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1
github.com/snyk/go-application-framework v0.0.0-20240515114301-86824c982460
github.com/snyk/go-application-framework v0.0.0-20240517080240-d22ced1f98d1
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20240510163626-041f744c3180
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJ
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20240425141803-2516e42296c3 h1:ZUaY5LIVGQ0GScf1SsaqvUxaiGbBKgBBLsQUgB4Zx5o=
github.com/snyk/error-catalog-golang-public v0.0.0-20240425141803-2516e42296c3/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240515114301-86824c982460 h1:gH7tm6K3Xb3i39jBdYf0YPksKHinhpP7GOWIVJtYaR8=
github.com/snyk/go-application-framework v0.0.0-20240515114301-86824c982460/go.mod h1:5gvF6i1sqmk1oN21ZbX/EDaEyQtPMfK1pbYCwtS+Fvw=
github.com/snyk/go-application-framework v0.0.0-20240517080240-d22ced1f98d1 h1:VQ3rIrdzxKGfQ7oeEeIWaxWoiZFLUlrcdgKfuXWcCjU=
github.com/snyk/go-application-framework v0.0.0-20240517080240-d22ced1f98d1/go.mod h1:5gvF6i1sqmk1oN21ZbX/EDaEyQtPMfK1pbYCwtS+Fvw=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk=
Expand Down
23 changes: 18 additions & 5 deletions test/jest/acceptance/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('Auth', () => {

beforeEach(async () => {
initialConfig = await getCliConfig();
// delete config
await runSnykCLI(`config clear`, {
env,
});
});

afterEach(async () => {
Expand All @@ -51,11 +55,6 @@ describe('Auth', () => {
},
);
expect(code).toEqual(0);

// delete test token
await runSnykCLI(`config unset INTERNAL_OAUTH_TOKEN_STORAGE`, {
env,
});
});

it('fails to us oauth client credentials grant to authenticate', async () => {
Expand Down Expand Up @@ -90,4 +89,18 @@ describe('Auth', () => {
expect(resultConfigGet.code).toEqual(0);
expect(resultConfigGet.stdout).toContain(serverToken);
});

it('fall back to API token based authentication for IDEs per default', async () => {
const { code } = await runSnykCLI(`auth`, {
env: { ...env, SNYK_INTEGRATION_NAME: 'VS_CODE' },
});

const resultConfigGet = await runSnykCLI('config get api', {
env,
});

expect(code).toEqual(0);
expect(resultConfigGet.code).toEqual(0);
expect(resultConfigGet.stdout).toContain(serverToken);
});
});
Loading