-
Notifications
You must be signed in to change notification settings - Fork 568
/
oauth-token.spec.ts
74 lines (61 loc) · 2.07 KB
/
oauth-token.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { fakeServer } from '../../acceptance/fake-server';
import { createProjectFromWorkspace } from '../util/createProject';
import { runSnykCLI } from '../util/runSnykCLI';
import { getServerPort } from '../util/getServerPort';
jest.setTimeout(1000 * 60);
describe('OAuth Token', () => {
let server: ReturnType<typeof fakeServer>;
let env: Record<string, string>;
beforeAll((done) => {
const apiPath = '/api/v1';
const apiPort = getServerPort(process);
env = {
...process.env,
SNYK_API: 'http://localhost:' + apiPort + apiPath,
SNYK_OAUTH_TOKEN: 'oauth-jwt-token',
SNYK_DISABLE_ANALYTICS: '1',
};
server = fakeServer(apiPath, env.SNYK_TOKEN);
server.listen(apiPort, () => done());
});
afterEach(() => {
server.restore();
});
afterAll((done) => {
server.close(() => done());
});
it('uses oauth token for authorised requests when testing projects', async () => {
const project = await createProjectFromWorkspace('fail-on/no-vulns');
server.setCustomResponse(await project.readJSON('vulns-result.json'));
const { code } = await runSnykCLI(`test --json`, {
cwd: project.path(),
env,
});
expect(code).toEqual(0);
expect(server.getRequests().length).toBeGreaterThanOrEqual(1);
server.getRequests().forEach((request) => {
expect(request).toMatchObject({
headers: {
authorization: 'Bearer oauth-jwt-token',
},
});
});
});
it('uses oauth token for authorised requests when monitoring projects', async () => {
const project = await createProjectFromWorkspace('fail-on/no-vulns');
server.setCustomResponse(await project.readJSON('vulns-result.json'));
const { code } = await runSnykCLI(`monitor --json`, {
cwd: project.path(),
env,
});
expect(code).toEqual(0);
expect(server.getRequests().length).toBeGreaterThanOrEqual(1);
server.getRequests().forEach((request) => {
expect(request).toMatchObject({
headers: {
authorization: 'Bearer oauth-jwt-token',
},
});
});
});
});