Skip to content

Commit

Permalink
fix(auth): Autodetect IDE usage and fallback to API token based authe…
Browse files Browse the repository at this point in the history
…ntication (#5241)

* fix(auth): Autodetect IDE usage and fallback to API token based authentication

* chore: update final gaf commit

* test: add closed box test
  • Loading branch information
PeterSchafer authored May 17, 2024
1 parent 3fcf8bc commit 4c795e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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);
});
});

0 comments on commit 4c795e0

Please sign in to comment.