|
|
|
@ -1,11 +1,13 @@ |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Shouldly; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Shouldly; |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity; |
|
|
|
|
|
|
|
public class OrganizationUnitManager_Tests : AbpIdentityDomainTestBase |
|
|
|
@ -17,6 +19,7 @@ public class OrganizationUnitManager_Tests : AbpIdentityDomainTestBase |
|
|
|
private readonly ILookupNormalizer _lookupNormalizer; |
|
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
private readonly IGuidGenerator _guidGenerator; |
|
|
|
private readonly ICurrentTenant _currentTenant; |
|
|
|
public OrganizationUnitManager_Tests() |
|
|
|
{ |
|
|
|
_organizationUnitManager = GetRequiredService<OrganizationUnitManager>(); |
|
|
|
@ -26,6 +29,7 @@ public class OrganizationUnitManager_Tests : AbpIdentityDomainTestBase |
|
|
|
_testData = GetRequiredService<IdentityTestData>(); |
|
|
|
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
|
|
|
_guidGenerator = GetService<IGuidGenerator>(); |
|
|
|
_currentTenant = GetRequiredService<ICurrentTenant>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -117,4 +121,39 @@ public class OrganizationUnitManager_Tests : AbpIdentityDomainTestBase |
|
|
|
ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails: true); |
|
|
|
ou.Roles.FirstOrDefault(r => r.RoleId == adminRole.Id).ShouldBeNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Not_Create_Organization_Unit_With_Cross_Tenant_Parent() |
|
|
|
{ |
|
|
|
var hostOu = await _organizationUnitRepository.GetAsync("OU1"); |
|
|
|
|
|
|
|
using (_currentTenant.Change(Guid.NewGuid())) |
|
|
|
{ |
|
|
|
var newOu = new OrganizationUnit(_guidGenerator.Create(), "Cross", hostOu.Id, _currentTenant.Id); |
|
|
|
|
|
|
|
var ex = await Assert.ThrowsAsync<BusinessException>( |
|
|
|
async () => await _organizationUnitManager.CreateAsync(newOu)); |
|
|
|
|
|
|
|
ex.Code.ShouldBe(IdentityErrorCodes.OrganizationUnitParentTenantMismatch); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Not_Move_Organization_Unit_To_Cross_Tenant_Parent() |
|
|
|
{ |
|
|
|
var hostOu1 = await _organizationUnitRepository.GetAsync("OU1"); |
|
|
|
|
|
|
|
OrganizationUnit tenantOu; |
|
|
|
var tenantId = Guid.NewGuid(); |
|
|
|
using (_currentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
tenantOu = new OrganizationUnit(_guidGenerator.Create(), "TenantRoot", null, tenantId); |
|
|
|
await _organizationUnitManager.CreateAsync(tenantOu); |
|
|
|
|
|
|
|
var ex = await Assert.ThrowsAsync<BusinessException>( |
|
|
|
async () => await _organizationUnitManager.MoveAsync(tenantOu.Id, hostOu1.Id)); |
|
|
|
|
|
|
|
ex.Code.ShouldBe(IdentityErrorCodes.OrganizationUnitParentTenantMismatch); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|