2
0
Files
logikonline 12f4ea03a8
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
refactor: add /v3 suffix to module path for proper Go semver
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
2026-01-17 17:53:59 -05:00

99 lines
2.5 KiB
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"io"
"net/http"
"net/url"
"testing"
"code.gitcaddy.com/server/v3/modules/setting"
"code.gitcaddy.com/server/v3/modules/test"
"code.gitcaddy.com/server/v3/modules/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGitSmartHTTP(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
testGitSmartHTTP(t, u)
testRenamedRepoRedirect(t)
})
}
func testGitSmartHTTP(t *testing.T, u *url.URL) {
kases := []struct {
method, path string
code int
}{
{
path: "user2/repo1/info/refs",
code: http.StatusOK,
},
{
method: "HEAD",
path: "user2/repo1/info/refs",
code: http.StatusOK,
},
{
path: "user2/repo1/HEAD",
code: http.StatusOK,
},
{
path: "user2/repo1/objects/info/alternates",
code: http.StatusNotFound,
},
{
path: "user2/repo1/objects/info/http-alternates",
code: http.StatusNotFound,
},
{
path: "user2/repo1/../../custom/conf/app.ini",
code: http.StatusNotFound,
},
{
path: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
code: http.StatusNotFound,
},
{
path: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
code: http.StatusBadRequest,
},
}
for _, kase := range kases {
t.Run(kase.path, func(t *testing.T) {
req, err := http.NewRequest(util.IfZero(kase.method, "GET"), u.String()+kase.path, nil)
require.NoError(t, err)
req.SetBasicAuth("user2", userPassword)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, kase.code, resp.StatusCode)
_, err = io.ReadAll(resp.Body)
require.NoError(t, err)
})
}
}
func testRenamedRepoRedirect(t *testing.T) {
defer test.MockVariableValue(&setting.Service.RequireSignInViewStrict, true)()
// git client requires to get a 301 redirect response before 401 unauthorized response
req := NewRequest(t, "GET", "/user2/oldrepo1/info/refs")
resp := MakeRequest(t, req, http.StatusMovedPermanently)
redirect := resp.Header().Get("Location")
assert.Equal(t, "/user2/repo1/info/refs", redirect)
req = NewRequest(t, "GET", redirect)
resp = MakeRequest(t, req, http.StatusUnauthorized)
assert.Equal(t, "Unauthorized\n", resp.Body.String())
req = NewRequest(t, "GET", redirect).AddBasicAuth("user2")
resp = MakeRequest(t, req, http.StatusOK)
assert.Contains(t, resp.Body.String(), "65f1bf27bc3bf70f64657658635e66094edbcb4d\trefs/tags/v1.1")
}