-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Expand file tree
/
Copy pathcredential-service.windows.test.ts
More file actions
68 lines (60 loc) · 2.1 KB
/
Copy pathcredential-service.windows.test.ts
File metadata and controls
68 lines (60 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { mkdtemp, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import {
ByokCredentialService,
createPlatformByokSecretBackend,
} from '../../src/byok/credential-service.js';
describe.runIf(process.platform === 'win32')('Windows DPAPI BYOK credential smoke', () => {
const roots: string[] = [];
afterEach(async () => {
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
});
it('creates, resolves, and deletes a profile without writing its secret as plaintext', async () => {
const dataDir = await mkdtemp(path.join(tmpdir(), 'od-byok-windows-dpapi-'));
roots.push(dataDir);
const backend = createPlatformByokSecretBackend('win32', dataDir);
const service = new ByokCredentialService({ dataDir, backend });
const apiKey = 'windows-dpapi-smoke-secret';
try {
await expect(service.status()).resolves.toEqual({
available: true,
backend: 'windows-dpapi',
});
const profile = await service.upsert({
id: 'byok-windows-dpapi-smoke',
label: 'Windows DPAPI smoke',
protocol: 'openai',
baseUrl: 'https://api.openai.com/v1',
model: 'gpt-5.4',
apiKey,
});
expect(profile).toMatchObject({
id: 'byok-windows-dpapi-smoke',
configured: true,
keyTail: 'cret',
});
expect(await service.resolve(profile.id)).toMatchObject({
apiKey,
provider: { apiKey },
});
expect(
await readFile(
path.join(dataDir, 'byok', 'profiles.json'),
'utf8',
),
).not.toContain(apiKey);
const encrypted = await readFile(
path.join(dataDir, 'byok', 'secrets', `${profile.id}.bin`),
);
expect(encrypted.includes(Buffer.from(apiKey, 'utf8'))).toBe(false);
await expect(service.delete(profile.id)).resolves.toBe(true);
await expect(service.resolve(profile.id)).resolves.toBeNull();
} finally {
await service.close();
}
});
});