test(api-keys): add tests for tenant API key management path rejection

Introduce tests to validate that tenant API keys are correctly restricted from accessing management paths. Implemented new test cases for both allowed and forbidden paths, ensuring proper enforcement of API key scopes. Additionally, refactored existing tests to utilize the new rejection logic.
This commit is contained in:
wizardchen
2026-07-06 13:39:02 +08:00
committed by lyingbug
parent 9a76a24ce6
commit fedb6c3f7e
8 changed files with 77 additions and 174 deletions
+1 -1
View File
@@ -260,7 +260,7 @@ func authenticateAPIKeyRequest(
if c.IsAborted() {
return false
}
if err := authorizeTenantAPIKeyAccess(c.Request.Context(), c.Request.Method, c.Request.URL.Path); err != nil {
if err := rejectTenantAPIKeyManagementPath(c.Request.Context(), c.Request.URL.Path); err != nil {
c.JSON(http.StatusForbidden, gin.H{"error": "Forbidden: API key scope does not allow this operation"})
c.Abort()
return false