Add sudo functionality to the API (#4809)

This commit is contained in:
zeripath 2018-09-07 04:31:29 +01:00 committed by techknowlogick
parent e6a03813d4
commit d293a2b9d6
4 changed files with 95 additions and 1 deletions

View file

@ -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)
}