Skip to content

Commit 7e3047f

Browse files
committed
Update test for access token versions
1 parent fd9fc48 commit 7e3047f

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

recipe/session/accessTokenVersions_test.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,30 @@ func TestShouldThrowErrorWhenUsingProtectedProps(t *testing.T) {
171171
testServer.Close()
172172
}()
173173

174-
appSub := "asdf"
175-
body := map[string]map[string]*string{
176-
"payload": {
177-
"sub": &appSub,
178-
},
179-
}
174+
sessionResponse, err := CreateNewSessionWithoutRequestResponse("public", "testing", map[string]interface{}{
175+
"customProps": "custom",
176+
}, map[string]interface{}{}, nil)
180177

181-
postBody, err := json.Marshal(body)
182178
if err != nil {
183179
t.Error(err.Error())
184180
}
185-
res2, err2 := http.Post(testServer.URL+"/create", "application/json", bytes.NewBuffer(postBody))
186-
if err2 != nil {
187-
t.Error(err2.Error())
181+
182+
newSession, err := CreateNewSessionWithoutRequestResponse("public", "testing2", sessionResponse.GetAccessTokenPayload(), map[string]interface{}{}, nil)
183+
184+
if err != nil {
185+
t.Error(err.Error())
188186
}
189187

190-
assert.Equal(t, 200, res2.StatusCode)
191-
cookies := unittesting.ExtractInfoFromResponse(res2)
192-
assert.False(t, cookies["accessTokenFromAny"] == "")
193-
assert.False(t, cookies["refreshTokenFromAny"] == "")
194-
assert.False(t, cookies["frontToken"] == "")
188+
accessToken := newSession.GetAccessToken()
195189

196-
parsedToken, err := ParseJWTWithoutSignatureVerification(cookies["accessTokenFromAny"])
190+
parsedToken, err := ParseJWTWithoutSignatureVerification(accessToken)
197191
if err != nil {
198192
t.Error(err.Error())
199193
}
200194

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

204200
func TestMergeIntoATShouldHelpMigratingV2TokenUsingProtectedProps(t *testing.T) {

0 commit comments

Comments
 (0)