mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 13:08:17 -05:00
Added groups and collection and users checks.
This commit is contained in:
parent
313dbc8616
commit
9b8a15193d
@ -445,7 +445,25 @@ public class OrganizationUserRepositoryTests
|
||||
CreationDate = requestTime
|
||||
});
|
||||
|
||||
var collection = await collectionRepository.CreateAsync(new Collection
|
||||
var collection1 = await collectionRepository.CreateAsync(new Collection
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Name = "Test Collection",
|
||||
ExternalId = "external-collection-1",
|
||||
CreationDate = requestTime,
|
||||
RevisionDate = requestTime
|
||||
});
|
||||
var collection2 = await collectionRepository.CreateAsync(new Collection
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Name = "Test Collection",
|
||||
ExternalId = "external-collection-1",
|
||||
CreationDate = requestTime,
|
||||
RevisionDate = requestTime
|
||||
});
|
||||
var collection3 = await collectionRepository.CreateAsync(new Collection
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
@ -455,13 +473,28 @@ public class OrganizationUserRepositoryTests
|
||||
RevisionDate = requestTime
|
||||
});
|
||||
|
||||
var group = await groupRepository.CreateAsync(new Group
|
||||
var group1 = await groupRepository.CreateAsync(new Group
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Name = "Test Group",
|
||||
ExternalId = "external-group-1"
|
||||
});
|
||||
var group2 = await groupRepository.CreateAsync(new Group
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Name = "Test Group",
|
||||
ExternalId = "external-group-1"
|
||||
});
|
||||
var group3 = await groupRepository.CreateAsync(new Group
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Name = "Test Group",
|
||||
ExternalId = "external-group-1"
|
||||
});
|
||||
|
||||
|
||||
var orgUserCollection = new List<CreateOrganizationUser>
|
||||
{
|
||||
@ -482,19 +515,85 @@ public class OrganizationUserRepositoryTests
|
||||
[
|
||||
new CollectionAccessSelection
|
||||
{
|
||||
Id = collection.Id,
|
||||
Id = collection1.Id,
|
||||
ReadOnly = true,
|
||||
HidePasswords = false,
|
||||
Manage = false
|
||||
}
|
||||
],
|
||||
Groups = [group.Id]
|
||||
Groups = [group1.Id]
|
||||
},
|
||||
new()
|
||||
{
|
||||
OrganizationUser = new OrganizationUser
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Email = "test-user@test.com",
|
||||
Status = OrganizationUserStatusType.Invited,
|
||||
Type = OrganizationUserType.Owner,
|
||||
ExternalId = "externalid-1",
|
||||
Permissions = CoreHelpers.ClassToJsonData(new Permissions()),
|
||||
AccessSecretsManager = false
|
||||
},
|
||||
Collections =
|
||||
[
|
||||
new CollectionAccessSelection
|
||||
{
|
||||
Id = collection2.Id,
|
||||
ReadOnly = true,
|
||||
HidePasswords = false,
|
||||
Manage = false
|
||||
}
|
||||
],
|
||||
Groups = [group2.Id]
|
||||
},
|
||||
new()
|
||||
{
|
||||
OrganizationUser = new OrganizationUser
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
OrganizationId = organization.Id,
|
||||
Email = "test-user@test.com",
|
||||
Status = OrganizationUserStatusType.Invited,
|
||||
Type = OrganizationUserType.Owner,
|
||||
ExternalId = "externalid-1",
|
||||
Permissions = CoreHelpers.ClassToJsonData(new Permissions()),
|
||||
AccessSecretsManager = false
|
||||
},
|
||||
Collections =
|
||||
[
|
||||
new CollectionAccessSelection
|
||||
{
|
||||
Id = collection3.Id,
|
||||
ReadOnly = true,
|
||||
HidePasswords = false,
|
||||
Manage = false
|
||||
}
|
||||
],
|
||||
Groups = [group3.Id]
|
||||
}
|
||||
};
|
||||
|
||||
await organizationUserRepository.CreateManyAsync(orgUserCollection);
|
||||
|
||||
var orgUser = await organizationUserRepository.GetDetailsByIdAsync(orgUserCollection.First().OrganizationUser.Id);
|
||||
Assert.Equal(orgUserCollection.First().OrganizationUser.Id, orgUser.Id);
|
||||
var orgUser1 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[0].OrganizationUser.Id);
|
||||
var group1Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[0].OrganizationUser.Id);
|
||||
Assert.Equal(orgUserCollection[0].OrganizationUser.Id, orgUser1.OrganizationUser.Id);
|
||||
Assert.Equal(collection1.Id, orgUser1.Collections.First().Id);
|
||||
Assert.Equal(group1.Id, group1Database.First());
|
||||
|
||||
|
||||
var orgUser2 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[1].OrganizationUser.Id);
|
||||
var group2Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[1].OrganizationUser.Id);
|
||||
Assert.Equal(orgUserCollection[1].OrganizationUser.Id, orgUser2.OrganizationUser.Id);
|
||||
Assert.Equal(collection2.Id, orgUser2.Collections.First().Id);
|
||||
Assert.Equal(group2.Id, group2Database.First());
|
||||
|
||||
var orgUser3 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[2].OrganizationUser.Id);
|
||||
var group3Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[2].OrganizationUser.Id);
|
||||
Assert.Equal(orgUserCollection[2].OrganizationUser.Id, orgUser3.OrganizationUser.Id);
|
||||
Assert.Equal(collection3.Id, orgUser3.Collections.First().Id);
|
||||
Assert.Equal(group3.Id, group3Database.First());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user