Hub client: accept the public key pasted on one line; clearer error for a bad key
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -101,6 +101,27 @@ describe('read-only mode', () => {
|
||||
])('%s %s keeps working', (m, p) => expect(isBlocked(m, p)).toBe(false));
|
||||
});
|
||||
|
||||
describe('pasting the Hub public key', () => {
|
||||
const { normalisePem } = require('../src/hub/publicKey');
|
||||
const pem = publicKey.export({ type: 'spki', format: 'pem' }).toString();
|
||||
const base64 = pem.replace(/-----(BEGIN|END) PUBLIC KEY-----|\s/g, '');
|
||||
|
||||
test.each([
|
||||
['proper PEM', pem],
|
||||
['with \\n', pem.replace(/\n/g, '\\n')],
|
||||
['all on one line', `-----BEGIN PUBLIC KEY-----${base64}-----END PUBLIC KEY-----`],
|
||||
['just the base64', base64],
|
||||
])('%s works', (label, input) => {
|
||||
expect(() => crypto.createPublicKey(normalisePem(input))).not.toThrow();
|
||||
expect(verifyToken(sign(base), crypto.createPublicKey(normalisePem(input)))).not.toBeNull();
|
||||
});
|
||||
|
||||
test('empty means none', () => {
|
||||
expect(normalisePem('')).toBeNull();
|
||||
expect(normalisePem(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
test('version comparison for "update available"', () => {
|
||||
expect(compareVersions('1.41.0', '1.41.1')).toBeLessThan(0);
|
||||
expect(compareVersions('1.41.0', '1.41.0')).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user