@@ -687,21 +687,22 @@ func TestHandlerSelfServiceSessionManagement(t *testing.T) {
687
687
688
688
func TestHandlerRefreshSessionBySessionID (t * testing.T ) {
689
689
conf , reg := internal .NewFastRegistryWithMocks (t )
690
- _ , ts , _ , _ := testhelpers .NewKratosServerWithCSRFAndRouters (t , reg )
690
+ publicServer , adminServer , _ , _ := testhelpers .NewKratosServerWithCSRFAndRouters (t , reg )
691
691
692
692
// set this intermediate because kratos needs some valid url for CRUDE operations
693
693
conf .MustSet (config .ViperKeyPublicBaseURL , "http://example.com" )
694
694
testhelpers .SetDefaultIdentitySchema (conf , "file://./stub/identity.schema.json" )
695
- conf .MustSet (config .ViperKeyPublicBaseURL , ts .URL )
695
+ conf .MustSet (config .ViperKeyPublicBaseURL , adminServer .URL )
696
+
697
+ i := identity .NewIdentity ("" )
698
+ require .NoError (t , reg .IdentityManager ().Create (context .Background (), i ))
699
+ s := & Session {Identity : i , ExpiresAt : time .Now ().Add (5 * time .Minute )}
700
+ require .NoError (t , reg .SessionPersister ().UpsertSession (context .Background (), s ))
696
701
697
702
t .Run ("case=should return 200 after refreshing one session" , func (t * testing.T ) {
698
703
client := testhelpers .NewClientWithCookies (t )
699
- i := identity .NewIdentity ("" )
700
- require .NoError (t , reg .IdentityManager ().Create (context .Background (), i ))
701
- s := & Session {Identity : i , ExpiresAt : time .Now ().Add (5 * time .Minute )}
702
- require .NoError (t , reg .SessionPersister ().UpsertSession (context .Background (), s ))
703
704
704
- req , _ := http .NewRequest ("PATCH" , ts .URL + "/admin/sessions/" + s .ID .String ()+ "/extend" , nil )
705
+ req , _ := http .NewRequest ("PATCH" , adminServer .URL + "/admin/sessions/" + s .ID .String ()+ "/extend" , nil )
705
706
res , err := client .Do (req )
706
707
require .NoError (t , err )
707
708
require .Equal (t , http .StatusOK , res .StatusCode )
@@ -712,7 +713,7 @@ func TestHandlerRefreshSessionBySessionID(t *testing.T) {
712
713
713
714
t .Run ("case=should return 400 when bad UUID is sent" , func (t * testing.T ) {
714
715
client := testhelpers .NewClientWithCookies (t )
715
- req , _ := http .NewRequest ("PATCH" , ts .URL + "/admin/sessions/BADUUID/extend" , nil )
716
+ req , _ := http .NewRequest ("PATCH" , adminServer .URL + "/admin/sessions/BADUUID/extend" , nil )
716
717
res , err := client .Do (req )
717
718
require .NoError (t , err )
718
719
require .Equal (t , http .StatusBadRequest , res .StatusCode )
@@ -721,9 +722,19 @@ func TestHandlerRefreshSessionBySessionID(t *testing.T) {
721
722
t .Run ("case=should return 404 when calling with missing UUID" , func (t * testing.T ) {
722
723
client := testhelpers .NewClientWithCookies (t )
723
724
someID , _ := uuid .NewV4 ()
724
- req , _ := http .NewRequest ("PATCH" , ts .URL + "/admin/sessions/" + someID .String ()+ "/extend" , nil )
725
+ req , _ := http .NewRequest ("PATCH" , adminServer .URL + "/admin/sessions/" + someID .String ()+ "/extend" , nil )
725
726
res , err := client .Do (req )
726
727
require .NoError (t , err )
727
728
require .Equal (t , http .StatusNotFound , res .StatusCode )
728
729
})
730
+
731
+ t .Run ("case=should return 404 when calling puplic server" , func (t * testing.T ) {
732
+ req := x .NewTestHTTPRequest (t , "PATCH" , publicServer .URL + "/sessions/" + s .ID .String ()+ "/extend" , nil )
733
+
734
+ res , err := publicServer .Client ().Do (req )
735
+ require .NoError (t , err )
736
+ assert .Equal (t , http .StatusNotFound , res .StatusCode )
737
+ body := ioutilx .MustReadAll (res .Body )
738
+ assert .NotEqual (t , gjson .GetBytes (body , "error.id" ).String (), "security_csrf_violation" )
739
+ })
729
740
}
0 commit comments