Skip to content

Commit 1648a4e

Browse files
gregns1bbrks
authored andcommitted
CBG-3607: disable the ability to set shared_bucket_access to false. I… (#6590)
* CBG-3607: disable the ability to set shared_bucket_access to false. In future we will probably look to fully remove the config param but for now this will protect against panics * remove comment slashes + add test comments * updates off review + failing test in integration test run * missed test update * lint error fix * add skip for lint?
1 parent b34105b commit 1648a4e

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

base/util_testing.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ func TestUseXattrs() bool {
209209
if err != nil {
210210
panic(fmt.Sprintf("unable to parse %q value %q: %v", TestEnvSyncGatewayUseXattrs, useXattrs, err))
211211
}
212+
if !val {
213+
panic("sync gateway requires xattrs to be enabled")
214+
}
212215

213216
return val
214217
}

db/revision_cache_interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ func revCacheLoaderForDocument(ctx context.Context, backingStore RevisionCacheBa
327327
}
328328

329329
// revCacheLoaderForDocumentCV used either during cache miss (from revCacheLoaderForCv), or used directly when getting current active CV from cache
330+
// nolint:staticcheck
330331
func revCacheLoaderForDocumentCV(ctx context.Context, backingStore RevisionCacheBackingStore, doc *Document, cv SourceAndVersion) (bodyBytes []byte, body Body, history Revisions, channels base.Set, removed bool, attachments AttachmentsMeta, deleted bool, expiry *time.Time, revid string, err error) {
331332
if bodyBytes, body, attachments, err = backingStore.getCurrentVersion(ctx, doc); err != nil {
333+
// TODO: pending CBG-3213 support of channel removal for CV
332334
// we need implementation of IsChannelRemoval for CV here.
333-
// pending CBG-3213 support of channel removal for CV
334335
}
335336

336337
if err = doc.HasCurrentVersion(cv); err != nil {

rest/adminapitest/admin_api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ func TestHandlePutDbConfigWithBackticksCollections(t *testing.T) {
24712471
reqBodyWithBackticks := `{
24722472
"server": "walrus:",
24732473
"bucket": "backticks",
2474-
"enable_shared_bucket_access":false,
2474+
"enable_shared_bucket_access":true,
24752475
"scopes": {
24762476
"scope1": {
24772477
"collections" : {

rest/api_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,79 @@ func TestNullDocHandlingForMutable1xBody(t *testing.T) {
27462746
assert.Contains(t, err.Error(), "null doc body for doc")
27472747
}
27482748

2749+
// TestDatabaseXattrConfigHandlingForDBConfigUpdate:
2750+
// - Create database with xattrs enabled
2751+
// - Test updating the config to disable the use of xattrs in this database through replacing + upserting the config
2752+
// - Assert error code is returned and response contains error string
2753+
func TestDatabaseXattrConfigHandlingForDBConfigUpdate(t *testing.T) {
2754+
base.LongRunningTest(t)
2755+
const (
2756+
dbName = "db1"
2757+
errResp = "sync gateway requires enable_shared_bucket_access=true"
2758+
)
2759+
2760+
testCases := []struct {
2761+
name string
2762+
upsertConfig bool
2763+
}{
2764+
{
2765+
name: "POST update",
2766+
upsertConfig: true,
2767+
},
2768+
{
2769+
name: "PUT update",
2770+
upsertConfig: false,
2771+
},
2772+
}
2773+
for _, testCase := range testCases {
2774+
t.Run(testCase.name, func(t *testing.T) {
2775+
rt := NewRestTester(t, &RestTesterConfig{
2776+
PersistentConfig: true,
2777+
})
2778+
defer rt.Close()
2779+
2780+
dbConfig := rt.NewDbConfig()
2781+
2782+
resp := rt.CreateDatabase(dbName, dbConfig)
2783+
RequireStatus(t, resp, http.StatusCreated)
2784+
assert.NoError(t, rt.WaitForDBOnline())
2785+
2786+
dbConfig.EnableXattrs = base.BoolPtr(false)
2787+
2788+
if testCase.upsertConfig {
2789+
resp = rt.UpsertDbConfig(dbName, dbConfig)
2790+
RequireStatus(t, resp, http.StatusInternalServerError)
2791+
assert.Contains(t, resp.Body.String(), errResp)
2792+
} else {
2793+
resp = rt.ReplaceDbConfig(dbName, dbConfig)
2794+
RequireStatus(t, resp, http.StatusInternalServerError)
2795+
assert.Contains(t, resp.Body.String(), errResp)
2796+
}
2797+
})
2798+
}
2799+
}
2800+
2801+
// TestCreateDBWithXattrsDisbaled:
2802+
// - Test that you cannot create a database with xattrs disabled
2803+
// - Assert error code is returned and response contains error string
2804+
func TestCreateDBWithXattrsDisbaled(t *testing.T) {
2805+
rt := NewRestTester(t, &RestTesterConfig{
2806+
PersistentConfig: true,
2807+
})
2808+
defer rt.Close()
2809+
const (
2810+
dbName = "db1"
2811+
errResp = "sync gateway requires enable_shared_bucket_access=true"
2812+
)
2813+
2814+
dbConfig := rt.NewDbConfig()
2815+
dbConfig.EnableXattrs = base.BoolPtr(false)
2816+
2817+
resp := rt.CreateDatabase(dbName, dbConfig)
2818+
RequireStatus(t, resp, http.StatusInternalServerError)
2819+
assert.Contains(t, resp.Body.String(), errResp)
2820+
}
2821+
27492822
// TestPutDocUpdateVersionVector:
27502823
// - Put a doc and assert that the versions and the source for the hlv is correctly updated
27512824
// - Update that doc and assert HLV has also been updated

rest/server_context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,11 @@ func dbcOptionsFromConfig(ctx context.Context, sc *ServerContext, config *DbConf
10851085
}
10861086
}
10871087

1088+
// In sync gateway version 4.0+ we do not support the disabling of use of xattrs
1089+
if !config.UseXattrs() {
1090+
return db.DatabaseContextOptions{}, fmt.Errorf("sync gateway requires enable_shared_bucket_access=true")
1091+
}
1092+
10881093
// Create a callback function that will be invoked if the database goes offline and comes
10891094
// back online again
10901095
dbOnlineCallback := func(dbContext *db.DatabaseContext) {

rest/serverless_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func TestServerlessSuspendDatabase(t *testing.T) {
319319
assert.NotNil(t, sc.dbConfigs["db"])
320320

321321
// Update config in bucket to see if unsuspending check for updates
322+
sc.dbConfigs["db"].EnableXattrs = base.BoolPtr(true) // xattrs must be enabled
322323
cas, err := sc.BootstrapContext.UpdateConfig(base.TestCtx(t), tb.GetName(), sc.Config.Bootstrap.ConfigGroupID, "db", func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) {
323324
config := sc.dbConfigs["db"].ToDatabaseConfig()
324325
config.cfgCas = bucketDbConfig.cfgCas

0 commit comments

Comments
 (0)