public async Task RevokeKeyAsync_should_not_be_implemented() { var keyManagerMock = new Mock <IKeyManager>(); keyManagerMock.Setup(m => m.GetAllKeys()).Returns(new List <IKey>()).Verifiable(); var defaultResolverMock = new Mock <IDefaultKeyResolver>(); var providerClientMock = new Mock <IProviderClient>(); var wrapper = new KeyManagerWrapper <IAuthenticatedEncryptorDescriptor>(keyManagerMock.Object, defaultResolverMock.Object, providerClientMock.Object); var sut = new KeyStore <string, IAuthenticatedEncryptorDescriptor>(wrapper); await Assert.ThrowsAsync <NotImplementedException>(() => sut.RevokeKeyAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())).ConfigureAwait(false); }
public async Task GetAllKeysAsync_should_call_wrapper_method() { var keyManagerMock = new Mock <IKeyManager>(); keyManagerMock.Setup(m => m.GetAllKeys()).Returns(new List <IKey>()).Verifiable(); var defaultResolverMock = new Mock <IDefaultKeyResolver>(); var providerClientMock = new Mock <IProviderClient>(); var wrapper = new KeyManagerWrapper <IAuthenticatedEncryptorDescriptor>(keyManagerMock.Object, defaultResolverMock.Object, providerClientMock.Object); var sut = new KeyStore <string, IAuthenticatedEncryptorDescriptor>(wrapper); await sut.GetAllKeysAsync().ConfigureAwait(false); keyManagerMock.Verify(); }
public async Task Subscribe_should_subcribe_to_hub_events() { using var waitHandle = new ManualResetEvent(false); var configuration = new Dictionary <string, string> { ["ConnectionStrings:DefaultConnection"] = Guid.NewGuid().ToString(), ["ApiAuthentication:Authority"] = "http://localhost", ["SignalR:HubUrl"] = "http://localhost/providerhub", ["SignalR:UseMessagePack"] = "false", ["Seed"] = "true" }; TestServer server = null; server = TestUtils.CreateTestServer(services => { services.RemoveAll <HubHttpMessageHandlerAccessor>(); services.AddTransient(p => new HubHttpMessageHandlerAccessor { Handler = new MockHttpMessageHandler(waitHandle, server.CreateHandler()) }); services.RemoveAll <HttpClient>(); services.AddTransient(p => server.CreateClient()); services.RemoveAll <HttpClientHandler>(); services.AddTransient <HttpClientHandler>(p => new MockHttpClientHandler(p.GetRequiredService <HttpClient>())); }, configuration, (endpoints, isProxy) => { endpoints.MapRazorPages(); endpoints.MapDefaultControllerRoute(); if (!isProxy) { endpoints.MapHub <ProviderHub>("/providerhub"); } }); using (server) { server.CreateWebSocketClient(); var provider = server.Host.Services; var store = provider.GetRequiredService <IAdminStore <ExternalProvider> >(); var serializer = provider.GetRequiredService <IAuthenticationSchemeOptionsSerializer>(); var manager = new NoPersistentDynamicManager <SchemeDefinition>(new Mock <IAuthenticationSchemeProvider>().Object, new OptionsMonitorCacheWrapperFactory(new Mock <IServiceProvider>().Object), Array.Empty <Type>()); var wrapper1 = new KeyManagerWrapper <Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.IAuthenticatedEncryptorDescriptor>(new Mock <IKeyManager>().Object, new Mock <IDefaultKeyResolver>().Object, new Mock <IProviderClient>().Object); var wrapper2 = new KeyManagerWrapper <IdentityServer.KeysRotation.RsaEncryptorDescriptor>(new Mock <IKeyManager>().Object, new Mock <IDefaultKeyResolver>().Object, new Mock <IProviderClient>().Object); var hubConnectionFactory = new HubConnectionFactory(provider.GetRequiredService <IConfiguration>(), provider, new NullLogger <HubConnectionFactory>()); var connection = hubConnectionFactory.GetConnection(default);
public void Constructor_should_throw_on_args_null() { Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(null, null, null, null, null, null)); var hubConnectionFactory = new HubConnectionFactory(new Mock <IConfiguration>().Object, new Mock <IServiceProvider>().Object, new NullLogger <HubConnectionFactory>()); Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(hubConnectionFactory, null, null, null, null, null)); var manager = new NoPersistentDynamicManager <SchemeDefinition>(new Mock <IAuthenticationSchemeProvider>().Object, new OptionsMonitorCacheWrapperFactory(new Mock <IServiceProvider>().Object), Array.Empty <Type>()); Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(hubConnectionFactory, manager, null, null, null, null)); Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(hubConnectionFactory, manager, new Mock <IDynamicProviderStore <SchemeDefinition> >().Object, null, null, null)); var wrapper1 = new KeyManagerWrapper <Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.IAuthenticatedEncryptorDescriptor>(new Mock <IKeyManager>().Object, new Mock <IDefaultKeyResolver>().Object, new Mock <IProviderClient>().Object); Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(hubConnectionFactory, manager, new Mock <IDynamicProviderStore <SchemeDefinition> >().Object, wrapper1, null, null)); var wrapper2 = new KeyManagerWrapper <IdentityServer.KeysRotation.RsaEncryptorDescriptor>(new Mock <IKeyManager>().Object, new Mock <IDefaultKeyResolver>().Object, new Mock <IProviderClient>().Object); Assert.Throws <ArgumentNullException>(() => new SchemeChangeSubscriber <SchemeDefinition>(hubConnectionFactory, manager, new Mock <IDynamicProviderStore <SchemeDefinition> >().Object, wrapper1, wrapper2, null)); }
public KeyStore(KeyManagerWrapper <T2> wrapper) { _wrapper = wrapper ?? throw new ArgumentNullException(nameof(wrapper)); }
/// <summary> /// Initializes a new instance of the <see cref="GenericKeyController{T}"/> class. /// </summary> /// <param name="wrapper">The manager.</param> /// <exception cref="ArgumentNullException">manager</exception> public GenericKeyController(KeyManagerWrapper <T> wrapper) { _wrapper = wrapper ?? throw new ArgumentNullException(nameof(wrapper)); }