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

Function TestRoleAccessChanges

rest/role_api_test.go:296–429  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

294}
295
296func TestRoleAccessChanges(t *testing.T) {
297
298 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAccess, base.KeyCRUD, base.KeyChanges)
299
300 rtConfig := RestTesterConfig{SyncFn: `function(doc) {role(doc.user, doc.role);channel(doc.channel)}`}
301 rt := NewRestTester(t,
302 &rtConfig)
303 defer rt.Close()
304 ds := rt.GetSingleDataStore()
305 c := ds.CollectionName()
306 s := ds.ScopeName()
307
308 ctx := rt.Context()
309 a := rt.ServerContext().Database(ctx, "db").Authenticator(ctx)
310 guest, err := a.GetUser("")
311 require.NoError(t, err)
312
313 guest.SetDisabled(false)
314 err = a.Save(guest)
315 assert.NoError(t, err)
316
317 rt.CreateUser("alice", []string{"alpha"})
318 rt.CreateUser("zegpold", []string{"beta"})
319
320 response := rt.SendAdminRequest("PUT", "/db/_role/hipster", GetRolePayload(t, "hipster", ds, []string{"gamma"}))
321 RequireStatus(t, response, 201)
322
323 // Create some docs in the channels:
324 cacheWaiter := rt.ServerContext().Database(ctx, "db").NewDCPCachingCountWaiter(t)
325 cacheWaiter.Add(1)
326 response = rt.SendRequest("PUT", "/{{.keyspace}}/fashion", `{"user":"alice","role":["role:hipster","role:bogus"]}`)
327 RequireStatus(t, response, 201)
328 var body db.Body
329 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body))
330 assert.Equal(t, true, body["ok"])
331 fashionRevID := body["rev"].(string)
332
333 roleGrantSequence := rt.GetDocumentSequence("fashion")
334
335 cacheWaiter.Add(4)
336 RequireStatus(t, rt.SendRequest("PUT", "/{{.keyspace}}/g1", `{"channel":"gamma"}`), 201)
337 RequireStatus(t, rt.SendRequest("PUT", "/{{.keyspace}}/a1", `{"channel":"alpha"}`), 201)
338 RequireStatus(t, rt.SendRequest("PUT", "/{{.keyspace}}/b1", `{"channel":"beta"}`), 201)
339 RequireStatus(t, rt.SendRequest("PUT", "/{{.keyspace}}/d1", `{"channel":"delta"}`), 201)
340
341 // Check user access:
342 alice, err := a.GetUser("alice")
343 require.NoError(t, err)
344 chs, err := alice.InheritedCollectionChannels(s, c)
345 require.NoError(t, err)
346 assert.Equal(t,
347 channels.TimedSet{
348 "!": channels.NewVbSimpleSequence(1),
349 "alpha": channels.NewVbSimpleSequence(alice.Sequence()),
350 "gamma": channels.NewVbSimpleSequence(roleGrantSequence),
351 }, chs)
352
353 assert.Equal(t,

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
ContextMethod · 0.95
ServerContextMethod · 0.95
CreateUserMethod · 0.95
SendAdminRequestMethod · 0.95
SendRequestMethod · 0.95
GetDocumentSequenceMethod · 0.95
GetChangesMethod · 0.95
SetUpTestLoggingFunction · 0.92
JSONUnmarshalFunction · 0.92
NewVbSimpleSequenceFunction · 0.92

Tested by

no test coverage detected