feat: configure key model access after creation
This commit is contained in:
1 parent
6de29ebd6d
commit
7f35960ba6
8 files changed
+175
-23
No files matched your search
@@ -38,10 +38,22 @@ test('platform key is returned once, hashed at rest, and can be revoked', async
|
||||
|
||||
test('key model allowlist is enforced by the service', async () => {
|
||||
const catalog = createCatalog()
|
||||
const created = await catalog.createApiKey('user-1', { modelIds: ['model-mock-text'] })
|
||||
const created = await catalog.createApiKey('user-1', {})
|
||||
const unconfigured = await catalog.authenticateApiKey(created.key)
|
||||
|
||||
assert.equal(created.apiKey.modelIds[0], 'model-mock-text')
|
||||
assert.deepEqual(created.apiKey.modelIds, [])
|
||||
assert.equal(created.apiKey.scopes.includes('invoke'), true)
|
||||
assert.equal(catalog.canInvoke(unconfigured!, 'model-mock-text'), false)
|
||||
|
||||
const updated = await catalog.updateApiKeyModels('user-1', created.apiKey.id, ['model-mock-3d', 'model-mock-3d'])
|
||||
const configured = await catalog.authenticateApiKey(created.key)
|
||||
assert.deepEqual(updated.modelIds, ['model-mock-3d'])
|
||||
assert.equal(catalog.canInvoke(configured!, 'model-mock-3d'), true)
|
||||
assert.equal(catalog.canInvoke(configured!, 'model-mock-text'), false)
|
||||
await assert.rejects(
|
||||
catalog.updateApiKeyModels('user-2', created.apiKey.id, ['model-mock-text']),
|
||||
(error: unknown) => error instanceof Error && error.message === 'Key 不存在、已停用或无权修改',
|
||||
)
|
||||
})
|
||||
|
||||
test('personal and project keys can coexist with project ownership checks', async () => {
|
||||
|
||||
Reference in new issue
Block a user