From 327211cec9a9a22e302f2ed270507db2677fb2a6 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Fri, 3 Dec 2021 23:44:18 +0000 Subject: [PATCH] Refreshing with an invalid session should work I would like this test to pass, but it currently doesn't. With the current implementation, there is a race, if the session is locked, but releases before the "handleObtainLockError" starts, then you'll get an error, which is not desirable --- pkg/middleware/stored_session_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/stored_session_test.go b/pkg/middleware/stored_session_test.go index d9868d58..901ffba2 100644 --- a/pkg/middleware/stored_session_test.go +++ b/pkg/middleware/stored_session_test.go @@ -613,7 +613,7 @@ var _ = Describe("Stored Session Suite", func() { ObtainError: errors.New("not able to obtain lock"), }, }), - Entry("when obtaining lock failed", refreshSessionIfNeededTableInput{ + Entry("when obtaining lock failed with a valid session", refreshSessionIfNeededTableInput{ refreshPeriod: 1 * time.Minute, session: &sessionsapi.SessionState{ RefreshToken: noRefresh, @@ -630,6 +630,24 @@ var _ = Describe("Stored Session Suite", func() { ObtainError: errors.New("not able to obtain lock"), }, }), + Entry("when obtaining lock failed with an invalid session", refreshSessionIfNeededTableInput{ + refreshPeriod: 1 * time.Minute, + session: &sessionsapi.SessionState{ + RefreshToken: noRefresh, + CreatedAt: &createdPast, + ExpiresOn: &createdPast, + Lock: &TestLock{ + ObtainError: errors.New("not able to obtain lock"), + }, + }, + expectedErr: nil, + expectRefreshed: true, + expectValidated: false, + expectedLockState: TestLock{ + PeekedCount: 2, + ObtainError: errors.New("not able to obtain lock"), + }, + }), Entry("when the session is not refreshed by the provider", refreshSessionIfNeededTableInput{ refreshPeriod: 1 * time.Minute, session: &sessionsapi.SessionState{