mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -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:
@ -1,50 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class AuthRequestRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfAuthRequestAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
AuthRequest authRequest,
|
||||
AuthRequestCompare equalityComparer,
|
||||
List<EfRepo.AuthRequestRepository> suts,
|
||||
SqlRepo.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());
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class EmergencyAccessRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfEmergencyAccessAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
EmergencyAccess emergencyAccess,
|
||||
List<User> users,
|
||||
EmergencyAccessCompare equalityComparer,
|
||||
List<EfRepo.EmergencyAccessRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.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());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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();
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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();
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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();
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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();
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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();
|
||||
}
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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, SqlRepo.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, SqlRepo.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, SqlRepo.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, SqlRepo.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, SqlRepo.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));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.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,
|
||||
SqlRepo.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, SqlRepo.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,
|
||||
SqlRepo.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,
|
||||
SqlRepo.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);
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.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.Repositories;
|
||||
@ -249,7 +251,7 @@ public class UserRepositoryTests
|
||||
public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org,
|
||||
SsoUser ssoUser, UserCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
List<EfRepo.SsoUserRepository> ssoUserRepos, List<EfRepo.OrganizationRepository> orgRepos,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlAuthRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<User>();
|
||||
|
Reference in New Issue
Block a user