fix(api-keys): enforce scope from request context after attach

Use c.Request.Context() in authenticateAPIKeyRequest so scoped keys are
actually restricted, update dto tests for removed tenant.api_key, and add
a regression test for the attach-context contract.
This commit is contained in:
wizardchen
2026-07-06 10:58:22 +08:00
committed by lyingbug
parent 94d18ea15a
commit c65ffa3d9c
4 changed files with 44 additions and 8 deletions
+5 -2
View File
@@ -26,7 +26,7 @@ func TestAuthLoginResponse_ViewerOmitsActiveTenantSecrets(t *testing.T) {
assert.NotContains(t, s, "parser-secret-123")
}
func TestAuthLoginResponse_OwnerGetsAPIKey(t *testing.T) {
func TestAuthLoginResponse_OwnerOmitsLegacyTenantAPIKey(t *testing.T) {
tenant := sampleSecretTenant()
resp := NewAuthLoginResponse(&types.LoginResponse{
Success: true,
@@ -38,7 +38,10 @@ func TestAuthLoginResponse_OwnerGetsAPIKey(t *testing.T) {
})
body, err := json.Marshal(resp)
require.NoError(t, err)
assert.Contains(t, string(body), "tenant-api-key-123")
s := string(body)
assert.NotContains(t, s, `"api_key"`)
assert.NotContains(t, s, "legacy-search-secret-999")
assert.Contains(t, s, "web_search_config")
}
func TestAuthOIDCCallbackResponse_ViewerOmitsTenantSecrets(t *testing.T) {