MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestBulkDocsChangeToAccess

Function TestBulkDocsChangeToAccess

rest/access_test.go:501–542  ·  view source on GitHub ↗

TestBulkDocsChangeToAccess verifies that access() grants from one doc in a single bulk_docs request apply to subsequent docs in the same batch.

(t *testing.T)

Source from the content-addressed store, hash-verified

499
500// TestBulkDocsChangeToAccess verifies that access() grants from one doc in a single bulk_docs request apply to subsequent docs in the same batch.
501func TestBulkDocsChangeToAccess(t *testing.T) {
502 base.SetUpTestLogging(t, base.LevelInfo, base.KeyAccess)
503
504 rtConfig := RestTesterConfig{SyncFn: `
505 function(doc) {
506 if(doc.type == "setaccess") {
507 channel(doc.channel);
508 access(doc.owner, doc.channel);
509 } else {
510 requireAccess(doc.channel);
511 }
512 }`}
513 rt := NewRestTesterDefaultCollection(t, &rtConfig)
514 defer rt.Close()
515
516 ctx := rt.Context()
517 a := rt.ServerContext().Database(ctx, "db").Authenticator(ctx)
518 user, err := a.GetUser("")
519 assert.NoError(t, err)
520 user.SetDisabled(true)
521 err = a.Save(user)
522 assert.NoError(t, err)
523
524 // Create a test user
525 user, err = a.NewUser("user1", "letmein", nil)
526 assert.NoError(t, err)
527 assert.NoError(t, a.Save(user))
528
529 input := `{"docs": [{"_id": "bulk1", "type" : "setaccess", "owner":"user1" , "channel":"chan1"}, {"_id": "bulk2" , "channel":"chan1"}]}`
530 response := rt.SendUserRequest("POST", "/db/_bulk_docs", input, "user1")
531 RequireStatus(t, response, 201)
532
533 var docs []interface{}
534 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &docs))
535 require.Len(t, docs, 2)
536 assert.NotContains(t, response.BodyString(), `missing channel access`)
537 assert.NotContains(t, response.BodyString(), `"status":403"`)
538 assert.Contains(t, response.BodyString(), `"id":"bulk1"`)
539 assert.Contains(t, response.BodyString(), `"rev":"1-afbcffa8a4641a0f4dd94d3fc9593e74"`)
540 assert.Contains(t, response.BodyString(), `"id":"bulk2"`)
541 assert.Contains(t, response.BodyString(), `"rev":"1-4d79588b9fe9c38faae61f0c1b9471c0"`)
542}
543
544// Test _all_docs API call under different security scenarios
545func TestAllDocsAccessControl(t *testing.T) {

Callers

nothing calls this directly

Calls 15

SetUpTestLoggingFunction · 0.92
JSONUnmarshalFunction · 0.92
RequireStatusFunction · 0.85
ServerContextMethod · 0.80
GetUserMethod · 0.80
SaveMethod · 0.80
NewUserMethod · 0.80
SendUserRequestMethod · 0.80
BodyStringMethod · 0.80
CloseMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected