added another test
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user