@@ -8,11 +8,14 @@ import { tmpdir } from 'node:os';
88import path from 'node:path' ;
99import { afterEach , beforeEach , describe , it } from 'node:test' ;
1010import { promisify } from 'node:util' ;
11+ //import keytar from 'keytar';
1112import type { DeepPartial } from '@apollo/client/utilities' ;
1213import type { EolScanComponent } from '@herodevs/eol-shared' ;
1314import { runCommand } from '@oclif/test' ;
1415import { config , filenamePrefix } from '../../src/config/constants.ts' ;
1516import { 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
1720const execAsync = promisify ( exec ) ;
1821const fixturesDir = path . resolve ( import . meta. dirname , '../fixtures' ) ;
@@ -73,6 +76,7 @@ describe('environment', () => {
7376
7477describe ( '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 , / S c a n r e s u l t s : / , 'Should show results header' ) ;
137144 match ( stdout , / 1 ( .* ) E n d - o f - L i f e \( E O L \) / , 'Should show EOL count' ) ;
138145 match ( stdout , / 2 t o t a l p a c k a g e s s c a n n e d / , '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 , / S c a n r e s u l t s : / , 'Should show results header' ) ;
145154 match ( stdout , / 1 ( .* ) E n d - o f - L i f e \( E O L \) / , 'Should show EOL count' ) ;
146155 match ( stdout , / 2 t o t a l p a c k a g e s s c a n n e d / , '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 / N o c o m p o n e n t s f o u n d i n s c a n . R e p o r t n o t g e n e r a t e d ./ ,
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