diff --git a/frontend/src/__tests__/api-apikeys.test.ts b/frontend/src/__tests__/api-apikeys.test.ts index ef38a9a89..a129f4ace 100644 --- a/frontend/src/__tests__/api-apikeys.test.ts +++ b/frontend/src/__tests__/api-apikeys.test.ts @@ -110,13 +110,14 @@ describe('API Keys API Module', () => { json: () => Promise.resolve(mockResponse) }); - const result = await createApiKey({ name: 'New Key' }); + const request = { name: 'New Key', password: 'cGFzc3dvcmQ=', expires_at: '2025-12-31T00:00:00Z' }; + const result = await createApiKey(request); expect(fetchMock).toHaveBeenCalledWith( '/api/api-keys', expect.objectContaining({ method: 'POST', - body: JSON.stringify({ name: 'New Key' }), + body: JSON.stringify(request), headers: expect.objectContaining({ 'Content-Type': 'application/json', 'x-amz-content-sha256': expect.stringMatching(/^[a-f0-9]{64}$/) @@ -140,6 +141,7 @@ describe('API Keys API Module', () => { const request = { name: 'Admin Key', + password: 'cGFzc3dvcmQ=', permissions: [{ action: 'read', resource: '*' }], expires_at: '2025-12-31T00:00:00Z' }; @@ -163,7 +165,7 @@ describe('API Keys API Module', () => { json: () => Promise.resolve({ error: 'Invalid request' }) }); - await expect(createApiKey({ name: '' })).rejects.toThrow('Invalid request'); + await expect(createApiKey({ name: '', password: '', expires_at: '2025-12-31T00:00:00Z' })).rejects.toThrow('Invalid request'); }); }); diff --git a/frontend/src/__tests__/apikeys.test.ts b/frontend/src/__tests__/apikeys.test.ts index 96d853402..a349278c1 100644 --- a/frontend/src/__tests__/apikeys.test.ts +++ b/frontend/src/__tests__/apikeys.test.ts @@ -20,7 +20,11 @@ jest.mock('../api', () => ({ getApiKeysUsageStats: jest.fn(), createApiKey: jest.fn(), revokeApiKey: jest.fn(), - deleteApiKey: jest.fn() + deleteApiKey: jest.fn(), + // Real implementation (not mocked): createApiKey encodes the password + // field with this before building the request, so tests need the real + // encoding to assert on the resulting request shape. + base64Encode: (str: string) => Buffer.from(str, 'binary').toString('base64') })); // confirmDialog (introduced in P2) is used for revoke/delete in place of @@ -43,10 +47,8 @@ describe('API Keys Module', () => {
- + + + Confirm your password to create this API key
-