@@ -9,14 +9,19 @@ import (
9
9
"net/url"
10
10
"testing"
11
11
12
+ "code.gitea.io/gitea/modules/setting"
13
+ "code.gitea.io/gitea/modules/test"
12
14
"code.gitea.io/gitea/modules/util"
13
15
14
16
"github.com/stretchr/testify/assert"
15
17
"github.com/stretchr/testify/require"
16
18
)
17
19
18
20
func 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
+ })
20
25
}
21
26
22
27
func testGitSmartHTTP (t * testing.T , u * url.URL ) {
@@ -73,3 +78,21 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
73
78
})
74
79
}
75
80
}
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