From 12e0a94316b2d310e44426196c083fb3f098c086 Mon Sep 17 00:00:00 2001 From: Emil Tullstedt Date: Fri, 19 Nov 2021 12:05:04 +0100 Subject: [PATCH] JWT: Split race-y test into two stable tests (#41950) --- pkg/services/auth/jwt/auth_test.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/services/auth/jwt/auth_test.go b/pkg/services/auth/jwt/auth_test.go index 71c315465c1..de6e5351341 100644 --- a/pkg/services/auth/jwt/auth_test.go +++ b/pkg/services/auth/jwt/auth_test.go @@ -148,7 +148,7 @@ func TestCachingJWKHTTPResponse(t *testing.T) { assert.Equal(t, 1, *sc.reqCount) }) - jwkCachingScenario(t, "respects TTL setting", func(t *testing.T, sc cachingScenarioContext) { + jwkCachingScenario(t, "respects TTL setting (while cached)", func(t *testing.T, sc cachingScenarioContext) { var err error token0 := sign(t, &jwKeys[0], jwt.Claims{Subject: subject}) @@ -160,17 +160,9 @@ func TestCachingJWKHTTPResponse(t *testing.T) { require.Error(t, err) assert.Equal(t, 1, *sc.reqCount) - - time.Sleep(sc.cfg.JWTAuthCacheTTL + time.Millisecond) - - _, err = sc.authJWTSvc.Verify(sc.ctx, token1) - require.NoError(t, err) - _, err = sc.authJWTSvc.Verify(sc.ctx, token0) - require.Error(t, err) - - assert.Equal(t, 2, *sc.reqCount) }, func(t *testing.T, cfg *setting.Cfg) { - cfg.JWTAuthCacheTTL = time.Second + // Arbitrary high value, several times what the test should take. + cfg.JWTAuthCacheTTL = time.Minute }) jwkCachingScenario(t, "does not cache the response when TTL is zero", func(t *testing.T, sc cachingScenarioContext) {