diff --git a/base/bucket_gocb_test.go b/base/bucket_gocb_test.go index 22864e9a6f..7dbee78b60 100644 --- a/base/bucket_gocb_test.go +++ b/base/bucket_gocb_test.go @@ -1746,13 +1746,7 @@ func TestCouchbaseServerIncorrectLogin(t *testing.T) { testBucket.BucketSpec.Server = strings.ReplaceAll(testBucket.BucketSpec.Server, "couchbase://", "couchbases://") } else { testBucket.BucketSpec.Server = strings.ReplaceAll(testBucket.BucketSpec.Server, "couchbases://", "couchbase://") - gocbBucket, err := AsGocbV2Bucket(testBucket) - require.NoError(t, err) - clusterCompatMajor, clusterCompatMinor, err := getClusterVersion(gocbBucket.cluster) - require.NoError(t, err) - if clusterCompatMajor == 7 && clusterCompatMinor == 6 { - t.Skip("Skipping test for Couchbase Server 7.6 due to GOCBC-1615") - } + SkipInvalidAuthForCouchbaseServer76(t) } // Attempt to open the bucket again using invalid creds. We should expect an error. diff --git a/base/main_test_bucket_pool.go b/base/main_test_bucket_pool.go index fb03b6245c..c544569564 100644 --- a/base/main_test_bucket_pool.go +++ b/base/main_test_bucket_pool.go @@ -39,7 +39,7 @@ type TestBucketPool struct { // readyBucketPool contains a buffered channel of buckets ready for use readyBucketPool chan Bucket - cluster tbpCluster + cluster *tbpCluster bucketReadierQueue chan tbpBucketName bucketReadierWaitGroup *sync.WaitGroup ctxCancelFunc context.CancelFunc @@ -122,7 +122,7 @@ func NewTestBucketPoolWithOptions(ctx context.Context, bucketReadierFunc TBPBuck useDefaultScope: options.UseDefaultScope, } - tbp.cluster = newTestCluster(ctx, UnitTestUrl(), tbp.Logf) + tbp.cluster = newTestCluster(ctx, UnitTestUrl(), &tbp) useCollections, err := tbp.canUseNamedCollections(ctx) if err != nil { diff --git a/base/main_test_cluster.go b/base/main_test_cluster.go index 96f6b975f7..29652dc5ab 100644 --- a/base/main_test_cluster.go +++ b/base/main_test_cluster.go @@ -17,19 +17,6 @@ import ( "github.com/couchbase/gocb/v2" ) -// tbpCluster defines the required test bucket pool cluster operations -type tbpCluster interface { - getBucketNames() ([]string, error) - insertBucket(ctx context.Context, name string, quotaMB int) error - removeBucket(name string) error - openTestBucket(ctx context.Context, name tbpBucketName, waitUntilReady time.Duration) (Bucket, error) - supportsCollections() (bool, error) - supportsMobileRBAC() (bool, error) - isServerEnterprise() (bool, error) - mobileXDCRCompatible(ctx context.Context) (bool, error) - close(context.Context) error -} - // firstServerVersionToSupportMobileXDCR this is the first server version to support Mobile XDCR feature var firstServerVersionToSupportMobileXDCR = &ComparableBuildVersion{ epoch: 0, @@ -40,30 +27,35 @@ var firstServerVersionToSupportMobileXDCR = &ComparableBuildVersion{ type clusterLogFunc func(ctx context.Context, format string, args ...interface{}) -// newTestCluster returns a cluster based on the driver used by the defaultBucketSpec. Accepts a clusterLogFunc to support -// cluster logging within a test bucket pool context -func newTestCluster(ctx context.Context, server string, logger clusterLogFunc) tbpCluster { - return newTestClusterV2(ctx, server, logger) -} - -// tbpClusterV2 implements the tbpCluster interface for a gocb v2 cluster -type tbpClusterV2 struct { - logger clusterLogFunc - server string // server address to connect to cluster - connstr string // connection string used to connect to the cluster - supportsHLV bool // Flag to indicate cluster supports Mobile XDCR +// tbpCluster represents a gocb v2 cluster +type tbpCluster struct { + logger clusterLogFunc + server string // server address to connect to cluster + connstr string // connection string used to connect to the cluster + supportsHLV bool // Flag to indicate cluster supports Mobile XDCR + majorVersion int + minorVersion int + version string // cluster can be used to perform cluster-level operations (but not bucket-level operations) cluster *gocb.Cluster } -var _ tbpCluster = &tbpClusterV2{} - -func newTestClusterV2(ctx context.Context, server string, logger clusterLogFunc) *tbpClusterV2 { - tbpCluster := &tbpClusterV2{ - logger: logger, +// newTestCluster returns a cluster based on the driver used by the defaultBucketSpec. +func newTestCluster(ctx context.Context, server string, tbp *TestBucketPool) *tbpCluster { + tbpCluster := &tbpCluster{ + logger: tbp.Logf, server: server, } tbpCluster.cluster, tbpCluster.connstr = getGocbClusterForTest(ctx, server) + metadata, err := tbpCluster.cluster.Internal().GetNodesMetadata(&gocb.GetNodesMetadataOptions{}) + if err != nil { + tbp.Fatalf(ctx, "Couldn't get cluster metadata: %v", err) + } + tbpCluster.version = metadata[0].Version + tbpCluster.majorVersion, tbpCluster.minorVersion, err = getClusterVersion(tbpCluster.cluster) + if err != nil { + tbp.Fatalf(ctx, "Couldn't get cluster version: %v", err) + } return tbpCluster } @@ -113,19 +105,14 @@ func getGocbClusterForTest(ctx context.Context, server string) (*gocb.Cluster, s // isServerEnterprise returns true if the connected returns true if the connected couchbase server // instance is Enterprise edition And false for Community edition -func (c *tbpClusterV2) isServerEnterprise() (bool, error) { - metadata, err := c.cluster.Internal().GetNodesMetadata(&gocb.GetNodesMetadataOptions{}) - if err != nil { - return false, err - } - - if strings.Contains(metadata[0].Version, "enterprise") { +func (c *tbpCluster) isServerEnterprise() (bool, error) { + if strings.Contains(c.version, "enterprise") { return true, nil } return false, nil } -func (c *tbpClusterV2) getBucketNames() ([]string, error) { +func (c *tbpCluster) getBucketNames() ([]string, error) { bucketSettings, err := c.cluster.Buckets().GetAllBuckets(nil) if err != nil { @@ -140,7 +127,7 @@ func (c *tbpClusterV2) getBucketNames() ([]string, error) { return names, nil } -func (c *tbpClusterV2) insertBucket(ctx context.Context, name string, quotaMB int) error { +func (c *tbpCluster) insertBucket(ctx context.Context, name string, quotaMB int) error { settings := gocb.CreateBucketSettings{ BucketSettings: gocb.BucketSettings{ @@ -158,12 +145,12 @@ func (c *tbpClusterV2) insertBucket(ctx context.Context, name string, quotaMB in return c.cluster.Buckets().CreateBucket(settings, options) } -func (c *tbpClusterV2) removeBucket(name string) error { +func (c *tbpCluster) removeBucket(name string) error { return c.cluster.Buckets().DropBucket(name, nil) } // openTestBucket opens the bucket of the given name for the gocb cluster in the given TestBucketPool. -func (c *tbpClusterV2) openTestBucket(ctx context.Context, testBucketName tbpBucketName, waitUntilReady time.Duration) (Bucket, error) { +func (c *tbpCluster) openTestBucket(ctx context.Context, testBucketName tbpBucketName, waitUntilReady time.Duration) (Bucket, error) { bucketCluster, connstr := getGocbClusterForTest(ctx, c.server) @@ -182,7 +169,7 @@ func (c *tbpClusterV2) openTestBucket(ctx context.Context, testBucketName tbpBuc return bucketFromSpec, nil } -func (c *tbpClusterV2) close(ctx context.Context) error { +func (c *tbpCluster) close(ctx context.Context) error { // no close operations needed if c.cluster != nil { if err := c.cluster.Close(nil); err != nil { @@ -193,7 +180,7 @@ func (c *tbpClusterV2) close(ctx context.Context) error { return nil } -func (c *tbpClusterV2) supportsCollections() (bool, error) { +func (c *tbpCluster) supportsCollections() (bool, error) { major, _, err := getClusterVersion(c.cluster) if err != nil { return false, err @@ -202,7 +189,7 @@ func (c *tbpClusterV2) supportsCollections() (bool, error) { } // supportsMobileRBAC is true if running couchbase server with all Sync Gateway roles -func (c *tbpClusterV2) supportsMobileRBAC() (bool, error) { +func (c *tbpCluster) supportsMobileRBAC() (bool, error) { isEE, err := c.isServerEnterprise() if err != nil { return false, err @@ -220,7 +207,7 @@ func (c *tbpClusterV2) supportsMobileRBAC() (bool, error) { } // mobileXDCRCompatible checks if a cluster is mobile XDCR compatible, a cluster must be enterprise edition AND > 7.6.1 -func (c *tbpClusterV2) mobileXDCRCompatible(ctx context.Context) (bool, error) { +func (c *tbpCluster) mobileXDCRCompatible(ctx context.Context) (bool, error) { enterprise, err := c.isServerEnterprise() if err != nil { return false, err @@ -229,14 +216,9 @@ func (c *tbpClusterV2) mobileXDCRCompatible(ctx context.Context) (bool, error) { return false, nil } - metadata, err := c.cluster.Internal().GetNodesMetadata(&gocb.GetNodesMetadataOptions{}) - if err != nil { - return false, err - } - // take server version, server version will be the first 5 character of version string // in the form of x.x.x - vrs := metadata[0].Version[:5] + vrs := c.version[:5] // convert the above string into a comparable string version, err := NewComparableBuildVersionFromString(vrs) diff --git a/base/util_testing.go b/base/util_testing.go index 413d714d9d..13a83064dd 100644 --- a/base/util_testing.go +++ b/base/util_testing.go @@ -767,6 +767,16 @@ func SkipImportTestsIfNotEnabled(t *testing.T) { } } +// SkipInvalidAuthForCouchbaseServer76 temporarily skips test on Couchbase Server 7.6 until invalid credentials return ErrAuthenticationFailure. +func SkipInvalidAuthForCouchbaseServer76(t *testing.T) { + if UnitTestUrlIsWalrus() { + return + } + if GTestBucketPool.cluster.majorVersion == 7 && GTestBucketPool.cluster.minorVersion == 6 { + t.Skip("Skipping test for invalid credentials with Couchbase Server 7.6 due to GOCBC-1615") + } +} + // CreateBucketScopesAndCollections will create the given scopes and collections within the given BucketSpec. func CreateBucketScopesAndCollections(ctx context.Context, bucketSpec BucketSpec, scopes map[string][]string) error { atLeastOneScope := false diff --git a/rest/adminapitest/admin_api_test.go b/rest/adminapitest/admin_api_test.go index 63576a829c..6dfa8def03 100644 --- a/rest/adminapitest/admin_api_test.go +++ b/rest/adminapitest/admin_api_test.go @@ -3183,7 +3183,6 @@ func TestConfigsIncludeDefaults(t *testing.T) { func TestLegacyCredentialInheritance(t *testing.T) { rest.RequireBucketSpecificCredentials(t) - base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP) ctx := base.TestCtx(t) @@ -3921,6 +3920,7 @@ func TestTombstoneCompactionPurgeInterval(t *testing.T) { // Make sure per DB credentials override per bucket credentials func TestPerDBCredsOverride(t *testing.T) { rest.RequireBucketSpecificCredentials(t) + base.SkipInvalidAuthForCouchbaseServer76(t) ctx := base.TestCtx(t) // Get test bucket