mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 22:16:38 +00:00
- add registry coverage for generated ids, reauth, and ambiguous prefixes - add CLI and dashboard validation tests for optional nickname handling - add manual callback coverage for persisted social OAuth nicknames
88 lines
3.4 KiB
TypeScript
88 lines
3.4 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import {
|
|
getStartAuthFailureMessage,
|
|
getStartAuthNicknameError,
|
|
getStartUrlUnsupportedReason,
|
|
} from '../../../src/web-server/routes/cliproxy-auth-routes';
|
|
|
|
describe('cliproxy-auth-routes start-url guard', () => {
|
|
it('rejects device code providers', () => {
|
|
expect(getStartUrlUnsupportedReason('kiro')).toContain(
|
|
"Kiro method 'aws' uses Device Code flow"
|
|
);
|
|
expect(getStartUrlUnsupportedReason('ghcp')).toContain("Provider 'ghcp' uses Device Code flow");
|
|
expect(getStartUrlUnsupportedReason('qwen')).toContain("Provider 'qwen' uses Device Code flow");
|
|
});
|
|
|
|
it('allows Kiro social methods on start-url', () => {
|
|
expect(getStartUrlUnsupportedReason('kiro', { kiroMethod: 'google' })).toBeNull();
|
|
expect(getStartUrlUnsupportedReason('kiro', { kiroMethod: 'github' })).toBeNull();
|
|
});
|
|
|
|
it('rejects Kiro aws-authcode method on start-url', () => {
|
|
expect(getStartUrlUnsupportedReason('kiro', { kiroMethod: 'aws-authcode' })).toContain(
|
|
"Kiro method 'aws-authcode' uses CLI auth flow"
|
|
);
|
|
});
|
|
|
|
it('allows authorization code providers', () => {
|
|
expect(getStartUrlUnsupportedReason('gemini')).toBeNull();
|
|
expect(getStartUrlUnsupportedReason('codex')).toBeNull();
|
|
expect(getStartUrlUnsupportedReason('claude')).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('cliproxy-auth-routes start failure messaging', () => {
|
|
it('returns ghcp-specific guidance for Copilot verification failures', () => {
|
|
expect(getStartAuthFailureMessage('ghcp')).toContain(
|
|
'GitHub Copilot verification did not complete'
|
|
);
|
|
});
|
|
|
|
it('keeps generic failure text for other providers', () => {
|
|
expect(getStartAuthFailureMessage('gemini')).toBe('Authentication failed or was cancelled');
|
|
expect(getStartAuthFailureMessage('kiro')).toBe('Authentication failed or was cancelled');
|
|
});
|
|
});
|
|
|
|
describe('cliproxy-auth-routes nickname validation', () => {
|
|
it('allows Kiro and GHCP start requests without a nickname', () => {
|
|
expect(getStartAuthNicknameError('kiro', undefined, [])).toBeNull();
|
|
expect(getStartAuthNicknameError('ghcp', undefined, [])).toBeNull();
|
|
});
|
|
|
|
it('rejects invalid supplied nicknames for no-email providers', () => {
|
|
expect(getStartAuthNicknameError('kiro', 'bad nickname', [])).toEqual({
|
|
error: 'Nickname cannot contain whitespace',
|
|
code: 'INVALID_NICKNAME',
|
|
});
|
|
});
|
|
|
|
it('rejects nicknames that collide with an existing account id or nickname', () => {
|
|
const existingAccounts = [
|
|
{ id: 'github-ABC123', nickname: 'work' },
|
|
{ id: 'ghcp-2', nickname: 'personal' },
|
|
];
|
|
|
|
expect(getStartAuthNicknameError('ghcp', 'github-ABC123', existingAccounts)).toEqual({
|
|
error: 'Nickname "github-ABC123" is already in use. Choose a different one.',
|
|
code: 'NICKNAME_EXISTS',
|
|
});
|
|
|
|
expect(getStartAuthNicknameError('ghcp', 'work', existingAccounts)).toEqual({
|
|
error: 'Nickname "work" is already in use. Choose a different one.',
|
|
code: 'NICKNAME_EXISTS',
|
|
});
|
|
});
|
|
|
|
it('allows reauth when the nickname already belongs to the same account', () => {
|
|
const existingAccounts = [
|
|
{ id: 'github-ABC123', nickname: 'work' },
|
|
{ id: 'ghcp-2', nickname: 'personal' },
|
|
];
|
|
|
|
expect(getStartAuthNicknameError('kiro', 'work', existingAccounts, 'github-ABC123')).toBeNull();
|
|
expect(getStartAuthNicknameError('kiro', 'github-ABC123', existingAccounts, 'github-ABC123')).toBeNull();
|
|
});
|
|
});
|