feat: EC2 UI polished + storage persisting

This commit is contained in:
Zakaria
2026-09-25 18:18:33 -04:00
parent 1b129e9dcf
commit 093afb9b2b
40 changed files with 2586 additions and 102 deletions
+42 -1
View File
@@ -12,6 +12,7 @@ import type {
Ec2IpPermission,
Ec2KeyPair,
Ec2KeyPairMaterial,
Ec2KeyPairType,
Ec2NatGateway,
Ec2RouteTable,
Ec2SecurityGroup,
@@ -75,7 +76,7 @@ const fakeService = {
getConsoleOutput: async (instanceId: string): Promise<Ec2ConsoleOutput> => ({instanceId, output: 'boot log'}),
listAmis: async (): Promise<Ec2Image[]> => [],
listKeyPairs: async (): Promise<Ec2KeyPair[]> => [],
createKeyPair: async (name: string): Promise<Ec2KeyPairMaterial> => ({keyPairId: 'key-0a1b2c3d4e5f6a7b', keyName: name, keyMaterial: '---PEM---'}),
createKeyPair: async (name: string, _keyType: Ec2KeyPairType = 'rsa'): Promise<Ec2KeyPairMaterial> => ({keyPairId: 'key-0a1b2c3d4e5f6a7b', keyName: name, keyMaterial: '---PEM---'}),
deleteKeyPair: async () => {},
listSecurityGroups: async (): Promise<Ec2SecurityGroup[]> => [],
createSecurityGroup: async () => ({groupId: 'sg-0a1b2c3d4e5f6a7b'}),
@@ -257,6 +258,46 @@ describe('POST /key-pairs', () => {
expect(body.keyName).toBe('my-key')
expect(body.keyMaterial).toBe('---PEM---')
})
test('accepts ed25519 key type', async () => {
let receivedKeyType: Ec2KeyPairType | undefined
const router = createEc2Router({...fakeService, createKeyPair: async (name: string, keyType: Ec2KeyPairType) => {
receivedKeyType = keyType
return {keyPairId: 'key-0a1b2c3d4e5f6a7b', keyName: name, keyMaterial: '---PEM---'}
}})
const res = await router.request('/key-pairs', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({name: 'my-ed25519-key', keyType: 'ed25519'}),
})
expect(res.status).toBe(200)
expect(receivedKeyType).toBe('ed25519')
})
test('defaults key type to rsa', async () => {
let receivedKeyType: Ec2KeyPairType | undefined
const router = createEc2Router({...fakeService, createKeyPair: async (name: string, keyType: Ec2KeyPairType) => {
receivedKeyType = keyType
return {keyPairId: 'key-0a1b2c3d4e5f6a7b', keyName: name, keyMaterial: '---PEM---'}
}})
const res = await router.request('/key-pairs', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({name: 'my-rsa-key'}),
})
expect(res.status).toBe(200)
expect(receivedKeyType).toBe('rsa')
})
test('rejects unsupported key types', async () => {
const res = await app.request('/key-pairs', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({name: 'my-key', keyType: 'dsa'}),
})
expect(res.status).toBe(400)
expect((await res.json() as {error: string}).error).toBe('keyType must be rsa or ed25519')
})
})
describe('GET /internet-gateways', () => {