From 41b65d08ab713a549555d362b2c6493f3940c469 Mon Sep 17 00:00:00 2001 From: Daniel Krol Date: Mon, 4 Jul 2022 11:50:00 -0400 Subject: [PATCH] Add test to make sure tokens don't set expiration on error. --- store/token_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/store/token_test.go b/store/token_test.go index 3c29b9f..9283b8e 100644 --- a/store/token_test.go +++ b/store/token_test.go @@ -185,17 +185,29 @@ func TestStoreSaveToken(t *testing.T) { // Version 1 of the token for both devices // created for addition to the DB (no expiration attached) + // Omit Device ID to induce an error. authToken_d1_1 := auth.AuthToken{ - Token: "seekrit-d1-1", - DeviceId: "dId-1", - Scope: "*", - UserId: userId, + Token: "seekrit-d1-1", + Scope: "*", + UserId: userId, } authToken_d2_1 := authToken_d1_1 - authToken_d2_1.DeviceId = "dId-2" authToken_d2_1.Token = "seekrit-d2-1" + // Save, have error for lack of device ID. We don't care what kind of error, + // we just want to make sure Expiration doesn't get set. + if err := s.SaveToken(&authToken_d1_1); err == nil { + t.Fatalf("Expected SaveToken to have err") + } + if authToken_d1_1.Expiration != nil { + t.Fatalf("Expected SaveToken to not set expiration on error") + } + + // Add the required device IDs to make the tokens valid + authToken_d1_1.DeviceId = "dId-1" + authToken_d2_1.DeviceId = "dId-2" + // Try to get the tokens, come back empty because we're just starting out expectTokenNotExists(t, &s, authToken_d1_1.Token) expectTokenNotExists(t, &s, authToken_d2_1.Token)