From b36df6cae36901af5525b5553f85e10b4d0b4561 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lb Date: Mon, 14 Aug 2023 15:56:41 -0700 Subject: [PATCH] SNOW-892592: Fix panic when SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED=false --- ocsp.go | 5 +++-- ocsp_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ocsp.go b/ocsp.go index f0a30b995..a1a9cb639 100644 --- a/ocsp.go +++ b/ocsp.go @@ -716,11 +716,12 @@ func overrideCacheDir() { // initOCSPCache initializes OCSP Response cache file. func initOCSPCache() { + ocspResponseCache = make(map[certIDKey][]interface{}) + ocspResponseCacheLock = &sync.RWMutex{} + if strings.EqualFold(os.Getenv(cacheServerEnabledEnv), "false") { return } - ocspResponseCache = make(map[certIDKey][]interface{}) - ocspResponseCacheLock = &sync.RWMutex{} logger.Infof("reading OCSP Response cache file. %v\n", cacheFileName) f, err := os.OpenFile(cacheFileName, os.O_CREATE|os.O_RDONLY, readWriteFileMode) diff --git a/ocsp_test.go b/ocsp_test.go index 678d1eadd..cf22f11e4 100644 --- a/ocsp_test.go +++ b/ocsp_test.go @@ -533,3 +533,21 @@ func TestInitOCSPCacheFileCreation(t *testing.T) { t.Error(err) } } + +func TestCacheServerDisabled(t *testing.T) { + _ = os.Setenv(cacheServerEnabledEnv, "false") + + if _, err := buildSnowflakeConn(context.Background(), Config{ + Account: "testaccount", + User: "testuser", + Password: "testpassword", + Host: "testaccount.us-east-1.snowflakecomputing.com", + }); err != nil { + t.Error(err) + } + + ocspURL := os.Getenv(cacheServerURLEnv) + if ocspURL != "" { + t.Fatalf("cache server is disabled. Expected empty url but got %v ", cacheServerURLEnv) + } +}