2021-06-09 15:53:12 +03:00
// Copyright 2021 The Gitea Authors. All rights reserved.
2022-11-27 21:20:29 +03:00
// SPDX-License-Identifier: MIT
2021-06-09 15:53:12 +03:00
2022-09-02 22:18:23 +03:00
package integration
2021-06-09 15:53:12 +03:00
import (
2021-09-22 08:38:34 +03:00
"io"
2021-06-09 15:53:12 +03: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 20:46:10 +03:00
kases := [ ] struct {
2021-06-09 15:53:12 +03:00
p string
code int
} {
{
p : "user2/repo1/info/refs" ,
2022-03-23 07:54:07 +03:00
code : http . StatusOK ,
2021-06-09 15:53:12 +03:00
} ,
{
p : "user2/repo1/HEAD" ,
2022-03-23 07:54:07 +03:00
code : http . StatusOK ,
2021-06-09 15:53:12 +03:00
} ,
{
p : "user2/repo1/objects/info/alternates" ,
2022-03-23 07:54:07 +03:00
code : http . StatusNotFound ,
2021-06-09 15:53:12 +03:00
} ,
{
p : "user2/repo1/objects/info/http-alternates" ,
2022-03-23 07:54:07 +03:00
code : http . StatusNotFound ,
2021-06-09 15:53:12 +03:00
} ,
{
p : "user2/repo1/../../custom/conf/app.ini" ,
2022-03-23 07:54:07 +03:00
code : http . StatusNotFound ,
2021-06-09 15:53:12 +03:00
} ,
{
p : "user2/repo1/objects/info/../../../../custom/conf/app.ini" ,
2022-03-23 07:54:07 +03:00
code : http . StatusNotFound ,
2021-06-09 15:53:12 +03:00
} ,
{
p : ` user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini ` ,
2022-03-23 07:54:07 +03:00
code : http . StatusBadRequest ,
2021-06-09 15:53:12 +03: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 08:38:34 +03:00
_ , err = io . ReadAll ( resp . Body )
2021-06-09 15:53:12 +03:00
assert . NoError ( t , err )
} )
}
}