@@ -649,6 +649,52 @@ func TestHandlerAdminSessionManagement(t *testing.T) {
649
649
})
650
650
})
651
651
652
+ t .Run ("case=session status should be false for inactive identity" , func (t * testing.T ) {
653
+ client := testhelpers .NewClientWithCookies (t )
654
+ var s * Session
655
+ require .NoError (t , faker .FakeData (& s ))
656
+ s .Active = true
657
+ s .Identity .State = identity .StateInactive
658
+ require .NoError (t , reg .Persister ().CreateIdentity (ctx , s .Identity ))
659
+
660
+ assert .Equal (t , uuid .Nil , s .ID )
661
+ require .NoError (t , reg .SessionPersister ().UpsertSession (ctx , s ))
662
+ assert .NotEqual (t , uuid .Nil , s .ID )
663
+ assert .NotEqual (t , uuid .Nil , s .Identity .ID )
664
+
665
+ req , _ := http .NewRequest ("GET" , ts .URL + "/admin/sessions/" + s .ID .String ()+ "?expand=Identity" , nil )
666
+ res , err := client .Do (req )
667
+ require .NoError (t , err )
668
+ assert .Equal (t , http .StatusOK , res .StatusCode )
669
+
670
+ body , err := io .ReadAll (res .Body )
671
+ require .NoError (t , err )
672
+ assert .Equal (t , "false" , gjson .GetBytes (body , "active" ).String (), "%s" , body )
673
+ })
674
+
675
+ t .Run ("case=session status should be false when session expiry is past" , func (t * testing.T ) {
676
+ client := testhelpers .NewClientWithCookies (t )
677
+ var s * Session
678
+ require .NoError (t , faker .FakeData (& s ))
679
+ s .Active = true
680
+ s .ExpiresAt = time .Now ().Add (- time .Hour * 1 )
681
+ require .NoError (t , reg .Persister ().CreateIdentity (ctx , s .Identity ))
682
+
683
+ assert .Equal (t , uuid .Nil , s .ID )
684
+ require .NoError (t , reg .SessionPersister ().UpsertSession (ctx , s ))
685
+ assert .NotEqual (t , uuid .Nil , s .ID )
686
+ assert .NotEqual (t , uuid .Nil , s .Identity .ID )
687
+
688
+ req , _ := http .NewRequest ("GET" , ts .URL + "/admin/sessions/" + s .ID .String (), nil )
689
+ res , err := client .Do (req )
690
+ require .NoError (t , err )
691
+ assert .Equal (t , http .StatusOK , res .StatusCode )
692
+
693
+ body , err := io .ReadAll (res .Body )
694
+ require .NoError (t , err )
695
+ assert .Equal (t , "false" , gjson .GetBytes (body , "active" ).String (), "%s" , body )
696
+ })
697
+
652
698
t .Run ("case=should return 400 when bad UUID is sent" , func (t * testing.T ) {
653
699
client := testhelpers .NewClientWithCookies (t )
654
700
0 commit comments