(t *testing.T)
| 846 | } |
| 847 | |
| 848 | func TestFetchRevisionBackupWithCollectionAccess(t *testing.T) { |
| 849 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 850 | |
| 851 | db, ctx := setupTestDB(t) |
| 852 | defer db.Close(ctx) |
| 853 | |
| 854 | auth := db.Authenticator(ctx) |
| 855 | |
| 856 | // Create a user who have access to channel ABC. |
| 857 | userAlice, err := auth.NewUser("alice", "pass", base.SetOf("ABC")) |
| 858 | require.NoError(t, err, "Error creating user") |
| 859 | |
| 860 | userBob, err := auth.NewUser("bob", "pass", base.SetOf("NBC")) |
| 861 | require.NoError(t, err, "Error creating user") |
| 862 | |
| 863 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 864 | collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout) |
| 865 | |
| 866 | // Create the first revision of doc1. |
| 867 | rev1Body := Body{ |
| 868 | "k1": "v1", |
| 869 | "channels": []string{"ABC"}, |
| 870 | } |
| 871 | rev1ID, _, err := collection.Put(ctx, "doc1", rev1Body) |
| 872 | require.NoError(t, err, "Error creating doc") |
| 873 | |
| 874 | // create the second revision of doc1. |
| 875 | rev2Body := Body{ |
| 876 | "k2": "v2", |
| 877 | "channels": []string{"ABC"}, |
| 878 | BodyRev: rev1ID, |
| 879 | } |
| 880 | _, _, err = collection.Put(ctx, "doc1", rev2Body) |
| 881 | require.NoError(t, err, "Error creating doc") |
| 882 | |
| 883 | // Flush the revision cache, this can be removed pending CBG-4542 |
| 884 | db.FlushRevisionCacheForTest() |
| 885 | |
| 886 | // Try with a user who has access to this revision. |
| 887 | collection.user = userAlice |
| 888 | body, err := collection.Get1xRevBody(ctx, "doc1", rev1ID, true, nil) |
| 889 | require.NoError(t, err, "Error getting 1x rev body") |
| 890 | |
| 891 | _, rev1Digest := ParseRevID(ctx, rev1ID) |
| 892 | |
| 893 | var interfaceListChannels []any |
| 894 | interfaceListChannels = append(interfaceListChannels, "ABC") |
| 895 | bodyExpected := Body{ |
| 896 | "k1": "v1", |
| 897 | "channels": interfaceListChannels, |
| 898 | BodyRevisions: Revisions{ |
| 899 | RevisionsStart: 1, |
| 900 | RevisionsIds: []string{rev1Digest}, |
| 901 | }, |
| 902 | BodyId: "doc1", |
| 903 | BodyRev: rev1ID, |
| 904 | } |
| 905 | require.Equal(t, bodyExpected, body) |
nothing calls this directly
no test coverage detected