forked from forgejo/forgejo
Fix token endpoints ignore specified account (#27080)
Fix #26234 close #26323 close #27040 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
8531ca0837
commit
f93ee5937b
4 changed files with 52 additions and 4 deletions
|
@ -40,6 +40,29 @@ func TestAPIDeleteMissingToken(t *testing.T) {
|
|||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
// TestAPIGetTokensPermission ensures that only the admin can get tokens from other users
|
||||
func TestAPIGetTokensPermission(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// admin can get tokens for other users
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
req := NewRequestf(t, "GET", "/api/v1/users/user2/tokens")
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// non-admin can get tokens for himself
|
||||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
req = NewRequestf(t, "GET", "/api/v1/users/user2/tokens")
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// non-admin can't get tokens for other users
|
||||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
||||
req = NewRequestf(t, "GET", "/api/v1/users/user2/tokens")
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusForbidden)
|
||||
}
|
||||
|
||||
type permission struct {
|
||||
category auth_model.AccessTokenScopeCategory
|
||||
level auth_model.AccessTokenScopeLevel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue