mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
904b2fe205
* [AC-1192] Create new OrganizationAuthRequestsController.cs * [AC-1192] Introduce OrganizationAdminAuthRequest model * [AC-1192] Add GetManyPendingByOrganizationId method to AuthRequest repository * [AC-1192] Add new list pending organization auth requests endpoint * [AC-1192] Add new GetManyAdminApprovalsByManyIdsAsync method to the AuthRequestRepository * [AC-1192] Make the response device identifier optional for admin approval requests * [AC-1192] Add endpoint for bulk denying admin device auth requests * [AC-1192] Add OrganizationUserId to PendingOrganizationAuthRequestResponseModel * [AC-1192] Add UpdateAuthRequest endpoint and logic to OrganizationAuthRequestsController * [AC-1192] Secure new endpoints behind TDE feature flag * [AC-1192] Formatting * [AC-1192] Add sql migration script * [AC-1192] Add optional OrganizationId column to AuthRequest entity - Rename migration script to match existing formatting - Add new column - Add migration scripts - Update new sprocs to filter/join on OrganizationId - Update old sprocs to include OrganizationId * [AC-1192] Format migration scripts * [AC-1192] Fix failing AuthRequest EF unit test * [AC-1192] Make OrganizationId optional in updated AuthRequest sprocs for backwards compatability * [AC-1192] Fix missing comma in migration file * [AC-1192] Rename Key to EncryptedUserKey to be more descriptive * [AC-1192] Move request validation into helper method to reduce repetition * [AC-1192] Return UnauthorizedAccessException instead of NotFound when user is missing permission * [AC-1192] Introduce FeatureUnavailableException * [AC-1192] Introduce RequireFeatureAttribute * [AC-1192] Utilize the new RequireFeatureAttribute in the OrganizationAuthRequestsController * [AC-1192] Attempt to fix out of sync database migration by moving new OrganizationId column * [AC-1192] More attempts to sync database migrations * [AC-1192] Formatting * [AC-1192] Remove unused reference to FeatureService * [AC-1192] Change Id types from String to Guid * [AC-1192] Add EncryptedString attribute * [AC-1192] Remove redundant OrganizationId property * [AC-1192] Switch to projection for OrganizationAdminAuthRequest mapping - Add new OrganizationUser relationship to EF entity - Replace AuthRequest DBContext config with new IEntityTypeConfiguration - Add navigation property to AuthRequest entity configuration for OrganizationUser - Update EF AuthRequestRepository to use new mapping and navigation properties * [AC-1192] Remove OrganizationUser navigation property
63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
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,
|
|
Organization organization,
|
|
User user,
|
|
List<EfRepo.UserRepository> efUserRepos,
|
|
List<EfRepo.OrganizationRepository> efOrgRepos,
|
|
SqlRepo.UserRepository sqlUserRepo,
|
|
SqlRepo.OrganizationRepository sqlOrgRepo
|
|
)
|
|
{
|
|
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 efOrg = await efOrgRepos[i].CreateAsync(organization);
|
|
sut.ClearChangeTracking();
|
|
authRequest.OrganizationId = efOrg.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 sqlOrg = await sqlOrgRepo.CreateAsync(organization);
|
|
authRequest.OrganizationId = sqlOrg.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());
|
|
}
|
|
}
|