diff options
Diffstat (limited to 'integrations/api_admin_test.go')
-rw-r--r-- | integrations/api_admin_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/integrations/api_admin_test.go b/integrations/api_admin_test.go index 37e5fd199a..ab878dd6a5 100644 --- a/integrations/api_admin_test.go +++ b/integrations/api_admin_test.go @@ -9,6 +9,8 @@ import ( "net/http" "testing" + "github.com/stretchr/testify/assert" + "code.gitea.io/gitea/models" api "code.gitea.io/sdk/gitea" ) @@ -71,3 +73,30 @@ func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) { adminUsername, newPublicKey.ID) session.MakeRequest(t, req, http.StatusForbidden) } + +func TestAPISudoUser(t *testing.T) { + prepareTestEnv(t) + adminUsername := "user1" + normalUsername := "user2" + session := loginUser(t, adminUsername) + + urlStr := fmt.Sprintf("/api/v1/user?sudo=%s", normalUsername) + req := NewRequest(t, "GET", urlStr) + resp := session.MakeRequest(t, req, http.StatusOK) + var user api.User + DecodeJSON(t, resp, &user) + + assert.Equal(t, normalUsername, user.UserName) +} + +func TestAPISudoUserForbidden(t *testing.T) { + prepareTestEnv(t) + adminUsername := "user1" + normalUsername := "user2" + + session := loginUser(t, normalUsername) + + urlStr := fmt.Sprintf("/api/v1/user?sudo=%s", adminUsername) + req := NewRequest(t, "GET", urlStr) + session.MakeRequest(t, req, http.StatusForbidden) +} |