Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
auth_model "code.gitcaddy.com/server/v3/models/auth"
|
|
"code.gitcaddy.com/server/v3/models/unittest"
|
|
user_model "code.gitcaddy.com/server/v3/models/user"
|
|
api "code.gitcaddy.com/server/v3/modules/structs"
|
|
"code.gitcaddy.com/server/v3/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAPIUserInfo(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
user := "user1"
|
|
user2 := "user31"
|
|
|
|
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"})
|
|
|
|
session := loginUser(t, user)
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
|
|
|
|
t.Run("GetInfo", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/users/"+user2).
|
|
AddTokenAuth(token)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
var u api.User
|
|
DecodeJSON(t, resp, &u)
|
|
assert.Equal(t, user2, u.UserName)
|
|
|
|
req = NewRequest(t, "GET", "/api/v1/users/"+user2)
|
|
MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
// test if the placaholder Mail is returned if a User is not logged in
|
|
req = NewRequest(t, "GET", "/api/v1/users/"+org3.Name)
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
DecodeJSON(t, resp, &u)
|
|
assert.Equal(t, org3.GetPlaceholderEmail(), u.Email)
|
|
|
|
// Test if the correct Mail is returned if a User is logged in
|
|
req = NewRequest(t, "GET", "/api/v1/users/"+org3.Name).
|
|
AddTokenAuth(token)
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
DecodeJSON(t, resp, &u)
|
|
assert.Equal(t, org3.GetEmail(), u.Email)
|
|
})
|
|
|
|
t.Run("GetAuthenticatedUser", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/user").
|
|
AddTokenAuth(token)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
var u api.User
|
|
DecodeJSON(t, resp, &u)
|
|
assert.Equal(t, user, u.UserName)
|
|
})
|
|
}
|