2021-06-09 18:23:12 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2021-06-09 18:23:12 +05:30
|
|
|
|
|
|
|
import (
|
2021-09-22 11:08:34 +05:30
|
|
|
"io"
|
2021-06-09 18:23:12 +05:30
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGitSmartHTTP(t *testing.T) {
|
|
|
|
onGiteaRun(t, testGitSmartHTTP)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testGitSmartHTTP(t *testing.T, u *url.URL) {
|
2022-01-20 23:16:10 +05:30
|
|
|
kases := []struct {
|
2021-06-09 18:23:12 +05:30
|
|
|
p string
|
|
|
|
code int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/info/refs",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusOK,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/HEAD",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusOK,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/alternates",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusNotFound,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/http-alternates",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusNotFound,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/../../custom/conf/app.ini",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusNotFound,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusNotFound,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
|
2022-03-23 10:24:07 +05:30
|
|
|
code: http.StatusBadRequest,
|
2021-06-09 18:23:12 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, kase := range kases {
|
|
|
|
t.Run(kase.p, func(t *testing.T) {
|
|
|
|
p := u.String() + kase.p
|
|
|
|
req, err := http.NewRequest("GET", p, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
req.SetBasicAuth("user2", userPassword)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
assert.EqualValues(t, kase.code, resp.StatusCode)
|
2021-09-22 11:08:34 +05:30
|
|
|
_, err = io.ReadAll(resp.Body)
|
2021-06-09 18:23:12 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|