diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs index a44b13bc6c..23d4a532b6 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Shouldly; +using Volo.Abp.Data; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -29,6 +30,7 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests(); CurrentTenant = GetRequiredService(); UnitOfWorkManager = GetRequiredService(); + DataFilter = GetRequiredService(); } [Fact] public virtual async Task Tenant_Connection_Should_Not_See_Host_Rows() { + // Disables IMultiTenant before querying so this test fails if connection routing is + // broken (a tenant context unexpectedly hitting the host db) rather than being masked + // by the data filter. var probeEmail = $"infra-host-{Guid.NewGuid():N}@abp.io"; + Guid hostUserId; using (CurrentTenant.Change(null)) using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) { var hostUser = new IdentityUser(Guid.NewGuid(), $"infra-host-{Guid.NewGuid():N}", probeEmail, null); await IdentityUserRepository.InsertAsync(hostUser); + hostUserId = hostUser.Id; + await uow.CompleteAsync(); + } + + using (CurrentTenant.Change(TenantAId)) + using (DataFilter.Disable()) + using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) + { + (await IdentityUserRepository.GetListAsync()).ShouldNotContain(u => u.Id == hostUserId); await uow.CompleteAsync(); } using (CurrentTenant.Change(TenantAId)) { - var foundInTenantA = await IdentityUserManager.FindByEmailAsync(probeEmail); - foundInTenantA.ShouldBeNull(); + (await IdentityUserManager.FindByEmailAsync(probeEmail)).ShouldBeNull(); } } @@ -62,19 +77,28 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests()) + using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) + { + (await IdentityUserRepository.GetListAsync()).ShouldNotContain(u => u.Id == tenantUserId); await uow.CompleteAsync(); } using (CurrentTenant.Change(null)) { - var foundInHost = await IdentityUserManager.FindByEmailAsync(probeEmail); - foundInHost.ShouldBeNull(); + (await IdentityUserManager.FindByEmailAsync(probeEmail)).ShouldBeNull(); } } @@ -82,19 +106,28 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests()) + using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) + { + (await IdentityUserRepository.GetListAsync()).ShouldNotContain(u => u.Id == tenantBUserId); + await uow.CompleteAsync(); + } + + using (CurrentTenant.Change(TenantAId)) { - var foundInB = await IdentityUserManager.FindByEmailAsync(probeEmail); - foundInB.ShouldBeNull(); + (await IdentityUserManager.FindByEmailAsync(probeEmail)).ShouldBeNull(); } }