@@ -27,7 +27,7 @@ import (
2727 "github.com/ory/x/uuidx"
2828)
2929
30- func MockConsentFlow (remember bool , rememberFor int , skip bool ) * flow.Flow {
30+ func mockConsentRequest (remember bool , rememberFor int , skip bool ) * flow.Flow {
3131 return & flow.Flow {
3232 ID : uuidx .NewV4 ().String (),
3333 Client : & client.Client {ID : uuidx .NewV4 ().String ()},
@@ -219,8 +219,8 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
219219 {"6" , true , 120 , true , false },
220220 } {
221221 t .Run ("key=" + tc .key , func (t * testing.T ) {
222- f := MockConsentFlow (tc .remember , tc .rememberFor , tc .skip )
223- require . NoError ( t , clientManager .CreateClient (t .Context (), f .Client ))
222+ f := mockConsentRequest (tc .remember , tc .rememberFor , tc .skip )
223+ _ = clientManager .CreateClient (t .Context (), f .Client ) // Ignore errors that are caused by duplication
224224 f .NID = deps .Networker ().NetworkID (t .Context ())
225225
226226 require .NoError (t , m .CreateConsentSession (t .Context (), f ))
@@ -234,7 +234,7 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
234234 // unfortunately the interface does not allow us to set the absolute time, so we have to wait
235235 time .Sleep (2 * time .Second )
236236 }
237- actual , err := m .FindGrantedAndRememberedConsentRequest (t .Context (), f .Client . ID , f .Subject )
237+ actual , err := m .FindGrantedAndRememberedConsentRequest (t .Context (), f .ClientID , f .Subject )
238238 if ! tc .expectRemembered {
239239 assert .Nil (t , actual )
240240 assert .ErrorIs (t , err , consent .ErrNoPreviousConsentFound )
@@ -260,45 +260,36 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
260260
261261 t .Run ("case=revoke consent request" , func (t * testing.T ) {
262262 type tc struct {
263- f * flow.Flow
264- at , rt string
265- revoke func (* testing.T , tc )
263+ at , rt , subject , client string
264+ revoke func (* testing.T )
266265 }
267- revokeFuncs := []func (* testing.T , tc ){
268- func (t * testing.T , c tc ) {
269- require .NoError (t , m .RevokeSubjectConsentSession (t .Context (), c .f .Subject ))
270- },
271- func (t * testing.T , c tc ) {
272- require .NoError (t , m .RevokeSubjectClientConsentSession (t .Context (), c .f .Subject , c .f .Client .ID ))
273- },
274- func (t * testing.T , c tc ) {
275- require .NoError (t , m .RevokeConsentSessionByID (t .Context (), c .f .ConsentRequestID .String ()))
276- },
277- }
278- tcs := make ([]tc , 2 * len (revokeFuncs ))
266+ tcs := make ([]tc , 2 )
279267 for i := range tcs {
280- f := MockConsentFlow ( i < len ( revokeFuncs ) , 0 , true )
268+ f := mockConsentRequest ( true , 0 , false )
281269 f .NID = deps .Networker ().NetworkID (t .Context ())
282270
283271 tcs [i ] = tc {
284- f : f ,
285- at : uuidx . NewV4 (). String () ,
286- rt : uuidx .NewV4 ().String (),
287- revoke : revokeFuncs [ i % len ( revokeFuncs )] ,
272+ subject : f . Subject ,
273+ client : f . Client . ID ,
274+ at : uuidx .NewV4 ().String (),
275+ rt : uuidx . NewV4 (). String () ,
288276 }
289277
290278 require .NoError (t , clientManager .CreateClient (t .Context (), f .Client ))
291279 require .NoError (t , m .CreateConsentSession (t .Context (), f ))
292- sess := & oauth2.Session {DefaultSession : openid .NewDefaultSession ()}
293- sess .Subject = f .Subject
294- sess .ConsentChallenge = f .ConsentRequestID .String ()
295280 require .NoError (t , fositeManager .CreateAccessTokenSession (t .Context (), tcs [i ].at ,
296- & fosite.Request {Client : f .Client , ID : f .ConsentRequestID .String (), RequestedAt : time .Now (), Session : sess }) ,
297- )
281+ & fosite.Request {Client : f .Client , ID : f .ConsentRequestID .String (), RequestedAt : time .Now (), Session : & oauth2. Session { DefaultSession : openid . NewDefaultSession ()}} ,
282+ ))
298283 require .NoError (t , fositeManager .CreateRefreshTokenSession (t .Context (), tcs [i ].rt , tcs [i ].at ,
299- & fosite.Request {Client : f .Client , ID : f .ConsentRequestID .String (), RequestedAt : time .Now (), Session : sess },
284+ & fosite.Request {Client : f .Client , ID : f .ConsentRequestID .String (), RequestedAt : time .Now (), Session : & oauth2. Session { DefaultSession : openid . NewDefaultSession ()} },
300285 ))
301286 }
287+ tcs [0 ].revoke = func (t * testing.T ) {
288+ require .NoError (t , m .RevokeSubjectConsentSession (t .Context (), tcs [0 ].subject ))
289+ }
290+ tcs [1 ].revoke = func (t * testing.T ) {
291+ require .NoError (t , m .RevokeSubjectClientConsentSession (t .Context (), tcs [1 ].subject , tcs [1 ].client ))
292+ }
302293
303294 for i , tc := range tcs {
304295 t .Run (fmt .Sprintf ("run=%d" , i ), func (t * testing.T ) {
@@ -307,7 +298,7 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
307298 _ , err = fositeManager .GetRefreshTokenSession (t .Context (), tc .rt , nil )
308299 require .NoError (t , err )
309300
310- tc .revoke (t , tc )
301+ tc .revoke (t )
311302
312303 r , err := fositeManager .GetAccessTokenSession (t .Context (), tc .at , nil )
313304 assert .ErrorIsf (t , err , fosite .ErrNotFound , "%+v" , r )
@@ -325,7 +316,7 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
325316 t .Run ("case=list consents" , func (t * testing.T ) {
326317 flows := make ([]* flow.Flow , 2 )
327318 for i := range flows {
328- f := MockConsentFlow (true , 0 , false )
319+ f := mockConsentRequest (true , 0 , false )
329320 f .NID = deps .Networker ().NetworkID (t .Context ())
330321 f .SessionID = sqlxx .NullString (uuidx .NewV4 ().String ())
331322 flows [i ] = f
@@ -354,8 +345,8 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
354345 }
355346
356347 t .Run ("random subject" , func (t * testing.T ) {
357- res , _ , err := m .FindSubjectsSessionGrantedConsentRequests (t .Context (), uuidx .NewV4 ().String (), flows [0 ].SessionID .String ())
358- assert .ErrorIsf (t , err , consent .ErrNoPreviousConsentFound , "%+v" , res )
348+ _ , _ , err := m .FindSubjectsSessionGrantedConsentRequests (t .Context (), uuidx .NewV4 ().String (), flows [0 ].SessionID .String ())
349+ assert .ErrorIs (t , err , consent .ErrNoPreviousConsentFound )
359350 })
360351 })
361352
@@ -435,7 +426,6 @@ func ConsentManagerTests(t *testing.T, deps Deps, m consent.Manager, loginManage
435426 SessionID : sqlxx .NullString (ls .ID ),
436427 ConsentRequestID : sqlxx .NullString (uuid .Must (uuid .NewV4 ()).String ()),
437428 GrantedScope : sqlxx.StringSliceJSONFormat {"scopea" , "scopeb" },
438- ConsentRemember : true ,
439429 ConsentRememberFor : pointerx .Ptr (0 ),
440430 }
441431
0 commit comments