added another test

This commit is contained in:
2026-01-27 09:20:05 +08:00
parent a36f652a1c
commit 4c190a2fff
+35
View File
@@ -340,3 +340,38 @@ func TestAuthorizeHandlerSpecialCharactersInFields(t *testing.T) {
}) })
} }
} }
func TestAuthorizeHandlerWithResourceData(t *testing.T) {
// Test that ResourceData is properly passed through to authorization
claims := &models.Claims{
UserID: "user123",
RoleID: "admin",
}
payload := models.AuthorizationContext{
UserID: "user123",
Resource: "personnel",
Action: "assign_role",
ResourceData: map[string]string{
"region": "01",
},
}
body, _ := json.Marshal(payload)
req := httptest.NewRequest("POST", AuthCheckEndpoint, bytes.NewBuffer(body))
ctx := context.WithValue(req.Context(), models.ContextKey("claims"), claims)
req = req.WithContext(ctx)
w := httptest.NewRecorder()
defer func() {
if r := recover(); r != nil {
t.Logf("Handler panicked (expected without DB): %v", r)
}
}()
AuthorizeHandler(w, req)
// ResourceData should not cause any parsing errors
if w.Code == http.StatusBadRequest {
t.Errorf("Handler returned bad request with valid ResourceData")
}
}