-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support OAuth Client Credentials Grant [HEAD-873] (#4970)
* feat: Support OAuth Client Credentials Grant * chore: improve help and remove obsolete test * fix: adapt test expectation to new behaviour * chore: added some basic oauth client cred tests * chore: run formatter * chore: remove test token to not interfer with other tests * chore: cleanup after auth test * fix: add missing return * chore: use final GAF commit
- Loading branch information
1 parent
0b6743c
commit 63b7378
Showing
6 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { fakeServer } from '../../acceptance/fake-server'; | ||
import { runSnykCLI } from '../util/runSnykCLI'; | ||
|
||
jest.setTimeout(1000 * 60); | ||
|
||
describe('Auth', () => { | ||
let server: ReturnType<typeof fakeServer>; | ||
let env: Record<string, string>; | ||
|
||
beforeAll((done) => { | ||
const apiPath = '/api/v1'; | ||
const apiPort = process.env.PORT || process.env.SNYK_PORT || '12345'; | ||
env = { | ||
...process.env, | ||
SNYK_API: 'http://localhost:' + apiPort + apiPath, | ||
SNYK_DISABLE_ANALYTICS: '1', | ||
}; | ||
|
||
server = fakeServer(apiPath, env.SNYK_TOKEN); | ||
server.listen(apiPort, () => done()); | ||
}); | ||
|
||
afterEach(() => { | ||
server.restore(); | ||
}); | ||
|
||
afterAll((done) => { | ||
server.close(() => done()); | ||
}); | ||
|
||
it('successfully uses oauth client credentials grant to authenticate', async () => { | ||
const { code } = await runSnykCLI( | ||
`auth --auth-type=oauth --client-id a --client-secret b`, | ||
{ | ||
env, | ||
}, | ||
); | ||
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 () => { | ||
const { code } = await runSnykCLI( | ||
`auth --auth-type=oauth --client-id wrong --client-secret b`, | ||
{ | ||
env, | ||
}, | ||
); | ||
expect(code).toEqual(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,9 +245,7 @@ describe('cli args', () => { | |
}); | ||
|
||
[ | ||
'auth', | ||
'config', | ||
'help', | ||
'ignore', | ||
'modules', | ||
'monitor', | ||
|