Skip to content

Commit

Permalink
Update test for access token versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed Sep 12, 2023
1 parent fd9fc48 commit 7e3047f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions recipe/session/accessTokenVersions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,30 @@ func TestShouldThrowErrorWhenUsingProtectedProps(t *testing.T) {
testServer.Close()
}()

appSub := "asdf"
body := map[string]map[string]*string{
"payload": {
"sub": &appSub,
},
}
sessionResponse, err := CreateNewSessionWithoutRequestResponse("public", "testing", map[string]interface{}{
"customProps": "custom",
}, map[string]interface{}{}, nil)

postBody, err := json.Marshal(body)
if err != nil {
t.Error(err.Error())
}
res2, err2 := http.Post(testServer.URL+"/create", "application/json", bytes.NewBuffer(postBody))
if err2 != nil {
t.Error(err2.Error())

newSession, err := CreateNewSessionWithoutRequestResponse("public", "testing2", sessionResponse.GetAccessTokenPayload(), map[string]interface{}{}, nil)

if err != nil {
t.Error(err.Error())
}

assert.Equal(t, 200, res2.StatusCode)
cookies := unittesting.ExtractInfoFromResponse(res2)
assert.False(t, cookies["accessTokenFromAny"] == "")
assert.False(t, cookies["refreshTokenFromAny"] == "")
assert.False(t, cookies["frontToken"] == "")
accessToken := newSession.GetAccessToken()

parsedToken, err := ParseJWTWithoutSignatureVerification(cookies["accessTokenFromAny"])
parsedToken, err := ParseJWTWithoutSignatureVerification(accessToken)
if err != nil {
t.Error(err.Error())
}

assert.True(t, parsedToken.Payload["sub"] != "asdf")
assert.True(t, parsedToken.Payload["customProps"] == "custom")
// This makes sure it does not reuse the sub from the old payload
assert.True(t, parsedToken.Payload["sub"] == "testing2")
}

func TestMergeIntoATShouldHelpMigratingV2TokenUsingProtectedProps(t *testing.T) {
Expand Down

0 comments on commit 7e3047f

Please sign in to comment.