|
6 | 6 | using Bit.Core.AdminConsole.Entities; |
7 | 7 | using Bit.Core.AdminConsole.Repositories; |
8 | 8 | using Bit.Core.Billing.Enums; |
| 9 | +using Bit.Core.Entities; |
9 | 10 | using Bit.Core.Enums; |
10 | 11 | using Bit.Core.Models.Data; |
11 | 12 | using Bit.Core.Platform.Push; |
@@ -114,4 +115,64 @@ public async Task CreateCollectionWithMultipleUsersAndVariedPermissions_Success( |
114 | 115 | Assert.NotEmpty(result.Item2.Groups); |
115 | 116 | Assert.NotEmpty(result.Item2.Users); |
116 | 117 | } |
| 118 | + |
| 119 | + [Fact] |
| 120 | + public async Task List_ExcludesDefaultUserCollections_IncludesGroupsAndUsers() |
| 121 | + { |
| 122 | + // Arrange |
| 123 | + var collectionRepository = _factory.GetService<ICollectionRepository>(); |
| 124 | + var groupRepository = _factory.GetService<IGroupRepository>(); |
| 125 | + |
| 126 | + var defaultCollection = new Collection |
| 127 | + { |
| 128 | + OrganizationId = _organization.Id, |
| 129 | + Name = "My Items", |
| 130 | + Type = CollectionType.DefaultUserCollection |
| 131 | + }; |
| 132 | + await collectionRepository.CreateAsync(defaultCollection, null, null); |
| 133 | + |
| 134 | + var group = await groupRepository.CreateAsync(new Group |
| 135 | + { |
| 136 | + OrganizationId = _organization.Id, |
| 137 | + Name = "Test Group", |
| 138 | + ExternalId = $"test-group-{Guid.NewGuid()}", |
| 139 | + }); |
| 140 | + |
| 141 | + var (_, user) = await OrganizationTestHelpers.CreateNewUserWithAccountAsync( |
| 142 | + _factory, |
| 143 | + _organization.Id, |
| 144 | + OrganizationUserType.User); |
| 145 | + |
| 146 | + var sharedCollection = await OrganizationTestHelpers.CreateCollectionAsync( |
| 147 | + _factory, |
| 148 | + _organization.Id, |
| 149 | + "Shared Collection with Access", |
| 150 | + externalId: "shared-collection-with-access", |
| 151 | + groups: |
| 152 | + [ |
| 153 | + new CollectionAccessSelection { Id = group.Id, ReadOnly = false, HidePasswords = false, Manage = true } |
| 154 | + ], |
| 155 | + users: |
| 156 | + [ |
| 157 | + new CollectionAccessSelection { Id = user.Id, ReadOnly = true, HidePasswords = true, Manage = false } |
| 158 | + ]); |
| 159 | + |
| 160 | + // Act |
| 161 | + var response = await _client.GetFromJsonAsync<ListResponseModel<CollectionResponseModel>>("public/collections"); |
| 162 | + |
| 163 | + // Assert |
| 164 | + Assert.NotNull(response); |
| 165 | + |
| 166 | + Assert.DoesNotContain(response.Data, c => c.Id == defaultCollection.Id); |
| 167 | + |
| 168 | + var collectionResponse = response.Data.First(c => c.Id == sharedCollection.Id); |
| 169 | + Assert.NotNull(collectionResponse.Groups); |
| 170 | + Assert.Single(collectionResponse.Groups); |
| 171 | + |
| 172 | + var groupResponse = collectionResponse.Groups.First(); |
| 173 | + Assert.Equal(group.Id, groupResponse.Id); |
| 174 | + Assert.False(groupResponse.ReadOnly); |
| 175 | + Assert.False(groupResponse.HidePasswords); |
| 176 | + Assert.True(groupResponse.Manage); |
| 177 | + } |
117 | 178 | } |
0 commit comments