Arshil-Khan opened a new pull request, #1760:
URL: https://github.com/apache/casbin/pull/1760
### What happened
In `GetNamedPermissionsForUser(ptype string, user string, domain
...string)`, the subject field index was looked up against hardcoded `"p"`
instead of the passed `ptype`:
```go
subIndex, err := e.GetFieldIndex("p", constant.SubjectIndex)
```
When a named policy definition has a column order differing from `p` (e.g.
`p2 = dom, sub, obj, act`), `subIndex` was resolved based on `p` rather than
`ptype`. Consequently:
1. `GetNamedPermissionsForUser("p2", "alice")` wrote the user into the
domain column (index 0), returning `[]`.
2. `GetNamedPermissionsForUser("p2", "alice", "tenant1")` wrote `alice` to
index 0 and subsequently overwrote index 0 with `tenant1`. The subject column
remained empty (wildcard), returning permissions for all users in that domain.
### Fix
- Pass `ptype` instead of `"p"` into `e.GetFieldIndex(ptype,
constant.SubjectIndex)` in `GetNamedPermissionsForUser`.
- Added unit test `TestNamedPermissionsForUserWithDifferentColumnOrder` in
`rbac_api_test.go` verifying both no-domain and with-domain queries when the
named policy has a custom column order.
Fixes #1759
### Verification
- `make test` (`go test -race -v ./...`) passes.
- `golangci-lint run` passes with 0 issues.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]