diff --git a/auth/auth_test.go b/auth/auth_test.go index 8a063d7f86..5e2da52078 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -402,7 +402,12 @@ func TestRebuildUserChannels(t *testing.T) { user2, err := auth.GetUser("testUser") assert.NoError(t, err) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit1", "derived1", "derived2", "!"), 1), user2.Channels()) + expected := ch.TimedSet{ + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.DynamicGrant}, + "explicit1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.AdminGrant}, + "derived1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.DynamicGrant}, + "derived2": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.DynamicGrant}} + assert.Equal(t, expected, user2.Channels()) } func TestRebuildUserChannelsMultiCollection(t *testing.T) { @@ -430,8 +435,15 @@ func TestRebuildUserChannelsMultiCollection(t *testing.T) { user2, err := auth.GetUser("testUser") assert.NoError(t, err) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit1", "derived1", "derived2", "!"), 1), user2.Channels()) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit2", "derived3", "derived4", "!"), 1), user2.CollectionChannels("scope1", "collection1")) + + assert.Equal(t, ch.TimedSet{"explicit1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}, + "derived1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "derived2": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}}, user2.Channels()) + assert.Equal(t, ch.TimedSet{"explicit2": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}, + "derived3": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "derived4": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}}, user2.CollectionChannels("scope1", "collection1")) } func TestRebuildUserChannelsNamedCollection(t *testing.T) { @@ -454,11 +466,15 @@ func TestRebuildUserChannelsNamedCollection(t *testing.T) { err = auth.InvalidateChannels("testUser", true, "scope1", "collection1", 2) assert.NoError(t, err) - + expected := ch.TimedSet{ + "derived4": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "derived3": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "explicit2": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}} user2, err := auth.GetUser("testUser") assert.NoError(t, err) assert.Equal(t, ch.TimedSet(nil), user2.Channels()) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit2", "derived3", "derived4", "!"), 1), user2.CollectionChannels("scope1", "collection1")) + assert.Equal(t, expected, user2.CollectionChannels("scope1", "collection1")) } // Test cases @@ -485,7 +501,12 @@ func TestRebuildRoleChannels(t *testing.T) { role2, err := auth.GetRole("testRole") assert.Equal(t, nil, err) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit1", "derived1", "derived2", "!"), 1), role2.Channels()) + expected := ch.TimedSet{ + "derived1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "derived2": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.DynamicGrant}, + "explicit1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}} + assert.Equal(t, expected, role2.Channels()) } func TestRebuildChannelsError(t *testing.T) { @@ -526,8 +547,10 @@ func TestRebuildUserRoles(t *testing.T) { // Retrieve the user, triggers initial build of roles user1, err := auth.GetUser("testUser") assert.Equal(t, nil, err) - expected := ch.AtSequence(base.SetOf("role1", "role3"), 1) - expected.AddChannel("role2", 3, ch.AdminGrant) + expected := ch.TimedSet{ + "role3": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}, + "role1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}} + expected.AddChannel("role2", 3, "") assert.Equal(t, expected, user1.RoleNames()) // Invalidate the roles, triggers rebuild @@ -536,8 +559,11 @@ func TestRebuildUserRoles(t *testing.T) { user2, err := auth.GetUser("testUser") assert.Equal(t, nil, err) - expected = ch.AtSequence(base.SetOf("role1", "role3"), 1) - expected.AddChannel("role2", 3, ch.AdminGrant) + expected = ch.TimedSet{ + "role3": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}, + "role1": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(1), Source: ch.AdminGrant}} + + expected.AddChannel("role2", 3, "") assert.Equal(t, expected, user2.RoleNames()) } @@ -567,10 +593,12 @@ func TestRoleInheritance(t *testing.T) { user2, err := auth.GetUser("arthur") assert.Equal(t, nil, err) log.Printf("Channels = %s", user2.Channels()) - assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "!", "britain"), 1), user2.Channels()) assert.Equal(t, ch.TimedSet{ - "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1)}, - "britain": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1)}, + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.DynamicGrant}, + "britain": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.AdminGrant}}, user2.Channels()) + assert.Equal(t, ch.TimedSet{ + "!": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.DynamicGrant}, + "britain": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x1), Source: ch.AdminGrant}, "dull": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x3)}, "duller": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x3)}, "dullest": ch.TimedSetEntry{VbSequence: ch.NewVbSimpleSequence(0x3)}, diff --git a/db/database_test.go b/db/database_test.go index 15f26d9447..78f2b978e3 100644 --- a/db/database_test.go +++ b/db/database_test.go @@ -1546,10 +1546,12 @@ func TestAccessFunctionDb(t *testing.T) { user, err = authenticator.GetUser("naomi") assert.NoError(t, err, "GetUser") - expected := channels.AtSequence(channels.BaseSetOf(t, "Hulu", "Netflix", "!"), 1) + expected := channels.TimedSet{"Hulu": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(1), Source: channels.DynamicGrant}, + "Netflix": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(1), Source: channels.AdminGrant}, + "!": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(1), Source: channels.DynamicGrant}} assert.Equal(t, expected, user.CollectionChannels(collection.ScopeName, collection.Name)) - expected.AddChannel("CrunchyRoll", 2, "") + expected.AddChannel("CrunchyRoll", 2, channels.AdminGrant) assert.Equal(t, expected, user.InheritedCollectionChannels(collection.ScopeName, collection.Name)) } diff --git a/docs/api/components/schemas.yaml b/docs/api/components/schemas.yaml index 1bd99638a4..6f98ecd657 100644 --- a/docs/api/components/schemas.yaml +++ b/docs/api/components/schemas.yaml @@ -2525,10 +2525,9 @@ AllUserChannels: UpdatedAt: type: integer description: Unix timestamp of last update - admin_assigned: - type: boolean - description: Whether a channel was assigned through admin_channels or not - + source: + type: string + description: Either JWT, Admin or Dynamic. dynamic_grants: description: |- Channels assigned to the user through the sync function. @@ -2544,7 +2543,9 @@ AllUserChannels: UpdatedAt: type: integer description: Unix timestamp of last update - + source: + type: string + description: Either JWT, Admin or Dynamic. jwt_grants: description: |- Channels assigned to the user through JWT. @@ -2560,7 +2561,9 @@ AllUserChannels: UpdatedAt: type: integer description: Unix timestamp of last update - + source: + type: string + description: Either JWT, Admin or Dynamic. admin_role_grants: description: |- Channels assigned to the user through the admin API, by assigning a role to the user through admin_roles, @@ -2577,8 +2580,9 @@ AllUserChannels: UpdatedAt: type: integer description: Unix timestamp of last update - - + source: + type: string + description: Either JWT, Admin or Dynamic. dynamic_role_grants: description: |- Channels assigned to the user through roles assigned using the sync function. Does not include historic roles. @@ -2594,5 +2598,6 @@ AllUserChannels: UpdatedAt: type: integer description: Unix timestamp of last update - - + source: + type: string + description: Either JWT, Admin or Dynamic. diff --git a/docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml b/docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml index 5b69ece930..b1d65abbb6 100644 --- a/docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml +++ b/docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml @@ -25,7 +25,6 @@ get: description: The channels the document has been in. type: array items: - sequences: description: The sequence number that document was added to the channel. type: string example: "28-48" diff --git a/rest/user_api_test.go b/rest/user_api_test.go index 08d23ef6e6..3b4e2ce5cb 100644 --- a/rest/user_api_test.go +++ b/rest/user_api_test.go @@ -303,7 +303,7 @@ func TestUserAPI(t *testing.T) { assert.Equal(t, "snej", user.Name()) assert.Equal(t, "jens@couchbase.com", user.Email()) assert.Equal(t, channels.TimedSet{"bar": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(0x1), Source: channels.AdminGrant}, - "foo": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(0x1)}}, user.CollectionExplicitChannels(s, c)) + "foo": channels.TimedSetEntry{VbSequence: channels.NewVbSimpleSequence(0x1), Source: channels.AdminGrant}}, user.CollectionExplicitChannels(s, c)) assert.True(t, user.Authenticate("letmein")) // Change the password and verify it: