2021-06-09 08:53:12 -04:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
2021-09-22 01:38:34 -04:00
|
|
|
"io"
|
2021-06-09 08:53:12 -04:00
|
|
|
"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 12:46:10 -05:00
|
|
|
kases := []struct {
|
2021-06-09 08:53:12 -04:00
|
|
|
p string
|
|
|
|
code int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
p: "user2/repo1/info/refs",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusOK,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/HEAD",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusOK,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/alternates",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusNotFound,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/http-alternates",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusNotFound,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/../../custom/conf/app.ini",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusNotFound,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusNotFound,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
|
2022-03-23 00:54:07 -04:00
|
|
|
code: http.StatusBadRequest,
|
2021-06-09 08:53:12 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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 01:38:34 -04:00
|
|
|
_, err = io.ReadAll(resp.Body)
|
2021-06-09 08:53:12 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|