@@ -13,6 +13,8 @@ import (
13
13
"testing"
14
14
"time"
15
15
16
+ "github.com/ory/hydra/v2/driver/config"
17
+
16
18
"github.com/stretchr/testify/require"
17
19
18
20
hydra "github.com/ory/hydra-client-go/v2"
@@ -85,11 +87,13 @@ func TestGetLoginRequest(t *testing.T) {
85
87
for k , tc := range []struct {
86
88
exists bool
87
89
handled bool
90
+ expired bool
88
91
status int
89
92
}{
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 },
93
97
} {
94
98
t .Run (fmt .Sprintf ("exists=%v/handled=%v" , tc .exists , tc .handled ), func (t * testing.T ) {
95
99
ctx := context .Background ()
@@ -109,6 +113,10 @@ func TestGetLoginRequest(t *testing.T) {
109
113
RequestURL : requestURL ,
110
114
RequestedAt : time .Now (),
111
115
})
116
+ if tc .expired {
117
+ require .NoError (t , conf .Set (ctx , config .KeyConsentRequestMaxAge , time .Millisecond ))
118
+ time .Sleep (time .Millisecond * 5 )
119
+ }
112
120
require .NoError (t , err )
113
121
challenge , err = f .ToLoginChallenge (ctx , reg )
114
122
require .NoError (t , err )
@@ -132,7 +140,7 @@ func TestGetLoginRequest(t *testing.T) {
132
140
require .NoError (t , err )
133
141
require .EqualValues (t , tc .status , resp .StatusCode )
134
142
135
- if tc .handled {
143
+ if tc .handled || tc . expired {
136
144
var result flow.OAuth2RedirectTo
137
145
require .NoError (t , json .NewDecoder (resp .Body ).Decode (& result ))
138
146
require .Equal (t , requestURL , result .RedirectTo )
@@ -151,11 +159,13 @@ func TestGetConsentRequest(t *testing.T) {
151
159
for k , tc := range []struct {
152
160
exists bool
153
161
handled bool
162
+ expired bool
154
163
status int
155
164
}{
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 },
159
169
} {
160
170
t .Run (fmt .Sprintf ("case=%d" , k ), func (t * testing.T ) {
161
171
ctx := context .Background ()
@@ -192,6 +202,10 @@ func TestGetConsentRequest(t *testing.T) {
192
202
CSRF : challenge ,
193
203
LoginChallenge : sqlxx .NullString (lr .ID ),
194
204
}))
205
+ if tc .expired {
206
+ require .NoError (t , conf .Set (ctx , config .KeyConsentRequestMaxAge , time .Millisecond ))
207
+ time .Sleep (time .Millisecond * 5 )
208
+ }
195
209
196
210
if tc .handled {
197
211
_ , err := reg .ConsentManager ().HandleConsentRequest (ctx , f , & flow.AcceptOAuth2ConsentRequest {
@@ -217,7 +231,7 @@ func TestGetConsentRequest(t *testing.T) {
217
231
require .NoError (t , err )
218
232
require .EqualValues (t , tc .status , resp .StatusCode )
219
233
220
- if tc .handled {
234
+ if tc .handled || tc . expired {
221
235
var result flow.OAuth2RedirectTo
222
236
require .NoError (t , json .NewDecoder (resp .Body ).Decode (& result ))
223
237
require .Equal (t , requestURL , result .RedirectTo )
0 commit comments