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

Function TestAccessFunctionDb

db/database_test.go:2495–2533  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2493}
2494
2495func TestAccessFunctionDb(t *testing.T) {
2496
2497 db, ctx := setupTestDB(t)
2498 defer db.Close(ctx)
2499
2500 authenticator := db.Authenticator(ctx)
2501 user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "Netflix"))
2502 require.NoError(t, err)
2503 user.SetExplicitRoles(channels.TimedSet{"animefan": channels.NewVbSimpleSequence(1), "tumblr": channels.NewVbSimpleSequence(1)}, 1)
2504 assert.NoError(t, authenticator.Save(user), "Save")
2505
2506 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2507
2508 _, err = collection.UpdateSyncFun(ctx, `function(doc){access(doc.users,doc.userChannels);}`)
2509 require.NoError(t, err)
2510
2511 body := Body{"users": []string{"naomi"}, "userChannels": []string{"Hulu"}}
2512 _, _, err = collection.Put(ctx, "doc1", body)
2513 assert.NoError(t, err, "")
2514
2515 body = Body{"users": []string{"role:animefan"}, "userChannels": []string{"CrunchyRoll"}}
2516 _, _, err = collection.Put(ctx, "doc2", body)
2517 assert.NoError(t, err, "")
2518
2519 // Create the role _after_ creating the documents, to make sure the previously-indexed access
2520 // privileges are applied.
2521 role, _ := authenticator.NewRole("animefan", nil)
2522 assert.NoError(t, authenticator.Save(role))
2523
2524 user, err = authenticator.GetUser("naomi")
2525 assert.NoError(t, err, "GetUser")
2526 expected := channels.AtSequence(channels.BaseSetOf(t, "Hulu", "Netflix", "!"), 1)
2527 assert.Equal(t, expected, user.CollectionChannels(collection.ScopeName, collection.Name))
2528
2529 expected.AddChannel("CrunchyRoll", 2)
2530 channels, err := user.InheritedCollectionChannels(collection.ScopeName, collection.Name)
2531 require.NoError(t, err)
2532 assert.Equal(t, expected, channels)
2533}
2534
2535func TestDocIDs(t *testing.T) {
2536 tests := []struct {

Callers

nothing calls this directly

Calls 15

SetExplicitRolesMethod · 0.95
BaseSetOfFunction · 0.92
NewVbSimpleSequenceFunction · 0.92
AtSequenceFunction · 0.92
setupTestDBFunction · 0.85
NewUserMethod · 0.80
SaveMethod · 0.80
UpdateSyncFunMethod · 0.80
NewRoleMethod · 0.80
GetUserMethod · 0.80
AddChannelMethod · 0.80

Tested by

no test coverage detected