mirror of
https://github.com/bitwarden/server.git
synced 2024-12-04 14:13:28 +01:00
f2180aa7b7
* Add HasVerifiedDomainsAsync method to IOrganizationDomainService * Add GetManagedUserIdsByOrganizationIdAsync method to IOrganizationUserRepository and the corresponding queries * Fix case on the sproc OrganizationUser_ReadManagedIdsByOrganizationId parameter * Update the EF query to use the Email from the User table * dotnet format * Fix IOrganizationDomainService.HasVerifiedDomainsAsync by checking that domains have been Verified and add unit tests * Rename IOrganizationUserRepository.GetManagedUserIdsByOrganizationAsync * Fix domain queries * Add OrganizationUserRepository integration tests * Add summary to IOrganizationDomainService.HasVerifiedDomainsAsync * chore: Rename IOrganizationUserRepository.GetManagedUserIdsByOrganizationAsync to GetManyIdsManagedByOrganizationIdAsync * Add IsManagedByAnyOrganizationAsync method to IUserRepository * Add integration tests for UserRepository.IsManagedByAnyOrganizationAsync * Refactor to IUserService.IsManagedByAnyOrganizationAsync and IOrganizationService.GetUsersOrganizationManagementStatusAsync * chore: Refactor IsManagedByAnyOrganizationAsync method in UserService * Refactor IOrganizationService.GetUsersOrganizationManagementStatusAsync to return IDictionary<Guid, bool> * Extract IOrganizationService.GetUsersOrganizationManagementStatusAsync into a query * Update comments in OrganizationDomainService to use proper capitalization * Move OrganizationDomainService to AdminConsole ownership and update namespace * feat: Add support for organization domains in enterprise plans * feat: Add HasOrganizationDomains property to OrganizationAbility class * refactor: Update GetOrganizationUsersManagementStatusQuery to use IApplicationCacheService * Remove HasOrganizationDomains and use UseSso to check if Organization can have Verified Domains * Refactor UserService.IsManagedByAnyOrganizationAsync to simply check the UseSso flag * Add TODO comment for replacing 'UseSso' organization ability on user verified domain checks * Bump date on migration script * Add indexes to OrganizationDomain table * Bump script migration date; Remove WITH ONLINE = ON from data migration.
102 lines
4.2 KiB
C#
102 lines
4.2 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Models.Data.Organizations;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Services;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|
|
|
[SutProviderCustomize]
|
|
public class GetOrganizationUsersManagementStatusQueryTests
|
|
{
|
|
[Theory, BitAutoData]
|
|
public async Task GetUsersOrganizationManagementStatusAsync_WithNoUsers_ReturnsEmpty(
|
|
Organization organization,
|
|
SutProvider<GetOrganizationUsersManagementStatusQuery> sutProvider)
|
|
{
|
|
var result = await sutProvider.Sut.GetUsersOrganizationManagementStatusAsync(organization.Id, new List<Guid>());
|
|
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetUsersOrganizationManagementStatusAsync_WithUseSsoEnabled_Success(
|
|
Organization organization,
|
|
ICollection<OrganizationUser> usersWithClaimedDomain,
|
|
SutProvider<GetOrganizationUsersManagementStatusQuery> sutProvider)
|
|
{
|
|
organization.Enabled = true;
|
|
organization.UseSso = true;
|
|
|
|
var userIdWithoutClaimedDomain = Guid.NewGuid();
|
|
var userIdsToCheck = usersWithClaimedDomain.Select(u => u.Id).Concat(new List<Guid> { userIdWithoutClaimedDomain }).ToList();
|
|
|
|
sutProvider.GetDependency<IApplicationCacheService>()
|
|
.GetOrganizationAbilityAsync(organization.Id)
|
|
.Returns(new OrganizationAbility(organization));
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
.GetManyByOrganizationWithClaimedDomainsAsync(organization.Id)
|
|
.Returns(usersWithClaimedDomain);
|
|
|
|
var result = await sutProvider.Sut.GetUsersOrganizationManagementStatusAsync(organization.Id, userIdsToCheck);
|
|
|
|
Assert.All(usersWithClaimedDomain, ou => Assert.True(result[ou.Id]));
|
|
Assert.False(result[userIdWithoutClaimedDomain]);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetUsersOrganizationManagementStatusAsync_WithUseSsoDisabled_ReturnsAllFalse(
|
|
Organization organization,
|
|
ICollection<OrganizationUser> usersWithClaimedDomain,
|
|
SutProvider<GetOrganizationUsersManagementStatusQuery> sutProvider)
|
|
{
|
|
organization.Enabled = true;
|
|
organization.UseSso = false;
|
|
|
|
var userIdWithoutClaimedDomain = Guid.NewGuid();
|
|
var userIdsToCheck = usersWithClaimedDomain.Select(u => u.Id).Concat(new List<Guid> { userIdWithoutClaimedDomain }).ToList();
|
|
|
|
sutProvider.GetDependency<IApplicationCacheService>()
|
|
.GetOrganizationAbilityAsync(organization.Id)
|
|
.Returns(new OrganizationAbility(organization));
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
.GetManyByOrganizationWithClaimedDomainsAsync(organization.Id)
|
|
.Returns(usersWithClaimedDomain);
|
|
|
|
var result = await sutProvider.Sut.GetUsersOrganizationManagementStatusAsync(organization.Id, userIdsToCheck);
|
|
|
|
Assert.All(result, r => Assert.False(r.Value));
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetUsersOrganizationManagementStatusAsync_WithDisabledOrganization_ReturnsAllFalse(
|
|
Organization organization,
|
|
ICollection<OrganizationUser> usersWithClaimedDomain,
|
|
SutProvider<GetOrganizationUsersManagementStatusQuery> sutProvider)
|
|
{
|
|
organization.Enabled = false;
|
|
|
|
var userIdWithoutClaimedDomain = Guid.NewGuid();
|
|
var userIdsToCheck = usersWithClaimedDomain.Select(u => u.Id).Concat(new List<Guid> { userIdWithoutClaimedDomain }).ToList();
|
|
|
|
sutProvider.GetDependency<IApplicationCacheService>()
|
|
.GetOrganizationAbilityAsync(organization.Id)
|
|
.Returns(new OrganizationAbility(organization));
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
.GetManyByOrganizationWithClaimedDomainsAsync(organization.Id)
|
|
.Returns(usersWithClaimedDomain);
|
|
|
|
var result = await sutProvider.Sut.GetUsersOrganizationManagementStatusAsync(organization.Id, userIdsToCheck);
|
|
|
|
Assert.All(result, r => Assert.False(r.Value));
|
|
}
|
|
}
|