(t *testing.T)
| 2493 | } |
| 2494 | |
| 2495 | func 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 | |
| 2535 | func TestDocIDs(t *testing.T) { |
| 2536 | tests := []struct { |
nothing calls this directly
no test coverage detected