diff options
author | CaiCandong <50507092+CaiCandong@users.noreply.github.com> | 2023-09-18 08:21:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 00:21:15 +0000 |
commit | f93ee5937bcb43aaf1e3b527d852487e80ae570b (patch) | |
tree | 34793295a78ae03e2f763df5bfb5011547b25757 /tests/integration/api_token_test.go | |
parent | 8531ca08372dd4a4739564dec17766fffe34a385 (diff) | |
download | gitea-f93ee5937bcb43aaf1e3b527d852487e80ae570b.tar.gz gitea-f93ee5937bcb43aaf1e3b527d852487e80ae570b.zip |
Fix token endpoints ignore specified account (#27080)
Fix #26234
close #26323
close #27040
---------
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'tests/integration/api_token_test.go')
-rw-r--r-- | tests/integration/api_token_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/integration/api_token_test.go b/tests/integration/api_token_test.go index 1c63d07f22..a713922982 100644 --- a/tests/integration/api_token_test.go +++ b/tests/integration/api_token_test.go @@ -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 |