Skip to content

Commit 735f146

Browse files
committed
Add tests
1 parent 99214c0 commit 735f146

File tree

2 files changed

+483
-5
lines changed

2 files changed

+483
-5
lines changed

recipe/session/recipeImplementation.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ
5757
return nil, parseErr
5858
}
5959

60-
frontToken := BuildFrontToken(sessionResponse.Session.UserID, sessionResponse.Session.ExpiryTime, parsedJWT.Payload)
60+
frontToken := BuildFrontToken(sessionResponse.Session.UserID, sessionResponse.AccessToken.Expiry, parsedJWT.Payload)
6161
session := sessionResponse.Session
6262
sessionContainerInput := makeSessionContainerInput(sessionResponse.AccessToken.Token, session.Handle, session.UserID, parsedJWT.Payload, result, frontToken, sessionResponse.AntiCsrfToken, nil, &sessionResponse.RefreshToken, true)
6363
return newSessionContainer(config, &sessionContainerInput), nil
@@ -66,7 +66,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ
6666
// In all cases if sIdRefreshToken token exists (so it's a legacy session) we return TRY_REFRESH_TOKEN. The refresh endpoint will clear this cookie and try to upgrade the session.
6767
// Check https://supertokens.com/docs/contribute/decisions/session/0007 for further details and a table of expected behaviours
6868
getSession := func(accessTokenString string, antiCsrfToken *string, options *sessmodels.VerifySessionOptions, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
69-
if options != nil && *options.AntiCsrfCheck != false && config.AntiCsrf != AntiCSRF_VIA_CUSTOM_HEADER {
69+
if options != nil && options.AntiCsrfCheck != nil && *options.AntiCsrfCheck != false && config.AntiCsrf != AntiCSRF_VIA_CUSTOM_HEADER {
7070
return nil, defaultErrors.New("Since the anti-csrf mode is VIA_CUSTOM_HEADER getSession can't check the CSRF token. Please either use VIA_TOKEN or set antiCsrfCheck to false")
7171
}
7272

@@ -88,6 +88,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ
8888
}
8989
}
9090

91+
accessToken = &accessTokenResponse
9192
err = ValidateAccessTokenStructure(accessTokenResponse.Payload, accessTokenResponse.Version)
9293

9394
if err != nil {
@@ -105,11 +106,15 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ
105106

106107
alwaysCheckCore := false
107108

108-
if options.CheckDatabase != nil {
109+
if options != nil && options.CheckDatabase != nil {
109110
alwaysCheckCore = *options.CheckDatabase == true
110111
}
111112

112-
doAntiCsrfCheck := options != nil && *options.AntiCsrfCheck != false
113+
doAntiCsrfCheck := true
114+
115+
if options != nil && options.AntiCsrfCheck != nil && *options.AntiCsrfCheck == false {
116+
doAntiCsrfCheck = false
117+
}
113118

114119
response, err := getSessionHelper(config, querier, *accessToken, antiCsrfToken, doAntiCsrfCheck, alwaysCheckCore)
115120
if err != nil {
@@ -119,7 +124,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ
119124
supertokens.LogDebugMessage("getSession: Success!")
120125
var payload map[string]interface{}
121126

122-
if reflect.DeepEqual(response.AccessToken, sessmodels.CreateOrRefreshAPIResponseToken{}) {
127+
if !reflect.DeepEqual(response.AccessToken, sessmodels.CreateOrRefreshAPIResponseToken{}) {
123128
parsedToken, parseErr := ParseJWTWithoutSignatureVerification(response.AccessToken.Token)
124129

125130
if parseErr != nil {

0 commit comments

Comments
 (0)