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

Function TestGetUserDocAccessMultiChannel

rest/diagnostic_doc_api_test.go:652–683  ·  view source on GitHub ↗

put doc in multiple channels, remove from some channels, assert response gets right sequences for each channels

(t *testing.T)

Source from the content-addressed store, hash-verified

650
651// put doc in multiple channels, remove from some channels, assert response gets right sequences for each channels
652func TestGetUserDocAccessMultiChannel(t *testing.T) {
653 rt := NewRestTester(t, &RestTesterConfig{SyncFn: `function(doc) {channel(doc.channel);}`})
654 defer rt.Close()
655 userGrant := userGrant{
656 user: "alice",
657 adminChannels: map[string][]string{
658 "{{.keyspace}}": {"A", "B", "C"},
659 },
660 }
661 userGrant.request(rt)
662
663 version := rt.PutDoc("doc1", `{"channel":["A"]}`)
664 updatedVersion := rt.UpdateDoc("doc1", version, `{"channel":["B", "A"]}`)
665 updatedVersion = rt.UpdateDoc("doc1", updatedVersion, `{"channel":["C", "B"]}`)
666
667 // assert sequences are registered correctly
668 expectedOutput := `{"doc1": {"A": { "entries" : ["2-4"]}, "B": { "entries" : ["3-0"]}, "C": { "entries" : ["4-0"]} }}`
669 response := rt.SendDiagnosticRequest(http.MethodGet,
670 "/{{.keyspace}}/_user/alice?docids=doc1", ``)
671 RequireStatus(rt.TB(), response, http.StatusOK)
672 require.JSONEq(rt.TB(), rt.mustTemplateResource(expectedOutput), response.BodyString())
673
674 // remove all channels
675 _ = rt.UpdateDoc("doc1", updatedVersion, `{"channel":[]}`)
676
677 // assert sequences spans end here
678 expectedOutput = `{"doc1": {"A": { "entries" : ["2-4"]}, "B": { "entries" : ["3-5"]}, "C": { "entries" : ["4-5"]} }}`
679 response = rt.SendDiagnosticRequest(http.MethodGet,
680 "/{{.keyspace}}/_user/alice?docids=doc1", ``)
681 RequireStatus(rt.TB(), response, http.StatusOK)
682 require.JSONEq(rt.TB(), rt.mustTemplateResource(expectedOutput), response.BodyString())
683}
684
685// give user access to chanA through admin API and role, remove admin API assignment, and assert access span is admin assignment to 0
686func TestGetUserDocAccessContinuousRoleAdminAPI(t *testing.T) {

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
requestMethod · 0.95
PutDocMethod · 0.95
UpdateDocMethod · 0.95
SendDiagnosticRequestMethod · 0.95
TBMethod · 0.95
mustTemplateResourceMethod · 0.95
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
BodyStringMethod · 0.80

Tested by

no test coverage detected