diff options
author | zeripath <art27@cantab.net> | 2018-09-07 04:31:29 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@users.noreply.github.com> | 2018-09-06 23:31:29 -0400 |
commit | d293a2b9d6722dffde7998c953c3087e47a38a83 (patch) | |
tree | 9fd63e39b27e51c8ca6360fd0cf4792e075c9b4a /integrations | |
parent | e6a03813d463bc0c624a3c40fb615cacc006e265 (diff) | |
download | gitea-d293a2b9d6722dffde7998c953c3087e47a38a83.tar.gz gitea-d293a2b9d6722dffde7998c953c3087e47a38a83.zip |
Add sudo functionality to the API (#4809)
Diffstat (limited to 'integrations')
-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) +} |