Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ function parseConfigSetValue<K extends ConfigSetKey>(key: K, rawValue: string):
return value as ConfigSetValueMap[K];
}

function updateConfigField<K extends ConfigSetKey>(
config: Config,
key: K,
value: ConfigSetValueMap[K],
): Config {
function updateConfigField<K extends ConfigSetKey>(config: Config, key: K, value: ConfigSetValueMap[K]): Config {
return {
...config,
[key]: value,
Expand All @@ -100,7 +96,7 @@ export function maskApiKey(apiKey: string | undefined): string {
return 'not stored in config';
}

const visibleLength = Math.min(4, Math.max(2, apiKey.length));
const visibleLength = Math.min(4, Math.floor(apiKey.length / 2));
return `${apiKey.slice(0, visibleLength)}••••`;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/config-command.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ test('maskApiKey returns fallback message for empty string', () => {
});

test('maskApiKey masks a 1-character key', () => {
assert.equal(maskApiKey('a'), 'a••••');
assert.equal(maskApiKey('a'), '••••');
});

test('maskApiKey masks a 2-character key', () => {
assert.equal(maskApiKey('ab'), 'ab••••');
assert.equal(maskApiKey('ab'), 'a••••');
});

test('maskApiKey masks a 3-character key', () => {
assert.equal(maskApiKey('abc'), 'abc••••');
assert.equal(maskApiKey('abc'), 'a••••');
});

test('maskApiKey masks a 4-character key', () => {
assert.equal(maskApiKey('abcd'), 'abcd••••');
assert.equal(maskApiKey('abcd'), 'ab••••');
});

test('maskApiKey masks a long key', () => {
Expand Down