2017-03-06 19:43:17 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-03-06 19:43:17 +05:30
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2017-03-06 19:43:17 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2024-03-19 12:46:19 +05:30
|
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
2017-04-25 12:54:51 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-05-11 15:51:34 +05:30
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2024-03-19 12:46:19 +05:30
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
"code.gitea.io/gitea/routers"
|
2022-09-03 00:48:23 +05:30
|
|
|
"code.gitea.io/gitea/tests"
|
2017-03-06 19:43:17 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-04-25 12:54:51 +05:30
|
|
|
func TestVersion(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-03-06 19:43:17 +05:30
|
|
|
|
2024-03-19 12:46:19 +05:30
|
|
|
t.Run("Version", func(t *testing.T) {
|
|
|
|
setting.AppVer = "test-version-1"
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/version")
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
2017-03-06 19:43:17 +05:30
|
|
|
|
2024-03-19 12:46:19 +05:30
|
|
|
var version structs.ServerVersion
|
|
|
|
DecodeJSON(t, resp, &version)
|
|
|
|
assert.Equal(t, setting.AppVer, version.Version)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Versions with REQUIRE_SIGNIN_VIEW enabled", func(t *testing.T) {
|
|
|
|
defer test.MockVariableValue(&setting.Service.RequireSignInView, true)()
|
|
|
|
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
|
|
|
|
|
|
|
setting.AppVer = "test-version-1"
|
|
|
|
|
|
|
|
t.Run("Get version without auth", func(t *testing.T) {
|
|
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
|
|
|
|
// GET api without auth
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/version")
|
|
|
|
MakeRequest(t, req, http.StatusForbidden)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get version without auth", func(t *testing.T) {
|
|
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
username := "user1"
|
|
|
|
session := loginUser(t, username)
|
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
|
|
|
|
|
|
|
// GET api with auth
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/version").AddTokenAuth(token)
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
var version structs.ServerVersion
|
|
|
|
DecodeJSON(t, resp, &version)
|
|
|
|
assert.Equal(t, setting.AppVer, version.Version)
|
|
|
|
})
|
|
|
|
})
|
2017-03-06 19:43:17 +05:30
|
|
|
}
|