Skip to content

Commit 6d2afa1

Browse files
dwelch2344sunshastry
authored andcommitted
feat: add login and logout commands and tie it up with graphql invocations
1 parent bcb66a7 commit 6d2afa1

35 files changed

+6438
-3322
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.3.4/schema.json",
33
"assist": { "actions": { "source": { "organizeImports": "on" } } },
44
"linter": {
55
"enabled": true,

e2e/scan/eol.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import { tmpdir } from 'node:os';
88
import path from 'node:path';
99
import { afterEach, beforeEach, describe, it } from 'node:test';
1010
import { promisify } from 'node:util';
11+
//import keytar from 'keytar';
1112
import type { DeepPartial } from '@apollo/client/utilities';
1213
import type { EolScanComponent } from '@herodevs/eol-shared';
1314
import { runCommand } from '@oclif/test';
1415
import { config, filenamePrefix } from '../../src/config/constants.ts';
1516
import { FetchMock } from '../../test/utils/mocks/fetch.mock.ts';
17+
// import { getAccessTokenKey, getRefreshTokenKey, getTokenServiceName } from '../../src/service/auth-config.svc.ts';
18+
// import { createTokenWithExp } from '../../test/utils/token.ts';
1619

1720
const execAsync = promisify(exec);
1821
const fixturesDir = path.resolve(import.meta.dirname, '../fixtures');
@@ -73,6 +76,7 @@ describe('environment', () => {
7376

7477
describe('scan:eol e2e', () => {
7578
let fetchMock: FetchMock;
79+
//let testAccessToken: string;
7680

7781
beforeEach(async () => {
7882
await mkdir(fixturesDir, { recursive: true });
@@ -85,10 +89,13 @@ describe('scan:eol e2e', () => {
8589
},
8690
];
8791
fetchMock = new FetchMock().addGraphQL(mockReport(components)).addGraphQL(mockGetReport(components));
92+
// testAccessToken = createTokenWithExp(3600);
93+
// await seedAuthTokens(testAccessToken);
8894
});
8995

9096
afterEach(() => {
9197
fetchMock.restore();
98+
//return clearAuthTokens();
9299
});
93100

94101
describe('default arguments', () => {
@@ -136,6 +143,8 @@ describe('scan:eol e2e', () => {
136143
match(stdout, /Scan results:/, 'Should show results header');
137144
match(stdout, /1( .*)End-of-Life \(EOL\)/, 'Should show EOL count');
138145
match(stdout, /2 total packages scanned/, 'Should show total packages scanned');
146+
// Authorization assertions disabled for now
147+
// assertAuthorizedCalls(fetchMock, testAccessToken);
139148
});
140149

141150
it('scans existing SPDX SBOM file and converts to CycloneDX', async () => {
@@ -144,6 +153,8 @@ describe('scan:eol e2e', () => {
144153
match(stdout, /Scan results:/, 'Should show results header');
145154
match(stdout, /1( .*)End-of-Life \(EOL\)/, 'Should show EOL count');
146155
match(stdout, /2 total packages scanned/, 'Should show total packages scanned with SPDX input');
156+
// Authorization assertions disabled for now
157+
// assertAuthorizedCalls(fetchMock, testAccessToken);
147158
});
148159

149160
it('shows warning and does not generate report when no components are found in scan', async () => {
@@ -154,6 +165,8 @@ describe('scan:eol e2e', () => {
154165
/No components found in scan. Report not generated./,
155166
'Should show warning, no results header or package totals',
156167
);
168+
// Authorization assertions disabled for now
169+
// assertAuthorizedCalls(fetchMock, testAccessToken);
157170
});
158171

159172
it('saves report when --save flag is used (directory scan)', async () => {
@@ -181,6 +194,8 @@ describe('scan:eol e2e', () => {
181194
'Report should contain a date created on property in ISO format',
182195
);
183196
unlinkSync(reportPath);
197+
// Authorization assertions disabled for now
198+
// assertAuthorizedCalls(fetchMock, testAccessToken);
184199
});
185200

186201
it('warns and skips saving when --output is provided without --save', async () => {
@@ -235,6 +250,8 @@ describe('scan:eol e2e', () => {
235250
);
236251
strictEqual(!!bootstrap, true, 'Should include bootstrap');
237252
}
253+
// Authorization assertions disabled for now
254+
// assertAuthorizedCalls(fetchMock, testAccessToken);
238255
});
239256

240257
it('shows zero EOL components when scanning up-to-date packages', async () => {
@@ -631,3 +648,34 @@ describe('scan:eol e2e', () => {
631648
});
632649
});
633650
});
651+
652+
// async function seedAuthTokens(accessToken: string) {
653+
// const service = getTokenServiceName();
654+
// const accessKey = getAccessTokenKey();
655+
// const refreshKey = getRefreshTokenKey();
656+
// await keytar.setPassword(service, accessKey, accessToken);
657+
// await keytar.setPassword(service, refreshKey, 'test-refresh-token');
658+
// }
659+
660+
// async function clearAuthTokens() {
661+
// const service = getTokenServiceName();
662+
// const accessKey = getAccessTokenKey();
663+
// const refreshKey = getRefreshTokenKey();
664+
// await keytar.deletePassword(service, accessKey);
665+
// await keytar.deletePassword(service, refreshKey);
666+
// }
667+
668+
// function assertAuthorizedCalls(mock: FetchMock, token: string, options: { expectCalls?: boolean } = {}) {
669+
// const { expectCalls = true } = options;
670+
// const calls = mock.getCalls();
671+
672+
// if (expectCalls) {
673+
// strictEqual(calls.length > 0, true, 'Expected GraphQL calls to be made');
674+
// for (const call of calls) {
675+
// const headers = new Headers(call.init?.headers);
676+
// strictEqual(headers.get('Authorization'), `Bearer ${token}`, 'Authorization header should include bearer token');
677+
// }
678+
// } else {
679+
// strictEqual(calls.length, 0, 'Expected no GraphQL calls to be made');
680+
// }
681+
// }

0 commit comments

Comments
 (0)