4
4
package integration
5
5
6
6
import (
7
+ "fmt"
7
8
"net/http"
8
9
"net/url"
9
10
"path"
@@ -14,22 +15,6 @@ import (
14
15
"github.com/stretchr/testify/assert"
15
16
)
16
17
17
- func testSrcRouteRedirect (t * testing.T , session * TestSession , user , repo , route , expectedLocation string , expectedStatus int ) {
18
- prefix := path .Join ("/" , user , repo , "src" )
19
-
20
- // Make request
21
- req := NewRequest (t , "GET" , path .Join (prefix , route ))
22
- resp := session .MakeRequest (t , req , http .StatusSeeOther )
23
-
24
- // Check Location header
25
- location := resp .Header ().Get ("Location" )
26
- assert .Equal (t , path .Join (prefix , expectedLocation ), location )
27
-
28
- // Perform redirect
29
- req = NewRequest (t , "GET" , location )
30
- session .MakeRequest (t , req , expectedStatus )
31
- }
32
-
33
18
func setDefaultBranch (t * testing.T , session * TestSession , user , repo , branch string ) {
34
19
location := path .Join ("/" , user , repo , "settings/branches" )
35
20
csrf := GetCSRF (t , session , location )
@@ -41,7 +26,7 @@ func setDefaultBranch(t *testing.T, session *TestSession, user, repo, branch str
41
26
session .MakeRequest (t , req , http .StatusSeeOther )
42
27
}
43
28
44
- func TestNonasciiBranches (t * testing.T ) {
29
+ func TestNonAsciiBranches (t * testing.T ) {
45
30
testRedirects := []struct {
46
31
from string
47
32
to string
@@ -98,6 +83,7 @@ func TestNonasciiBranches(t *testing.T) {
98
83
to : "branch/%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81" ,
99
84
status : http .StatusOK ,
100
85
},
86
+
101
87
// Tags
102
88
{
103
89
from : "Тэг" ,
@@ -119,6 +105,7 @@ func TestNonasciiBranches(t *testing.T) {
119
105
to : "tag/%E3%82%BF%E3%82%B0/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.md" ,
120
106
status : http .StatusOK ,
121
107
},
108
+
122
109
// Files
123
110
{
124
111
from : "README.md" ,
@@ -135,6 +122,7 @@ func TestNonasciiBranches(t *testing.T) {
135
122
to : "branch/Plus+Is+Not+Space/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.md" ,
136
123
status : http .StatusNotFound , // it's not on default branch
137
124
},
125
+
138
126
// Same but url-encoded (few tests)
139
127
{
140
128
from : "%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81" ,
@@ -205,10 +193,23 @@ func TestNonasciiBranches(t *testing.T) {
205
193
session := loginUser (t , user )
206
194
207
195
setDefaultBranch (t , session , user , repo , "Plus+Is+Not+Space" )
196
+ defer setDefaultBranch (t , session , user , repo , "master" )
208
197
209
198
for _ , test := range testRedirects {
210
- testSrcRouteRedirect (t , session , user , repo , test .from , test .to , test .status )
211
- }
199
+ t .Run (test .from , func (t * testing.T ) {
200
+ req := NewRequest (t , "GET" , fmt .Sprintf ("/%s/%s/src/%s" , user , repo , test .from ))
201
+ resp := session .MakeRequest (t , req , http .StatusSeeOther )
202
+ if resp .Code != http .StatusSeeOther {
203
+ return
204
+ }
212
205
213
- setDefaultBranch (t , session , user , repo , "master" )
206
+ redirectLocation := resp .Header ().Get ("Location" )
207
+ if ! assert .Equal (t , fmt .Sprintf ("/%s/%s/src/%s" , user , repo , test .to ), redirectLocation ) {
208
+ return
209
+ }
210
+
211
+ req = NewRequest (t , "GET" , redirectLocation )
212
+ session .MakeRequest (t , req , test .status )
213
+ })
214
+ }
214
215
}
0 commit comments