Skip to content

Commit 0601985

Browse files
chore: remove auth and user-setup feature flags (always-on) (#471)
1 parent 21047b5 commit 0601985

11 files changed

Lines changed: 47 additions & 41 deletions

File tree

.envrc.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export GRAPHQL_PATH='/graphql';
66
export EOL_REPORT_URL='https://eol-report-card.apps.herodevs.com/reports';
77
export ANALYTICS_URL='https://eol-api.herodevs.com/track';
88

9-
# Authentication (set to 'true' to enable auth requirement for scans)
10-
export ENABLE_AUTH='false';
119
export OAUTH_CONNECT_URL='';
1210
export OAUTH_CLIENT_ID='';
1311

e2e/setup/mock-auth-hooks.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* ESM loader hooks that replace auth.svc.ts with a mock during E2E tests.
3+
* This avoids hitting the system keyring (unavailable in CI).
4+
*/
5+
export async function load(url, context, nextLoad) {
6+
if (url.endsWith('/service/auth.svc.ts') || url.endsWith('/service/auth.svc.js')) {
7+
return {
8+
format: 'module',
9+
shortCircuit: true,
10+
source: `
11+
export class AuthError extends Error {
12+
constructor(message, code) {
13+
super(message);
14+
this.name = 'AuthError';
15+
this.code = code;
16+
}
17+
}
18+
export function persistTokenResponse() { return Promise.resolve(); }
19+
export function getAccessToken() { return Promise.resolve('test-token'); }
20+
export function requireAccessToken() { return Promise.resolve('test-token'); }
21+
export function logoutLocally() { return Promise.resolve(); }
22+
export function requireAccessTokenForScan() { return Promise.resolve('test-token'); }
23+
`,
24+
};
25+
}
26+
27+
return nextLoad(url, context);
28+
}

e2e/setup/register-mock-auth.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { register } from 'node:module';
2+
3+
register('./mock-auth-hooks.mjs', import.meta.url);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"readme": "npm run ci:fix && npm run build && oclif readme && sed -i '' 's|/plugin-help/blob/v|/plugin-help/blob/|; s|/plugin-update/blob/v|/plugin-update/blob/|' README.md",
3232
"test": "vitest run",
3333
"test:watch": "vitest watch",
34-
"test:e2e": "globstar -- node --import tsx --test \"e2e/**/*.test.ts\"",
34+
"test:e2e": "globstar -- node --import tsx --import ./e2e/setup/register-mock-auth.mjs --test \"e2e/**/*.test.ts\"",
3535
"typecheck": "tsc --noEmit",
3636
"version": "oclif manifest",
3737
"postversion": "node scripts/update-install-script-version.js && git add README.md"

src/api/nes.client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ const createAuthorizedFetch =
2222
async (input, init) => {
2323
const headers = new Headers(init?.headers);
2424

25-
if (config.enableAuth) {
26-
const token = await tokenProvider();
27-
headers.set('Authorization', `Bearer ${token}`);
28-
}
25+
const token = await tokenProvider();
26+
headers.set('Authorization', `Bearer ${token}`);
2927

3028
return fetch(input, { ...init, headers });
3129
};

src/commands/auth/login.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { createInterface } from 'node:readline';
44
import { URL } from 'node:url';
55
import { Command } from '@oclif/core';
66
import { ensureUserSetup } from '../../api/user-setup.client.ts';
7-
import { config } from '../../config/constants.ts';
87
import { persistTokenResponse } from '../../service/auth.svc.ts';
98
import { getClientId, getRealmUrl } from '../../service/auth-config.svc.ts';
109
import { getErrorMessage } from '../../service/log.svc.ts';
@@ -48,9 +47,6 @@ export default class AuthLogin extends Command {
4847
return;
4948
}
5049

51-
if (!config.enableUserSetup) {
52-
return;
53-
}
5450
try {
5551
await ensureUserSetup();
5652
} catch (error) {

src/commands/scan/eol.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ export default class ScanEol extends Command {
8888
public async run(): Promise<EolReport | undefined> {
8989
const { flags } = await this.parse(ScanEol);
9090

91-
if (config.enableAuth) {
92-
await requireAccessTokenForScan();
93-
}
91+
await requireAccessTokenForScan();
9492

9593
track('CLI EOL Scan Started', (context) => ({
9694
command: context.command,

src/config/constants.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ export const GIT_OUTPUT_FORMAT = `"${['%h', '%an', '%ad'].join('|')}"`;
1010
export const DEFAULT_DATE_FORMAT = 'yyyy-MM-dd';
1111
export const DEFAULT_DATE_COMMIT_FORMAT = 'MM/dd/yyyy, h:mm:ss a';
1212
export const DEFAULT_DATE_COMMIT_MONTH_FORMAT = 'MMMM yyyy';
13-
export const ENABLE_AUTH = false;
14-
export const ENABLE_USER_SETUP = false;
15-
16-
const toBoolean = (value: string | undefined): boolean | undefined => {
17-
if (value === 'true') return true;
18-
if (value === 'false') return false;
19-
return undefined;
20-
};
21-
2213
// Trackers - Constants
2314
export const DEFAULT_TRACKER_RUN_DATA_FILE = 'data.json';
2415
export const TRACKER_GIT_OUTPUT_FORMAT = `"${['%H', '%an', '%ad'].join('|')}"`;
@@ -40,8 +31,6 @@ export const config = {
4031
graphqlHost: process.env.GRAPHQL_HOST || GRAPHQL_HOST,
4132
graphqlPath: process.env.GRAPHQL_PATH || GRAPHQL_PATH,
4233
analyticsUrl: process.env.ANALYTICS_URL || ANALYTICS_URL,
43-
enableAuth: toBoolean(process.env.ENABLE_AUTH) ?? ENABLE_AUTH,
44-
enableUserSetup: toBoolean(process.env.ENABLE_USER_SETUP) ?? ENABLE_USER_SETUP,
4534
concurrentPageRequests,
4635
pageSize,
4736
};

test/api/nes.client.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { CreateEolReportInput } from '@herodevs/eol-shared';
2+
import { vi } from 'vitest';
23
import { submitScan } from '../../src/api/nes.client.ts';
34
import { SCAN_ORIGIN_AUTOMATED, SCAN_ORIGIN_CLI } from '../../src/config/constants.ts';
45
import { FetchMock } from '../utils/mocks/fetch.mock.ts';
56

7+
vi.mock('../../src/service/auth.svc.ts', () => ({
8+
requireAccessTokenForScan: vi.fn().mockResolvedValue('test-token'),
9+
}));
10+
611
function getGraphQLVariables(fetchMock: FetchMock, callIndex = 0): Record<string, unknown> {
712
const calls = fetchMock.getCalls();
813
const init = calls[callIndex]?.init;

test/api/user-setup.client.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { vi } from 'vitest';
12
import { ApiError } from '../../src/api/errors.ts';
23
import { completeUserSetup, ensureUserSetup, getUserSetupStatus } from '../../src/api/user-setup.client.ts';
34
import { FetchMock } from '../utils/mocks/fetch.mock.ts';
45

6+
vi.mock('../../src/service/auth.svc.ts', () => ({
7+
requireAccessTokenForScan: vi.fn().mockResolvedValue('test-token'),
8+
requireAccessToken: vi.fn().mockResolvedValue('test-token'),
9+
}));
10+
511
describe('user-setup.client', () => {
612
let fetchMock: FetchMock;
713

0 commit comments

Comments
 (0)