import { getToken } from './token'; import { getCredentialsFromProcess } from '../getCredentialsFromProcess'; import { getTokenFromKeystore } from '../getTokenFromKeystore'; jest.mock('../getCredentialsFromProcess'); jest.mock('../getTokenFromKeystore'); jest.mock('../log'); // AC-1.2: a credential_process that emits a `password` must not be honored — // only `refresh_token` is consumed. Basic auth is removed, so a password-only // credential_process yields no token. describe('getToken credential_process handling (AC-1.2)', () => { const originalEnv = process.env; beforeEach(() => { jest.resetAllMocks(); process.env = { ...originalEnv }; delete process.env.ALKS_REFRESH_TOKEN; (getTokenFromKeystore as jest.Mock).mockResolvedValue(undefined); }); afterEach(() => { process.env = originalEnv; }); it('consumes refresh_token from credential_process and ignores any password field', async () => { (getCredentialsFromProcess as jest.Mock).mockResolvedValue({ password: 'network-secret', refresh_token: 'rt-123', }); const token = await getToken(); expect(token).toBe('rt-123'); }); it('does not honor a credential_process that emits only a password', async () => { (getCredentialsFromProcess as jest.Mock).mockResolvedValue({ password: 'network-secret', }); const token = await getToken(); // No refresh_token and nothing in the keystore → no token; the password is // never treated as a credential. expect(token).toBeUndefined(); }); });