@@ -13,6 +13,8 @@ import (
1313 "testing"
1414 "time"
1515
16+ "github.com/ory/hydra/v2/driver/config"
17+
1618 "github.com/stretchr/testify/require"
1719
1820 hydra "github.com/ory/hydra-client-go/v2"
@@ -85,11 +87,13 @@ func TestGetLoginRequest(t *testing.T) {
8587 for k , tc := range []struct {
8688 exists bool
8789 handled bool
90+ expired bool
8891 status int
8992 }{
90- {false , false , http .StatusNotFound },
91- {true , false , http .StatusOK },
92- {true , true , http .StatusGone },
93+ {false , false , false , http .StatusNotFound },
94+ {true , false , false , http .StatusOK },
95+ {true , true , false , http .StatusGone },
96+ {true , false , true , http .StatusGone },
9397 } {
9498 t .Run (fmt .Sprintf ("exists=%v/handled=%v" , tc .exists , tc .handled ), func (t * testing.T ) {
9599 ctx := context .Background ()
@@ -109,6 +113,10 @@ func TestGetLoginRequest(t *testing.T) {
109113 RequestURL : requestURL ,
110114 RequestedAt : time .Now (),
111115 })
116+ if tc .expired {
117+ require .NoError (t , conf .Set (ctx , config .KeyConsentRequestMaxAge , time .Millisecond ))
118+ time .Sleep (time .Millisecond * 5 )
119+ }
112120 require .NoError (t , err )
113121 challenge , err = f .ToLoginChallenge (ctx , reg )
114122 require .NoError (t , err )
@@ -132,7 +140,7 @@ func TestGetLoginRequest(t *testing.T) {
132140 require .NoError (t , err )
133141 require .EqualValues (t , tc .status , resp .StatusCode )
134142
135- if tc .handled {
143+ if tc .handled || tc . expired {
136144 var result flow.OAuth2RedirectTo
137145 require .NoError (t , json .NewDecoder (resp .Body ).Decode (& result ))
138146 require .Equal (t , requestURL , result .RedirectTo )
@@ -151,11 +159,13 @@ func TestGetConsentRequest(t *testing.T) {
151159 for k , tc := range []struct {
152160 exists bool
153161 handled bool
162+ expired bool
154163 status int
155164 }{
156- {false , false , http .StatusNotFound },
157- {true , false , http .StatusOK },
158- {true , true , http .StatusGone },
165+ {false , false , false , http .StatusNotFound },
166+ {true , false , false , http .StatusOK },
167+ {true , true , false , http .StatusGone },
168+ {true , false , true , http .StatusGone },
159169 } {
160170 t .Run (fmt .Sprintf ("case=%d" , k ), func (t * testing.T ) {
161171 ctx := context .Background ()
@@ -192,6 +202,10 @@ func TestGetConsentRequest(t *testing.T) {
192202 CSRF : challenge ,
193203 LoginChallenge : sqlxx .NullString (lr .ID ),
194204 }))
205+ if tc .expired {
206+ require .NoError (t , conf .Set (ctx , config .KeyConsentRequestMaxAge , time .Millisecond ))
207+ time .Sleep (time .Millisecond * 5 )
208+ }
195209
196210 if tc .handled {
197211 _ , err := reg .ConsentManager ().HandleConsentRequest (ctx , f , & flow.AcceptOAuth2ConsentRequest {
@@ -217,7 +231,7 @@ func TestGetConsentRequest(t *testing.T) {
217231 require .NoError (t , err )
218232 require .EqualValues (t , tc .status , resp .StatusCode )
219233
220- if tc .handled {
234+ if tc .handled || tc . expired {
221235 var result flow.OAuth2RedirectTo
222236 require .NoError (t , json .NewDecoder (resp .Body ).Decode (& result ))
223237 require .Equal (t , requestURL , result .RedirectTo )
0 commit comments