@@ -9,14 +9,19 @@ import (
99 "net/url"
1010 "testing"
1111
12+ "code.gitea.io/gitea/modules/setting"
13+ "code.gitea.io/gitea/modules/test"
1214 "code.gitea.io/gitea/modules/util"
1315
1416 "github.com/stretchr/testify/assert"
1517 "github.com/stretchr/testify/require"
1618)
1719
1820func TestGitSmartHTTP (t * testing.T ) {
19- onGiteaRun (t , testGitSmartHTTP )
21+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
22+ testGitSmartHTTP (t , u )
23+ testRenamedRepoRedirect (t )
24+ })
2025}
2126
2227func testGitSmartHTTP (t * testing.T , u * url.URL ) {
@@ -73,3 +78,21 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
7378 })
7479 }
7580}
81+
82+ func testRenamedRepoRedirect (t * testing.T ) {
83+ defer test .MockVariableValue (& setting .Service .RequireSignInView , true )()
84+
85+ // git client requires to get a 301 redirect response before 401 unauthorized response
86+ req := NewRequest (t , "GET" , "/user2/oldrepo1/info/refs" )
87+ resp := MakeRequest (t , req , http .StatusMovedPermanently )
88+ redirect := resp .Header ().Get ("Location" )
89+ assert .Equal (t , "/user2/repo1/info/refs" , redirect )
90+
91+ req = NewRequest (t , "GET" , redirect )
92+ resp = MakeRequest (t , req , http .StatusUnauthorized )
93+ assert .Equal (t , "Unauthorized\n " , resp .Body .String ())
94+
95+ req = NewRequest (t , "GET" , redirect ).AddBasicAuth ("user2" )
96+ resp = MakeRequest (t , req , http .StatusOK )
97+ assert .Contains (t , resp .Body .String (), "65f1bf27bc3bf70f64657658635e66094edbcb4d\t refs/tags/v1.1" )
98+ }
0 commit comments