mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
[PM-1815] Include Member Decryption Type in Token Response (#2927)
* Include Member Decryption Type * Make ICurrentContext protected from base class * Return MemberDecryptionType * Extend WebApplicationFactoryBase - Allow for service subsitution * Create SSO Tests - Mock IAuthorizationCodeStore so the SSO process can be limited to Identity * Add MemberDecryptionOptions * Remove Unused Property Assertion * Make MemberDecryptionOptions an Array * Address PR Feedback * Make HasAdminApproval Policy Aware * Format * Use Object Instead * Add UserDecryptionOptions File
This commit is contained in:
@ -12,6 +12,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
using NoopRepos = Bit.Core.Repositories.Noop;
|
||||
|
||||
namespace Bit.IntegrationTestCommon.Factories;
|
||||
@ -33,6 +34,23 @@ public abstract class WebApplicationFactoryBase<T> : WebApplicationFactory<T>
|
||||
/// </remarks>
|
||||
public string DatabaseName { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
private readonly List<Action<IServiceCollection>> _configureTestServices = new();
|
||||
|
||||
public void SubstitueService<TService>(Action<TService> mockService)
|
||||
where TService : class
|
||||
{
|
||||
_configureTestServices.Add(services =>
|
||||
{
|
||||
var foundServiceDescriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(TService))
|
||||
?? throw new InvalidOperationException($"Could not find service of type {typeof(TService).FullName} to substitute");
|
||||
services.Remove(foundServiceDescriptor);
|
||||
|
||||
var substitutedService = Substitute.For<TService>();
|
||||
mockService(substitutedService);
|
||||
services.Add(ServiceDescriptor.Singleton(typeof(TService), substitutedService));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure the web host to use an EF in memory database
|
||||
/// </summary>
|
||||
@ -146,6 +164,11 @@ public abstract class WebApplicationFactoryBase<T> : WebApplicationFactory<T>
|
||||
// Disable logs
|
||||
services.AddSingleton<ILoggerFactory, NullLoggerFactory>();
|
||||
});
|
||||
|
||||
foreach (var configureTestService in _configureTestServices)
|
||||
{
|
||||
builder.ConfigureTestServices(configureTestService);
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseContext GetDatabaseContext()
|
||||
|
Reference in New Issue
Block a user