合并 `test` 的 v1.10.0 提交到 `main`。 **包含提交** - `28c9433` feat: 添加自定义命令片段库 - `9aa2e80` release: 发布 v1.10.0 自定义命令片段库版本 **关联** - Related to #90 > 本 PR 仅关联 #90,不自动关闭该 Issue。 **验证** - `pnpm run typecheck` 0 错 - `pnpm test` 47/47 603/603 通过 - `pnpm run build:frontend` 成功 --------- Co-authored-by: TanXin <tanxin@example.com>
99 lines
2.8 KiB
TypeScript
99 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
describe('SSH Key Integration', () => {
|
|
describe('Key format validation', () => {
|
|
it('should validate OpenSSH format magic bytes', () => {
|
|
const magic = 'openssh-key-v1\0';
|
|
const magicBytes = new TextEncoder().encode(magic);
|
|
|
|
expect(magicBytes.length).toBe(15);
|
|
expect(magicBytes[14]).toBe(0);
|
|
});
|
|
|
|
it('should parse key type from OpenSSH format', () => {
|
|
const keyType = 'ssh-ed25519';
|
|
const keyTypeBytes = new TextEncoder().encode(keyType);
|
|
|
|
expect(keyTypeBytes.length).toBeGreaterThan(0);
|
|
expect(keyType).toMatch(/^ssh-(ed25519|rsa|ecdsa-sha2-nistp\d+)$/);
|
|
});
|
|
});
|
|
|
|
describe('DER encoding', () => {
|
|
it('should encode DER INTEGER correctly', () => {
|
|
const value = 42;
|
|
const encoded = new Uint8Array([0x02, 0x01, value]);
|
|
|
|
expect(encoded[0]).toBe(0x02);
|
|
expect(encoded[1]).toBe(0x01);
|
|
expect(encoded[2]).toBe(42);
|
|
});
|
|
|
|
it('should encode DER SEQUENCE correctly', () => {
|
|
const contents = new Uint8Array([0x01, 0x02, 0x03]);
|
|
const encoded = new Uint8Array([0x30, contents.length, ...contents]);
|
|
|
|
expect(encoded[0]).toBe(0x30);
|
|
expect(encoded[1]).toBe(3);
|
|
});
|
|
});
|
|
|
|
describe('Key type detection', () => {
|
|
it('should detect all supported key types', () => {
|
|
const keyTypes = [
|
|
'ssh-ed25519',
|
|
'ssh-rsa',
|
|
'ecdsa-sha2-nistp256',
|
|
'ecdsa-sha2-nistp384',
|
|
'ecdsa-sha2-nistp521',
|
|
];
|
|
|
|
const validPattern = /^(ssh-(ed25519|rsa)|ecdsa-sha2-nistp\d+)$/;
|
|
|
|
for (const keyType of keyTypes) {
|
|
expect(keyType).toMatch(validPattern);
|
|
}
|
|
});
|
|
|
|
it('should identify supported key types', () => {
|
|
const supportedTypes = [
|
|
'ssh-ed25519',
|
|
'ssh-rsa',
|
|
'ecdsa-sha2-nistp256',
|
|
'ecdsa-sha2-nistp384',
|
|
'ecdsa-sha2-nistp521',
|
|
];
|
|
|
|
const unsupportedTypes = ['ssh-dsa', 'ssh-unknown'];
|
|
|
|
for (const type of supportedTypes) {
|
|
const isSupported =
|
|
type === 'ssh-ed25519' || type === 'ssh-rsa' || type.startsWith('ecdsa-sha2-nistp');
|
|
expect(isSupported).toBe(true);
|
|
}
|
|
|
|
for (const type of unsupportedTypes) {
|
|
const isSupported =
|
|
type === 'ssh-ed25519' || type === 'ssh-rsa' || type.startsWith('ecdsa-sha2-nistp');
|
|
expect(isSupported).toBe(false);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Error handling', () => {
|
|
it('should handle invalid magic bytes', () => {
|
|
const invalidMagic = 'invalid-format\0';
|
|
const magic = 'openssh-key-v1\0';
|
|
|
|
expect(invalidMagic).not.toBe(magic);
|
|
});
|
|
|
|
it('should handle encrypted keys', () => {
|
|
const cipherName = 'aes256-ctr';
|
|
const unencrypted = 'none';
|
|
|
|
expect(cipherName).not.toBe(unencrypted);
|
|
});
|
|
});
|
|
});
|