Skip to content

Commit

Permalink
fix: not exposing new session function used in test server
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 29, 2024
1 parent 06a718c commit 13cfa9a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
1 change: 1 addition & 0 deletions .circleci/setupAndTestBackendSDKWithFreeCore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ST_CONNECTION_URI=http://localhost:8081

# start test-server
pushd test/test-server
sh setup-for-test.sh
API_PORT=$API_PORT ST_CONNECTION_URI=$ST_CONNECTION_URI /usr/local/go/bin/go run . &
popd

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ releasePassword

build-errors.log
main

recipe/**/*_for_test_server.go
35 changes: 0 additions & 35 deletions recipe/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,6 @@ func makeSessionContainerInput(
}
}

func NewSessionContainerFromSessionContainerInputForTestServer(sessionMap map[string]interface{}) (sessmodels.SessionContainer, error) {
recipe, err := getRecipeInstanceOrThrowError()
if err != nil {
return nil, err
}

session := &SessionContainerInput{
sessionHandle: sessionMap["sessionHandle"].(string),
userID: sessionMap["userId"].(string),
tenantId: sessionMap["tenantId"].(string),
userDataInAccessToken: sessionMap["userDataInAccessToken"].(map[string]interface{}),
accessToken: sessionMap["accessToken"].(string),
frontToken: sessionMap["frontToken"].(string),
refreshToken: nil,
antiCSRFToken: nil,
accessTokenUpdated: sessionMap["accessTokenUpdated"].(bool),
}

if refreshToken, ok := sessionMap["refreshToken"].(map[string]interface{}); ok {
session.refreshToken = &sessmodels.CreateOrRefreshAPIResponseToken{
Token: refreshToken["token"].(string),
Expiry: uint64(refreshToken["expiry"].(float64)),
CreatedTime: uint64(refreshToken["createdTime"].(float64)),
}
}

if antiCsrfToken, ok := sessionMap["antiCsrfToken"].(string); ok {
session.antiCSRFToken = &antiCsrfToken
}

session.recipeImpl = recipe.RecipeImpl

return newSessionContainer(recipe.Config, session), nil
}

func newSessionContainer(config sessmodels.TypeNormalisedInput, session *SessionContainerInput) sessmodels.SessionContainer {

sessionContainer := &sessmodels.TypeSessionContainer{}
Expand Down
40 changes: 40 additions & 0 deletions test/test-server/additional-files/new_session_for_test_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package session

import (
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
)

func NewSessionContainerFromSessionContainerInputForTestServer(sessionMap map[string]interface{}) (sessmodels.SessionContainer, error) {
recipe, err := getRecipeInstanceOrThrowError()
if err != nil {
return nil, err
}

session := &SessionContainerInput{
sessionHandle: sessionMap["sessionHandle"].(string),
userID: sessionMap["userId"].(string),
tenantId: sessionMap["tenantId"].(string),
userDataInAccessToken: sessionMap["userDataInAccessToken"].(map[string]interface{}),
accessToken: sessionMap["accessToken"].(string),
frontToken: sessionMap["frontToken"].(string),
refreshToken: nil,
antiCSRFToken: nil,
accessTokenUpdated: sessionMap["accessTokenUpdated"].(bool),
}

if refreshToken, ok := sessionMap["refreshToken"].(map[string]interface{}); ok {
session.refreshToken = &sessmodels.CreateOrRefreshAPIResponseToken{
Token: refreshToken["token"].(string),
Expiry: uint64(refreshToken["expiry"].(float64)),
CreatedTime: uint64(refreshToken["createdTime"].(float64)),
}
}

if antiCsrfToken, ok := sessionMap["antiCsrfToken"].(string); ok {
session.antiCSRFToken = &antiCsrfToken
}

session.recipeImpl = recipe.RecipeImpl

return newSessionContainer(recipe.Config, session), nil
}
3 changes: 3 additions & 0 deletions test/test-server/setup-for-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cp ./additional-files/new_session_for_test_server.go ../../recipe/session/

0 comments on commit 13cfa9a

Please sign in to comment.