1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

[PM-18527] - Fix allowing restored user to own multiple free orgs (#5444)

* Moved RestoreUserAsync and RestoreUsersAsync to Command.

* Fixing the bug.

* Added test for bulk method.

* Fixing sonar cube warning.

* SonarQube warning fix.

* Excluding org users we already have.

* Fixed misspelling. Added integration test for method.

* test had the misspelling as well 🤦

* Split out interface. Added admin and confirmed constraints.

* fixed queries and added xml comments and tests.
This commit is contained in:
Jared McCannon
2025-03-31 08:33:57 -05:00
committed by GitHub
parent 887332b436
commit 786b0edceb
18 changed files with 1298 additions and 710 deletions

View File

@ -196,4 +196,43 @@ public class OrganizationRepositoryTests
Assert.Single(sqlResult);
Assert.True(sqlResult.All(o => o.Name == org.Name));
}
[CiSkippedTheory, EfOrganizationAutoData]
public async Task GetManyByIdsAsync_Works_DataMatches(List<Organization> organizations,
SqlRepo.OrganizationRepository sqlOrganizationRepo,
List<EfRepo.OrganizationRepository> suts)
{
var returnedOrgs = new List<Organization>();
foreach (var sut in suts)
{
_ = await sut.CreateMany(organizations);
sut.ClearChangeTracking();
var efReturnedOrgs = await sut.GetManyByIdsAsync(organizations.Select(o => o.Id).ToList());
returnedOrgs.AddRange(efReturnedOrgs);
}
foreach (var organization in organizations)
{
var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);
returnedOrgs.Add(await sqlOrganizationRepo.GetByIdAsync(postSqlOrg.Id));
}
var orgIds = organizations.Select(o => o.Id).ToList();
var distinctReturnedOrgIds = returnedOrgs.Select(o => o.Id).Distinct().ToList();
Assert.Equal(orgIds.Count, distinctReturnedOrgIds.Count);
Assert.Equivalent(orgIds, distinctReturnedOrgIds);
// clean up
foreach (var organization in organizations)
{
await sqlOrganizationRepo.DeleteAsync(organization);
foreach (var sut in suts)
{
await sut.DeleteAsync(organization);
}
}
}
}