@@ -1013,3 +1013,65 @@ func TestSignoutWorksAfterSessionDeletedOnBackend(t *testing.T) {
10131013 assert .Equal (t , cookieData ["idRefreshTokenFromCookie" ], "" )
10141014 assert .Equal (t , cookieData ["idRefreshTokenFromHeader" ], "remove" )
10151015}
1016+
1017+ func TestSessionContainerOverride (t * testing.T ) {
1018+ customAntiCsrfVal := "VIA_TOKEN"
1019+ configValue := supertokens.TypeInput {
1020+ Supertokens : & supertokens.ConnectionInfo {
1021+ ConnectionURI : "http://localhost:8080" ,
1022+ },
1023+ AppInfo : supertokens.AppInfo {
1024+ AppName : "SuperTokens" ,
1025+ WebsiteDomain : "supertokens.io" ,
1026+ APIDomain : "api.supertokens.io" ,
1027+ },
1028+ RecipeList : []supertokens.Recipe {
1029+ Init (& sessmodels.TypeInput {
1030+ AntiCsrf : & customAntiCsrfVal ,
1031+ Override : & sessmodels.OverrideStruct {
1032+ Functions : func (originalImplementation sessmodels.RecipeInterface ) sessmodels.RecipeInterface {
1033+ oGetSessionInformation := * originalImplementation .GetSessionInformation
1034+ nGetSessionInformation := func (sessionHandle string , userContext supertokens.UserContext ) (* sessmodels.SessionInformation , error ) {
1035+ info , err := oGetSessionInformation (sessionHandle , userContext )
1036+ if err != nil {
1037+ return nil , err
1038+ }
1039+ info .SessionData = map [string ]interface {}{
1040+ "test" : 1 ,
1041+ }
1042+ return info , nil
1043+ }
1044+ * originalImplementation .GetSessionInformation = nGetSessionInformation
1045+ return originalImplementation
1046+ },
1047+ },
1048+ }),
1049+ },
1050+ }
1051+ BeforeEach ()
1052+ unittesting .StartUpST ("localhost" , "8080" )
1053+ defer AfterEach ()
1054+ err := supertokens .Init (configValue )
1055+ if err != nil {
1056+ t .Error (err .Error ())
1057+ }
1058+ res := MockResponseWriter {}
1059+ session , err := CreateNewSession (res , "testId" , map [string ]interface {}{}, map [string ]interface {}{})
1060+ assert .NoError (t , err )
1061+
1062+ data , err := session .GetSessionData ()
1063+ assert .NoError (t , err )
1064+
1065+ assert .Equal (t , 1 , data ["test" ])
1066+ }
1067+
1068+ type MockResponseWriter struct {}
1069+
1070+ func (mw MockResponseWriter ) Header () http.Header {
1071+ return http.Header {}
1072+ }
1073+ func (mw MockResponseWriter ) Write ([]byte ) (int , error ) {
1074+ return 0 , nil
1075+ }
1076+ func (mw MockResponseWriter ) WriteHeader (statusCode int ) {
1077+ }
0 commit comments