|
|
@ -9,7 +9,10 @@ import (
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestGitSmartHTTP(t *testing.T) {
|
|
|
|
func TestGitSmartHTTP(t *testing.T) {
|
|
|
@ -18,51 +21,55 @@ func TestGitSmartHTTP(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func testGitSmartHTTP(t *testing.T, u *url.URL) {
|
|
|
|
func testGitSmartHTTP(t *testing.T, u *url.URL) {
|
|
|
|
kases := []struct {
|
|
|
|
kases := []struct {
|
|
|
|
p string
|
|
|
|
method, path string
|
|
|
|
code int
|
|
|
|
code int
|
|
|
|
}{
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/info/refs",
|
|
|
|
path: "user2/repo1/info/refs",
|
|
|
|
|
|
|
|
code: http.StatusOK,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
method: "HEAD",
|
|
|
|
|
|
|
|
path: "user2/repo1/info/refs",
|
|
|
|
code: http.StatusOK,
|
|
|
|
code: http.StatusOK,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/HEAD",
|
|
|
|
path: "user2/repo1/HEAD",
|
|
|
|
code: http.StatusOK,
|
|
|
|
code: http.StatusOK,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/alternates",
|
|
|
|
path: "user2/repo1/objects/info/alternates",
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/http-alternates",
|
|
|
|
path: "user2/repo1/objects/info/http-alternates",
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/../../custom/conf/app.ini",
|
|
|
|
path: "user2/repo1/../../custom/conf/app.ini",
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
|
|
|
|
path: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
code: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
|
|
|
|
path: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
|
|
|
|
code: http.StatusBadRequest,
|
|
|
|
code: http.StatusBadRequest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, kase := range kases {
|
|
|
|
for _, kase := range kases {
|
|
|
|
t.Run(kase.p, func(t *testing.T) {
|
|
|
|
t.Run(kase.path, func(t *testing.T) {
|
|
|
|
p := u.String() + kase.p
|
|
|
|
req, err := http.NewRequest(util.IfZero(kase.method, "GET"), u.String()+kase.path, nil)
|
|
|
|
req, err := http.NewRequest("GET", p, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req.SetBasicAuth("user2", userPassword)
|
|
|
|
req.SetBasicAuth("user2", userPassword)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
defer resp.Body.Close()
|
|
|
|
assert.EqualValues(t, kase.code, resp.StatusCode)
|
|
|
|
assert.EqualValues(t, kase.code, resp.StatusCode)
|
|
|
|
_, err = io.ReadAll(resp.Body)
|
|
|
|
_, err = io.ReadAll(resp.Body)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|