Skip to content

Commit

Permalink
reset cert pools only in a test
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Dec 2, 2024
1 parent ea548ac commit f0cf548
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 0 additions & 7 deletions base/dcp_feed_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,3 @@ func setCbgtRootCertsForBucket(bucketUUID string, pool *x509.CertPool) {
defer cbgtGlobalsLock.Unlock()
cbgtRootCertPools[bucketUUID] = pool
}

// removeCbgtRootCertsForBucket removes all the root certificates for a bucket. See the comment of cbgtRootCAsProvider for usage details.
func removeCbgtRootCertsForBucket(bucketUUID string) {
cbgtGlobalsLock.Lock()
defer cbgtGlobalsLock.Unlock()
delete(cbgtRootCertPools, bucketUUID)
}
2 changes: 1 addition & 1 deletion base/dcp_sharded.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (c *CbgtContext) Stop() {

func (c *CbgtContext) RemoveFeedCredentials(dbName string) {
removeCbgtCredentials(dbName)
removeCbgtRootCertsForBucket(c.sourceUUID)
// CBG-4394: removing root certs for the bucket should be done, but it is keyed based on the bucket UUID, and multiple dbs can use the same bucket
}

// Format of dest key for retrieval of import dest from cbgtDestFactories
Expand Down
12 changes: 12 additions & 0 deletions base/util_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"io/fs"
"log"
"maps"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -978,3 +979,14 @@ func numFilesInDir(t *testing.T, dir string, recursive bool) int {
require.NoError(t, err)
return numFiles
}

// ResetCBGTCertPools resets the cert pools used for cbgt in a test.
func ResetCBGTCertPools(t *testing.T) {
// CBG-4394: removing root certs for the bucket should be done, but it is keyed based on the bucket UUID, and multiple dbs can use the same bucket
cbgtGlobalsLock.Lock()
defer cbgtGlobalsLock.Unlock()
oldRootCAs := maps.Clone(cbgtRootCertPools)
t.Cleanup(func() {
cbgtRootCertPools = oldRootCAs
})
}
1 change: 1 addition & 0 deletions rest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3140,6 +3140,7 @@ func TestRevCacheMemoryLimitConfig(t *testing.T) {
}

func TestTLSWithoutCerts(t *testing.T) {
base.ResetCBGTCertPools(t) // CBG-4394: removing root certs for the bucket should be done, but it is keyed based on the bucket UUID, and multiple dbs can use the same bucket
rt := NewRestTester(t, &RestTesterConfig{
PersistentConfig: true,
MutateStartupConfig: func(config *StartupConfig) {
Expand Down

0 comments on commit f0cf548

Please sign in to comment.