@@ -141,10 +141,24 @@ func TestHandler(t *testing.T) {
141
141
})
142
142
143
143
t .Run ("description=init a flow as browser" , func (t * testing.T ) {
144
- t .Run ("description=without privileges" , func (t * testing.T ) {
145
- res , body := initSPAFlow (t , new (http.Client ))
146
- assert .Equal (t , http .StatusUnauthorized , res .StatusCode , "%s" , body )
147
- assert .Equal (t , text .ErrNoActiveSession , gjson .GetBytes (body , "error.id" ).String (), "%s" , body )
144
+ t .Run ("case=unauthorized users are redirected to login" , func (t * testing.T ) {
145
+ c := testhelpers .NewClientWithCookies (t )
146
+ // prevent the redirect
147
+ c .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
148
+ return http .ErrUseLastResponse
149
+ }
150
+ returnTo := "?return_to=validRedirect"
151
+ req , err := http .NewRequest ("GET" , publicTS .URL + settings .RouteInitBrowserFlow + returnTo , nil )
152
+ require .NoError (t , err )
153
+
154
+ res , err := c .Do (req )
155
+ require .NoError (t , err )
156
+ // here we check that the redirect status is 303
157
+ require .Equal (t , http .StatusSeeOther , res .StatusCode )
158
+ location , err := res .Location ()
159
+ require .NoError (t , err )
160
+ require .Equal (t , publicTS .URL + login .RouteInitBrowserFlow + returnTo , location .String ())
161
+ defer res .Body .Close ()
148
162
})
149
163
150
164
t .Run ("description=success" , func (t * testing.T ) {
@@ -179,6 +193,12 @@ func TestHandler(t *testing.T) {
179
193
})
180
194
181
195
t .Run ("description=init a flow as SPA" , func (t * testing.T ) {
196
+ t .Run ("description=without privileges" , func (t * testing.T ) {
197
+ res , body := initSPAFlow (t , new (http.Client ))
198
+ assert .Equal (t , http .StatusUnauthorized , res .StatusCode , "%s" , body )
199
+ assert .Equal (t , text .ErrNoActiveSession , gjson .GetBytes (body , "error.id" ).String (), "%s" , body )
200
+ })
201
+
182
202
t .Run ("description=success" , func (t * testing.T ) {
183
203
user1 := testhelpers .NewHTTPClientWithArbitrarySessionToken (t , reg )
184
204
res , body := initSPAFlow (t , user1 )
0 commit comments