mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PM-1188] Server owner auth migration (#2825)
* [PM-1188] add sso project to auth * [PM-1188] move sso api models to auth * [PM-1188] fix sso api model namespace & imports * [PM-1188] move core files to auth * [PM-1188] fix core sso namespace & models * [PM-1188] move sso repository files to auth * [PM-1188] fix sso repo files namespace & imports * [PM-1188] move sso sql files to auth folder * [PM-1188] move sso test files to auth folders * [PM-1188] fix sso tests namespace & imports * [PM-1188] move auth api files to auth folder * [PM-1188] fix auth api files namespace & imports * [PM-1188] move auth core files to auth folder * [PM-1188] fix auth core files namespace & imports * [PM-1188] move auth email templates to auth folder * [PM-1188] move auth email folder back into shared directory * [PM-1188] fix auth email names * [PM-1188] move auth core models to auth folder * [PM-1188] fix auth model namespace & imports * [PM-1188] add entire Identity project to auth codeowners * [PM-1188] fix auth orm files namespace & imports * [PM-1188] move auth orm files to auth folder * [PM-1188] move auth sql files to auth folder * [PM-1188] move auth tests to auth folder * [PM-1188] fix auth test files namespace & imports * [PM-1188] move emergency access api files to auth folder * [PM-1188] fix emergencyaccess api files namespace & imports * [PM-1188] move emergency access core files to auth folder * [PM-1188] fix emergency access core files namespace & imports * [PM-1188] move emergency access orm files to auth folder * [PM-1188] fix emergency access orm files namespace & imports * [PM-1188] move emergency access sql files to auth folder * [PM-1188] move emergencyaccess test files to auth folder * [PM-1188] fix emergency access test files namespace & imports * [PM-1188] move captcha files to auth folder * [PM-1188] fix captcha files namespace & imports * [PM-1188] move auth admin files into auth folder * [PM-1188] fix admin auth files namespace & imports - configure mvc to look in auth folders for views * [PM-1188] remove extra imports and formatting * [PM-1188] fix ef auth model imports * [PM-1188] fix DatabaseContextModelSnapshot paths * [PM-1188] fix grant import in ef * [PM-1188] update sqlproj * [PM-1188] move missed sqlproj files * [PM-1188] move auth ef models out of auth folder * [PM-1188] fix auth ef models namespace * [PM-1188] remove auth ef models unused imports * [PM-1188] fix imports for auth ef models * [PM-1188] fix more ef model imports * [PM-1188] fix file encodings
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Test.AutoFixture.UserFixtures;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture.Relays;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
|
||||
internal class AuthRequestBuilder : ISpecimenBuilder
|
||||
{
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var type = request as Type;
|
||||
if (type == null || type != typeof(AuthRequest))
|
||||
{
|
||||
return new NoSpecimen();
|
||||
}
|
||||
|
||||
var fixture = new Fixture();
|
||||
fixture.Customizations.Insert(0, new MaxLengthStringRelay());
|
||||
var obj = fixture.WithAutoNSubstitutions().Create<AuthRequest>();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfAuthRequest : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new AuthRequestBuilder());
|
||||
fixture.Customizations.Add(new DeviceBuilder());
|
||||
fixture.Customizations.Add(new UserBuilder());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<AuthRequestRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<DeviceRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<UserRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfAuthRequestAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfAuthRequestAutoDataAttribute() : base(new SutProviderCustomization(), new EfAuthRequest())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class InlineEfAuthRequestAutoDataAttribute : InlineCustomAutoDataAttribute
|
||||
{
|
||||
public InlineEfAuthRequestAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||||
typeof(EfAuthRequest) }, values)
|
||||
{ }
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Test.AutoFixture.UserFixtures;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture.Relays;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
|
||||
internal class EmergencyAccessBuilder : ISpecimenBuilder
|
||||
{
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var type = request as Type;
|
||||
if (type == null || type != typeof(EmergencyAccess))
|
||||
{
|
||||
return new NoSpecimen();
|
||||
}
|
||||
|
||||
var fixture = new Fixture();
|
||||
fixture.Customizations.Insert(0, new MaxLengthStringRelay());
|
||||
var obj = fixture.Create<EmergencyAccess>();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfEmergencyAccess : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
// TODO: Make a base EF Customization with IgnoreVirtualMembers/GlobalSettings/All repos and inherit
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new EmergencyAccessBuilder());
|
||||
fixture.Customizations.Add(new UserBuilder());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<EmergencyAccessRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<UserRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfEmergencyAccessAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfEmergencyAccessAutoDataAttribute() : base(new SutProviderCustomization(), new EfEmergencyAccess())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class InlineEfEmergencyAccessAutoDataAttribute : InlineCustomAutoDataAttribute
|
||||
{
|
||||
public InlineEfEmergencyAccessAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||||
typeof(EfEmergencyAccess) }, values)
|
||||
{ }
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture.Relays;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
|
||||
internal class GrantBuilder : ISpecimenBuilder
|
||||
{
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var type = request as Type;
|
||||
if (type == null || type != typeof(Grant))
|
||||
{
|
||||
return new NoSpecimen();
|
||||
}
|
||||
|
||||
var fixture = new Fixture();
|
||||
fixture.Customizations.Insert(0, new MaxLengthStringRelay());
|
||||
var obj = fixture.WithAutoNSubstitutions().Create<Grant>();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfGrant : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new GrantBuilder());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<GrantRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfGrantAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfGrantAutoDataAttribute() : base(new SutProviderCustomization(), new EfGrant())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class InlineEfGrantAutoDataAttribute : InlineCustomAutoDataAttribute
|
||||
{
|
||||
public InlineEfGrantAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||||
typeof(EfGrant) }, values)
|
||||
{ }
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Auth.Models.Data;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
|
||||
internal class SsoConfigBuilder : ISpecimenBuilder
|
||||
{
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var type = request as Type;
|
||||
if (type == null || type != typeof(SsoConfig))
|
||||
{
|
||||
return new NoSpecimen();
|
||||
}
|
||||
|
||||
var fixture = new Fixture();
|
||||
var ssoConfig = fixture.WithAutoNSubstitutions().Create<SsoConfig>();
|
||||
var ssoConfigData = fixture.WithAutoNSubstitutions().Create<SsoConfigurationData>();
|
||||
ssoConfig.SetData(ssoConfigData);
|
||||
return ssoConfig;
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfSsoConfig : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new OrganizationBuilder());
|
||||
fixture.Customizations.Add(new SsoConfigBuilder());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<SsoConfigRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfSsoConfigAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfSsoConfigAutoDataAttribute() : base(new SutProviderCustomization(), new EfSsoConfig())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class InlineEfSsoConfigAutoDataAttribute : InlineCustomAutoDataAttribute
|
||||
{
|
||||
public InlineEfSsoConfigAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||||
typeof(EfSsoConfig) }, values)
|
||||
{ }
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using AutoFixture;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Test.AutoFixture.UserFixtures;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
|
||||
internal class EfSsoUser : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new UserBuilder());
|
||||
fixture.Customizations.Add(new OrganizationBuilder());
|
||||
fixture.Customize<SsoUser>(composer => composer.Without(ou => ou.Id));
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<SsoUserRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<UserRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfSsoUserAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfSsoUserAutoDataAttribute() : base(new SutProviderCustomization(), new EfSsoUser())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class InlineEfSsoUserAutoDataAttribute : InlineCustomAutoDataAttribute
|
||||
{
|
||||
public InlineEfSsoUserAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||||
typeof(EfSsoUser) }, values)
|
||||
{ }
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfAuthRepo = Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlAuthRepo = Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories;
|
||||
|
||||
public class AuthRequestRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfAuthRequestAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
AuthRequest authRequest,
|
||||
AuthRequestCompare equalityComparer,
|
||||
List<EfAuthRepo.AuthRequestRepository> suts,
|
||||
SqlAuthRepo.AuthRequestRepository sqlAuthRequestRepo,
|
||||
User user,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
{
|
||||
authRequest.ResponseDeviceId = null;
|
||||
var savedAuthRequests = new List<AuthRequest>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
authRequest.UserId = efUser.Id;
|
||||
|
||||
var postEfAuthRequest = await sut.CreateAsync(authRequest);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedAuthRequest = await sut.GetByIdAsync(postEfAuthRequest.Id);
|
||||
savedAuthRequests.Add(savedAuthRequest);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
authRequest.UserId = sqlUser.Id;
|
||||
var sqlAuthRequest = await sqlAuthRequestRepo.CreateAsync(authRequest);
|
||||
var savedSqlAuthRequest = await sqlAuthRequestRepo.GetByIdAsync(sqlAuthRequest.Id);
|
||||
savedAuthRequests.Add(savedSqlAuthRequest);
|
||||
|
||||
var distinctItems = savedAuthRequests.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfAuthRepo = Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlAuthRepo = Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories;
|
||||
|
||||
public class EmergencyAccessRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfEmergencyAccessAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
EmergencyAccess emergencyAccess,
|
||||
List<User> users,
|
||||
EmergencyAccessCompare equalityComparer,
|
||||
List<EfAuthRepo.EmergencyAccessRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlAuthRepo.EmergencyAccessRepository sqlEmergencyAccessRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
{
|
||||
var savedEmergencyAccesss = new List<EmergencyAccess>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
for (int j = 0; j < users.Count; j++)
|
||||
{
|
||||
users[j] = await efUserRepos[i].CreateAsync(users[j]);
|
||||
}
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
emergencyAccess.GrantorId = users[0].Id;
|
||||
emergencyAccess.GranteeId = users[0].Id;
|
||||
var postEfEmergencyAccess = await sut.CreateAsync(emergencyAccess);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEmergencyAccess = await sut.GetByIdAsync(postEfEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedEmergencyAccess);
|
||||
}
|
||||
|
||||
for (int j = 0; j < users.Count; j++)
|
||||
{
|
||||
users[j] = await sqlUserRepo.CreateAsync(users[j]);
|
||||
}
|
||||
|
||||
emergencyAccess.GrantorId = users[0].Id;
|
||||
emergencyAccess.GranteeId = users[0].Id;
|
||||
var sqlEmergencyAccess = await sqlEmergencyAccessRepo.CreateAsync(emergencyAccess);
|
||||
var savedSqlEmergencyAccess = await sqlEmergencyAccessRepo.GetByIdAsync(sqlEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedSqlEmergencyAccess);
|
||||
|
||||
var distinctItems = savedEmergencyAccesss.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Auth.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
|
||||
public class AuthRequestCompare : IEqualityComparer<AuthRequest>
|
||||
{
|
||||
public bool Equals(AuthRequest x, AuthRequest y)
|
||||
{
|
||||
return x.AccessCode == y.AccessCode &&
|
||||
x.MasterPasswordHash == y.MasterPasswordHash &&
|
||||
x.PublicKey == y.PublicKey &&
|
||||
x.RequestDeviceIdentifier == y.RequestDeviceIdentifier &&
|
||||
x.RequestDeviceType == y.RequestDeviceType &&
|
||||
x.RequestIpAddress == y.RequestIpAddress;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] AuthRequest obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Auth.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
|
||||
public class EmergencyAccessCompare : IEqualityComparer<EmergencyAccess>
|
||||
{
|
||||
public bool Equals(EmergencyAccess x, EmergencyAccess y)
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.KeyEncrypted == y.KeyEncrypted &&
|
||||
x.Type == y.Type &&
|
||||
x.Status == y.Status &&
|
||||
x.WaitTimeDays == y.WaitTimeDays &&
|
||||
x.RecoveryInitiatedDate == y.RecoveryInitiatedDate &&
|
||||
x.LastNotificationDate == y.LastNotificationDate;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] EmergencyAccess obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Auth.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
|
||||
public class GrantCompare : IEqualityComparer<Grant>
|
||||
{
|
||||
public bool Equals(Grant x, Grant y)
|
||||
{
|
||||
return x.Key == y.Key &&
|
||||
x.Type == y.Type &&
|
||||
x.SubjectId == y.SubjectId &&
|
||||
x.ClientId == y.ClientId &&
|
||||
x.Description == y.Description &&
|
||||
x.ExpirationDate == y.ExpirationDate &&
|
||||
x.ConsumedDate == y.ConsumedDate &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Grant obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Auth.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
|
||||
public class SsoConfigCompare : IEqualityComparer<SsoConfig>
|
||||
{
|
||||
public bool Equals(SsoConfig x, SsoConfig y)
|
||||
{
|
||||
return x.Enabled == y.Enabled &&
|
||||
x.OrganizationId == y.OrganizationId &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] SsoConfig obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Auth.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
|
||||
public class SsoUserCompare : IEqualityComparer<SsoUser>
|
||||
{
|
||||
public bool Equals(SsoUser x, SsoUser y)
|
||||
{
|
||||
return x.ExternalId == y.ExternalId;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] SsoUser obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlAuthRepo = Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories;
|
||||
|
||||
public class SsoConfigRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(ssoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedEfSsoConfig);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var sqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(sqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig,
|
||||
Organization org, SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
postSsoConfig.OrganizationId = replaceSsoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(postSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceSsoConfig.Id = postEfSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postEfSsoConfig);
|
||||
await sut.ReplaceAsync(replaceSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedSsoConfig = await sut.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSsoConfig);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
postSsoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(postSsoConfig);
|
||||
replaceSsoConfig.Id = postSqlSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postSqlSsoConfig);
|
||||
|
||||
await sqlSsoConfigRepo.ReplaceAsync(replaceSsoConfig);
|
||||
var replacedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(2).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(postEfSsoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoConfig);
|
||||
var deletedEfSsoConfig = await sut.GetByIdAsync(savedEfSsoConfig.Id);
|
||||
Assert.True(deletedEfSsoConfig == null);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
|
||||
await sqlSsoConfigRepo.DeleteAsync(savedSqlSsoConfig);
|
||||
savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig == null);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByOrganizationIdAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfUser = await sut.GetByOrganizationIdAsync(savedEfOrg.Id);
|
||||
Assert.True(savedEfUser != null);
|
||||
returnedList.Add(savedEfUser);
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByOrganizationIdAsync(ssoConfig.OrganizationId);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByIdentifierAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
returnedList.Add(savedEfSsoConfig);
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
// Testing that data matches here would involve manipulating all SsoConfig records in the db
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetManyByRevisionNotBeforeDate_Works(SsoConfig ssoConfig, DateTime notBeforeDate,
|
||||
Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var returnedEfSsoConfigs = await sut.GetManyByRevisionNotBeforeDate(notBeforeDate);
|
||||
Assert.True(returnedEfSsoConfigs.All(sc => sc.RevisionDate >= notBeforeDate));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlAuthRepo = Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories;
|
||||
|
||||
public class SsoUserRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoUser ssoUser, User user, Organization org,
|
||||
SsoUserCompare equalityComparer, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlAuthRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var createdSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = efUser.Id;
|
||||
ssoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedSsoUser = await sut.GetByIdAsync(ssoUser.Id);
|
||||
createdSsoUsers.Add(savedSsoUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
var sqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
|
||||
createdSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(sqlSsoUser.Id));
|
||||
|
||||
var distinctSsoUsers = createdSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctSsoUsers.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoUser postSsoUser, SsoUser replaceSsoUser,
|
||||
Organization org, User user, SsoUserCompare equalityComparer,
|
||||
List<EfRepo.SsoUserRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlAuthRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
postSsoUser.UserId = efUser.Id;
|
||||
postSsoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(postSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceSsoUser.Id = postEfSsoUser.Id;
|
||||
replaceSsoUser.UserId = postEfSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postEfSsoUser.OrganizationId;
|
||||
await sut.ReplaceAsync(replaceSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedSsoUser = await sut.GetByIdAsync(replaceSsoUser.Id);
|
||||
savedSsoUsers.Add(replacedSsoUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
postSsoUser.UserId = sqlUser.Id;
|
||||
postSsoUser.OrganizationId = sqlOrganization.Id;
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(postSsoUser);
|
||||
|
||||
replaceSsoUser.Id = postSqlSsoUser.Id;
|
||||
replaceSsoUser.UserId = postSqlSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postSqlSsoUser.OrganizationId;
|
||||
await sqlSsoUserRepo.ReplaceAsync(replaceSsoUser);
|
||||
|
||||
savedSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(replaceSsoUser.Id));
|
||||
|
||||
var distinctItems = savedSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoUser ssoUser, Organization org, User user, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlAuthRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoUser);
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_UserIdOrganizationId_Works_DataMatches(SsoUser ssoUser,
|
||||
User user, Organization org, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlAuthRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoUser.UserId, savedEfSsoUser.OrganizationId);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser.UserId, savedSqlSsoUser.OrganizationId);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user