test(api-keys): add unit tests for tenant API key validation
Introduce unit tests for the tenant API key validation logic, ensuring that scoped keys require capabilities, while full-access keys are validated without them. The tests cover various scenarios, reinforcing the expected behavior of the API key validation function.
This commit is contained in:
@@ -8,6 +8,9 @@ CREATE TABLE IF NOT EXISTS tenant_api_keys (
|
||||
api_key TEXT NOT NULL DEFAULT '',
|
||||
full_access BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
knowledge_base_ids JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
-- Bounded per-key grants for non-full-access keys. KB allow-list still
|
||||
-- constrains which knowledge bases a scoped key may touch.
|
||||
capabilities JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
last_used_at TIMESTAMP,
|
||||
expires_at TIMESTAMP,
|
||||
revoked_at TIMESTAMP,
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE tenant_api_keys DROP COLUMN IF EXISTS capabilities;
|
||||
@@ -1,9 +0,0 @@
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000066] Adding tenant_api_keys.capabilities...'; END $$;
|
||||
|
||||
-- Additive per-key grants for non-full-access keys. Capabilities let a scoped
|
||||
-- key call a bounded route family, while knowledge_base_ids still constrains
|
||||
-- the KBs the key can touch where a route targets knowledge-base data.
|
||||
ALTER TABLE tenant_api_keys
|
||||
ADD COLUMN IF NOT EXISTS capabilities JSONB NOT NULL DEFAULT '[]'::jsonb;
|
||||
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000066] tenant_api_keys.capabilities ready'; END $$;
|
||||
Reference in New Issue
Block a user