You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
70 lines
1.5 KiB
4 years ago
|
// 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.
|
||
|
|
||
2 years ago
|
package integration
|
||
4 years ago
|
|
||
|
import (
|
||
3 years ago
|
"io"
|
||
4 years ago
|
"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) {
|
||
3 years ago
|
kases := []struct {
|
||
4 years ago
|
p string
|
||
|
code int
|
||
|
}{
|
||
|
{
|
||
|
p: "user2/repo1/info/refs",
|
||
3 years ago
|
code: http.StatusOK,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: "user2/repo1/HEAD",
|
||
3 years ago
|
code: http.StatusOK,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: "user2/repo1/objects/info/alternates",
|
||
3 years ago
|
code: http.StatusNotFound,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: "user2/repo1/objects/info/http-alternates",
|
||
3 years ago
|
code: http.StatusNotFound,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: "user2/repo1/../../custom/conf/app.ini",
|
||
3 years ago
|
code: http.StatusNotFound,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
|
||
3 years ago
|
code: http.StatusNotFound,
|
||
4 years ago
|
},
|
||
|
{
|
||
|
p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
|
||
3 years ago
|
code: http.StatusBadRequest,
|
||
4 years ago
|
},
|
||
|
}
|
||
|
|
||
|
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)
|
||
3 years ago
|
_, err = io.ReadAll(resp.Body)
|
||
4 years ago
|
assert.NoError(t, err)
|
||
|
})
|
||
|
}
|
||
|
}
|