@@ -84,15 +84,17 @@ func TestPackageContainer(t *testing.T) {
84
84
Token string `json:"token"`
85
85
}
86
86
87
- authenticate := []string {`Bearer realm="` + setting .AppURL + `v2/token",service="container_registry",scope="*"` }
87
+ wwwAuthenticateValues := func () []string {
88
+ return []string {`Bearer realm="` + setting .AppURL + `v2/token",service="container_registry",scope="*"` }
89
+ }
88
90
89
91
t .Run ("Anonymous" , func (t * testing.T ) {
90
92
defer tests .PrintCurrentTest (t )()
91
93
92
94
req := NewRequest (t , "GET" , fmt .Sprintf ("%sv2" , setting .AppURL ))
93
95
resp := MakeRequest (t , req , http .StatusUnauthorized )
94
96
95
- assert .ElementsMatch (t , authenticate , resp .Header ().Values ("WWW-Authenticate" ))
97
+ assert .ElementsMatch (t , wwwAuthenticateValues () , resp .Header ().Values ("WWW-Authenticate" ))
96
98
97
99
req = NewRequest (t , "GET" , fmt .Sprintf ("%sv2/token" , setting .AppURL ))
98
100
resp = MakeRequest (t , req , http .StatusOK )
@@ -115,6 +117,12 @@ func TestPackageContainer(t *testing.T) {
115
117
116
118
req = NewRequest (t , "GET" , fmt .Sprintf ("%sv2/token" , setting .AppURL ))
117
119
MakeRequest (t , req , http .StatusUnauthorized )
120
+
121
+ defer test .MockVariableValue (& setting .AppURL , "http://domain/sub-path/" )()
122
+ defer test .MockVariableValue (& setting .AppSubURL , "/sub-path" )()
123
+ req = NewRequest (t , "GET" , fmt .Sprintf ("/v2" ))
124
+ resp = MakeRequest (t , req , http .StatusUnauthorized )
125
+ assert .Equal (t , `Bearer realm="http://domain/v2/token",service="container_registry",scope="*"` , resp .Header ().Get ("WWW-Authenticate" ))
118
126
})
119
127
120
128
t .Run ("User" , func (t * testing.T ) {
@@ -123,7 +131,7 @@ func TestPackageContainer(t *testing.T) {
123
131
req := NewRequest (t , "GET" , fmt .Sprintf ("%sv2" , setting .AppURL ))
124
132
resp := MakeRequest (t , req , http .StatusUnauthorized )
125
133
126
- assert .ElementsMatch (t , authenticate , resp .Header ().Values ("WWW-Authenticate" ))
134
+ assert .ElementsMatch (t , wwwAuthenticateValues () , resp .Header ().Values ("WWW-Authenticate" ))
127
135
128
136
req = NewRequest (t , "GET" , fmt .Sprintf ("%sv2/token" , setting .AppURL )).
129
137
AddBasicAuth (user .Name )
0 commit comments