public async Task FindClientByIdAsync_WhenClientExistsWithCollections_ExpectClientReturnedCollections()
        {
            var storeHolder = GetConfigurationDocumentStoreHolder();

            var testClient = new Client
            {
                ClientId                     = "properties_test_client",
                ClientName                   = "Properties Test Client",
                AllowedCorsOrigins           = { "https://localhost" },
                AllowedGrantTypes            = GrantTypes.HybridAndClientCredentials,
                AllowedScopes                = { "openid", "profile", "api1" },
                Claims                       = { new ClientClaim("test", "value") },
                ClientSecrets                = { new Secret(CryptographyHelper.CreateHash("secret")) },
                IdentityProviderRestrictions = { "AD" },
                PostLogoutRedirectUris       = { "https://locahost/signout-callback" },
                Properties                   = { { "foo1", "bar1" }, { "foo2", "bar2" }, },
                RedirectUris                 = { "https://locahost/signin" }
            };

            using (var session = storeHolder.OpenAsyncSession())
            {
                await session.StoreAsync(testClient.ToEntity());

                await session.SaveChangesAsync();
            }

            WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore());

            var store  = new ClientStore(storeHolder, FakeLogger <ClientStore> .Create());
            var client = await store.FindClientByIdAsync(testClient.ClientId);

            client.Should().BeEquivalentTo(testClient);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(ConsentInputModel model)
        {
            var result = await ProcessConsent(model);

            if (result.IsRedirect)
            {
                if (await ClientStore.IsPkceClientAsync(result.ClientId))
                {
                    // if the client is PKCE then we assume it's native, so this change in how to
                    // return the response is for better UX for the end user.
                    return(View("Redirect", new RedirectViewModel {
                        RedirectUrl = result.RedirectUri
                    }));
                }

                return(Redirect(result.RedirectUri));
            }

            if (result.HasValidationError)
            {
                ModelState.AddModelError(string.Empty, result.ValidationError);
            }

            return(result.ShowView ? View("Index", result.ViewModel) : View("Error"));
        }
Exemplo n.º 3
0
        public async Task FindClientByIdAsync_WhenClientExistsWithCollections_ExpectClientReturnedCollections(DbContextOptions <ConfigurationDbContext> options)
        {
            var testClient = new Client
            {
                ClientId                     = "properties_test_client",
                ClientName                   = "Properties Test Client",
                AllowedCorsOrigins           = { "https://localhost" },
                AllowedGrantTypes            = GrantTypes.HybridAndClientCredentials,
                AllowedScopes                = { "openid", "profile", "api1" },
                Claims                       = { new Claim("test", "value") },
                ClientSecrets                = { new Secret("secret".Sha256()) },
                IdentityProviderRestrictions = { "AD" },
                PostLogoutRedirectUris       = { "https://locahost/signout-callback" },
                Properties                   = { { "foo1", "bar1" }, { "foo2", "bar2" }, },
                RedirectUris                 = { "https://locahost/signin" }
            };

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.Clients.Add(testClient.ToEntity());
                context.SaveChanges();
            }

            Client client;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ClientStore(context, FakeLogger <ClientStore> .Create());
                client = await store.FindClientByIdAsync(testClient.ClientId);
            }

            client.Should().BeEquivalentTo(testClient);
        }
        public async Task FindClientByIdAsync_WhenClientExists_ExpectClientReturned()
        {
            var storeHolder = GetConfigurationDocumentStoreHolder();

            WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore());

            var testClient = new Client
            {
                ClientId   = "test_client",
                ClientName = "Test Client"
            };

            using (var session = storeHolder.OpenAsyncSession())
            {
                await session.StoreAsync(testClient.ToEntity());

                await session.SaveChangesAsync();
            }

            WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore());

            var store  = new ClientStore(storeHolder, FakeLogger <ClientStore> .Create());
            var client = await store.FindClientByIdAsync(testClient.ClientId);

            client.Should().NotBeNull();
        }
Exemplo n.º 5
0
        public void FindClientByIdAsync_WhenClientExists_ExpectClientRetured(
            DbContextOptions <ConfigurationDbContext> options)
        {
            var testClient = new Client
            {
                ClientId   = "test_client",
                ClientName = "Test Client"
            };

            using (var context =
                       new ConfigurationDbContext(options, StoreOptions))
            {
                context.Clients.Add(testClient.ToEntity());
                context.SaveChanges();
            }

            Client client;

            using (var context =
                       new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ClientStore(
                    context,
                    NullLogger <ClientStore> .Create()
                    );

                client = store.FindClientByIdAsync(testClient.ClientId).Result;
            }

            Assert.NotNull(client);
        }
Exemplo n.º 6
0
    public async Task Can_call_ClientStore_FindClientByIdAsync()
    => await ExecuteWithStrategyInTransactionAsync(
        async context =>
    {
        context.AddRange(
            new Client
        {
            ClientId = "C1", Description = "D1",
        },
            new Client
        {
            ClientId = "C2", Description = "D2",
        },
            new Client
        {
            ClientId = "C3", Description = "D3",
        });

        await context.SaveChangesAsync();
    },
        async context =>
    {
        var store = new ClientStore(context, new FakeLogger <ClientStore>());

        Assert.Equal("D2", (await store.FindClientByIdAsync("C2")).Description);
    }
        );
        public static List <RefreshTokenHandleRecord> InsertTestData(ClientStore clientStore, ScopeStore scopeStore, TokenHandleStore ths, RefreshTokenStore store, int count = 1)
        {
            List <RefreshTokenHandleRecord> result = new List <RefreshTokenHandleRecord>();
            var insert      = TokenHandleStoreTest.InsertTestData(clientStore, scopeStore, ths, count);
            var subjectSeed = Guid.NewGuid().ToString();
            var clientId    = insert[0].Record.ClientId;

            foreach (var item in insert)
            {
                RefreshTokenHandle tokenHandle = new RefreshTokenHandle
                {
                    ClientId     = clientId,
                    AccessToken  = item.Record,
                    CreationTime = DateTimeOffset.UtcNow,
                    Key          = Guid.NewGuid().ToString(),
                    Expires      = DateTimeOffset.UtcNow.AddMinutes(5),
                    LifeTime     = 5,
                    SubjectId    = item.Record.SubjectId,
                    Version      = 1
                };
                var tokenHandleRecord = new RefreshTokenHandleRecord(tokenHandle);
                store.CreateAsync(tokenHandleRecord.Record);
                result.Add(tokenHandleRecord);
            }
            return(result);
        }
        public async Task FindClientByIdAsync_WhenClientIdReceived_ExpectClientToBeReturned()
        {
            var store = new ClientStore(StoreOptions, new FakeLogger <ClientStore>());

            foreach (var testObject in GetClientTestObjects())
            {
                await store.StoreAsync(testObject);
            }

            var client = await store.FindClientByIdAsync("roclient");

            Assert.Single(client.Claims);
            Assert.Equal("role", client.Claims.ToArray()[0].Type);
            Assert.Equal("service", client.Claims.ToArray()[0].Value);

            Assert.Equal("https://cors/", client.AllowedCorsOrigins.ToArray()[0]);
            Assert.Equal("https://origin/", client.AllowedCorsOrigins.ToArray()[1]);

            Assert.Single(client.AllowedGrantTypes);
            Assert.Equal("password", client.AllowedGrantTypes.ToArray()[0]);

            Assert.Single(client.ClientSecrets);
            Assert.Equal("K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=", client.ClientSecrets.ToArray()[0].Value);
            Assert.Equal("SharedSecret", client.ClientSecrets.ToArray()[0].Type);

            Assert.Equal("api1", client.AllowedScopes.ToArray()[0]);
            Assert.Equal("api2.read_only", client.AllowedScopes.ToArray()[1]);

            Assert.Equal("provider", client.IdentityProviderRestrictions.ToArray()[0]);

            Assert.Equal("https://logout/redirect/", client.PostLogoutRedirectUris.ToArray()[0]);
            Assert.Equal("https://logout/redirect-failure/", client.PostLogoutRedirectUris.ToArray()[1]);

            Assert.Equal("https://redirect/", client.RedirectUris.ToArray()[0]);
        }
Exemplo n.º 9
0
        public async Task FindClientByIdAsync_WhenClientExists_ExpectClientRetured()
        {
            var repo = g.configurationDb.GetRepository <IdentityServer4.Fsql.Storage.Entities.Client>();

            var testClient = new Client
            {
                ClientId   = "test_client",
                ClientName = "Test Client"
            };
            var entity = testClient.ToEntity();

            repo.Insert(entity);
            repo.SaveMany(entity, "AllowedCorsOrigins");
            repo.SaveMany(entity, "AllowedGrantTypes");
            repo.SaveMany(entity, "AllowedScopes");
            repo.SaveMany(entity, "Claims");
            repo.SaveMany(entity, "ClientSecrets");
            repo.SaveMany(entity, "IdentityProviderRestrictions");
            repo.SaveMany(entity, "PostLogoutRedirectUris");
            repo.SaveMany(entity, "Properties");
            repo.SaveMany(entity, "RedirectUris");


            Client client;
            var    store = new ClientStore(g.configurationDb, FakeLogger <ClientStore> .Create());

            client = await store.FindClientByIdAsync(testClient.ClientId);

            client.Should().NotBeNull();

            DeleteTestData(entity);
        }
Exemplo n.º 10
0
        private void FrozenInStoreConfirmScan_Load(object sender, EventArgs e)
        {
            //不做离线,直接从接口取
            var listObj = RpcFacade.Call <List <RpcObject> >("/MainSystem/B3Butchery/Rpcs/BaseInfoRpc/SyncFrozenStore");
            var list    = new List <ClientStore>();

            foreach (RpcObject obj in listObj)
            {
                var store = new ClientStore();
                store.ID   = obj.Get <long>("ID");
                store.Name = obj.Get <string>("Name");
                list.Add(store);
            }
            _storeList              = list;
            comboBox1.DataSource    = _storeList;
            comboBox1.DisplayMember = "Name";
            comboBox1.ValueMember   = "ID";

            var productPlanObj  = RpcFacade.Call <List <RpcObject> >("/MainSystem/B3Butchery/Rpcs/ProduceOutputRpc/GetProductPlan");
            var productPlanList = new List <ClientProductPlan>();

            foreach (RpcObject obj in productPlanObj)
            {
                var productPlan = new ClientProductPlan();
                productPlan.ID         = obj.Get <long>("ID");
                productPlan.PlanNumber = obj.Get <string>("PlanNumber");
                productPlanList.Add(productPlan);
            }
            _productPlanList        = productPlanList;
            comboBox2.DataSource    = _productPlanList;
            comboBox2.DisplayMember = "PlanNumber";
            comboBox2.ValueMember   = "ID";
        }
 public void Setup()
 {
     base.Setup();
     _clientStore      = new ClientStore(StoreSettings.UsingFolder(TargetFolder));
     _tokenHandleStore = new TokenHandleStore(StoreSettings.UsingFolder(TargetFolder));
     _scopeStore       = new ScopeStore(StoreSettings.UsingFolder(TargetFolder));
 }
        public async Task Should_Retrieve_Client_With_Allowed_Cors_Origins(TestDatabase testDb)
        {
            var testClient = new Client()
            {
                ClientId           = Guid.NewGuid().ToString(),
                ClientName         = "Test Client with CORS Origins",
                AllowedCorsOrigins =
                {
                    "*.tld1",
                    "*.tld2",
                    "*.tld3"
                }
            };

            using (var session = testDb.OpenSession())
            {
                await session.SaveAsync(testClient.ToEntity());

                await session.FlushAsync();
            }

            Client requestedClient;
            var    loggerMock = new Mock <ILogger <ClientStore> >();

            using (var session = testDb.OpenSession())
            {
                var store = new ClientStore(session, loggerMock.Object);
                requestedClient = await store.FindClientByIdAsync(testClient.ClientId);
            }

            requestedClient.Should().NotBeNull();
            requestedClient.AllowedCorsOrigins.Count.Should().Be(3);

            await CleanupTestDataAsync(testDb);
        }
        public async Task Should_Retrieve_Client_With_Properties(TestDatabase testDb)
        {
            var testClient = new Client()
            {
                ClientId   = Guid.NewGuid().ToString(),
                ClientName = "Test Client with Properties",
                Properties =
                {
                    { "prop1", "val1" },
                    { "prop2", "val2" },
                    { "prop3", "val3" }
                }
            };

            using (var session = testDb.OpenSession())
            {
                await session.SaveAsync(testClient.ToEntity());

                await session.FlushAsync();
            }

            Client requestedClient;
            var    loggerMock = new Mock <ILogger <ClientStore> >();

            using (var session = testDb.OpenSession())
            {
                var store = new ClientStore(session, loggerMock.Object);
                requestedClient = await store.FindClientByIdAsync(testClient.ClientId);
            }

            requestedClient.Should().NotBeNull();
            requestedClient.Properties.Count.Should().Be(3);

            await CleanupTestDataAsync(testDb);
        }
Exemplo n.º 14
0
        public void FindClientByIdAsync_WhenClientExists_ExpectClientRetured()
        {
            var testClient = new Client {
                Claims = new List <ClientClaim> {
                    new ClientClaim {
                        Type = "type", Value = "value"
                    }
                }, ClientName = "re", ClientId = "re", AllowedGrantTypes = new List <ClientGrantType> {
                    new ClientGrantType {
                        GrantType = "xxxxx"
                    }
                }
            };

            using (var session = martenFixture.Store.OpenSession())
            {
                session.Store(testClient);
                session.SaveChanges();
            }
            using (var session = martenFixture.Store.OpenSession())
            {
                var _client = new ClientStore(session).FindClientByIdAsync(testClient.ClientId).Result;
                Assert.NotNull(_client);
            }
        }
Exemplo n.º 15
0
        public async Task FindClientByIdAsync_should_return_client()
        {
            using var store = new RavenDbTestDriverWrapper().GetDocumentStore();
            using var s1    = store.OpenAsyncSession();

            await s1.StoreAsync(new Entity.Client
            {
                Id = "test",
                AllowedGrantTypes = new List <Entity.ClientGrantType>
                {
                    new Entity.ClientGrantType
                    {
                        Id = $"{nameof(Entity.ClientGrantType).ToLowerInvariant()}/test"
                    }
                }
            }, $"{nameof(Entity.Client)}/test");

            await s1.StoreAsync(new Entity.ClientGrantType
            {
                Id        = "test",
                GrantType = "client_credential"
            }, $"{nameof(Entity.ClientGrantType).ToLowerInvariant()}/test");

            await s1.SaveChangesAsync();

            var sut = new ClientStore(new ScopedAsynDocumentcSession(store.OpenAsyncSession()));

            var result = await sut.FindClientByIdAsync("test");

            Assert.NotNull(result);
            Assert.Contains(result.AllowedGrantTypes, g => g == "client_credential");
        }
Exemplo n.º 16
0
        public void FindClientByIdAsync_WhenClientExists_ExpectClientPropertiesRetured(DbContextOptions <ConfigurationDbContext> options)
        {
            var testClient = new Client
            {
                ClientId   = "properties_test_client",
                ClientName = "Properties Test Client",
                Properties =
                {
                    { "foo1", "bar1" },
                    { "foo2", "bar2" },
                }
            };

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.Clients.Add(testClient.ToEntity());
                context.SaveChanges();
            }

            Client client;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ClientStore(context, FakeLogger <ClientStore> .Create());
                client = store.FindClientByIdAsync(testClient.ClientId).Result;
            }

            client.Properties.Should().NotBeNull();
            client.Properties.Count.Should().Be(2);
            client.Properties.ContainsKey("foo1").Should().BeTrue();
            client.Properties.ContainsKey("foo2").Should().BeTrue();
            client.Properties["foo1"].Should().Be("bar1");
            client.Properties["foo2"].Should().Be("bar2");
        }
Exemplo n.º 17
0
        public TcpServerController(TcpListener server, TraceSource trace, ClientStore clientStore, NetworkStreamReader reader, NetworkStreamWriter writer)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }
            if (trace == null)
            {
                throw new ArgumentNullException(nameof(trace));
            }
            if (clientStore == null)
            {
                throw new ArgumentNullException(nameof(clientStore));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            _server      = server;
            _trace       = trace;
            _clientStore = clientStore;
            _reader      = reader;
            _writer      = writer;
        }
        public async Task Should_Retrieve_Client_If_It_Exists(TestDatabase testDb)
        {
            var testClient = new Client()
            {
                ClientId   = Guid.NewGuid().ToString(),
                ClientName = "Test Client"
            };

            using (var session = testDb.OpenSession())
            {
                await session.SaveAsync(testClient.ToEntity());

                await session.FlushAsync();
            }

            Client requestedClient;
            var    loggerMock = new Mock <ILogger <ClientStore> >();

            using (var session = testDb.OpenSession())
            {
                var store = new ClientStore(session, loggerMock.Object);
                requestedClient = await store.FindClientByIdAsync(testClient.ClientId);
            }

            requestedClient.Should().NotBeNull();

            await CleanupTestDataAsync(testDb);
        }
Exemplo n.º 19
0
        public async Task CanLoadClientById()
        {
            var store  = new ClientStore(Session);
            var client = await store.FindClientByIdAsync("codeclient");

            client.ShouldNotBe(null);
        }
        public async Task FindClientByIdAsync_WhenClientExists_ExpectClientReturned()
        {
            using var ravenStore = GetDocumentStore();
            await new ClientIndex().ExecuteAsync(ravenStore);

            var testClient = new Client
            {
                ClientId   = "test_client",
                ClientName = "Test Client"
            };

            using (var session = ravenStore.OpenSession())
            {
                session.Store(testClient.ToEntity());
                session.SaveChanges();
            }

            WaitForIndexing(ravenStore);

            Client client;

            using (var session = ravenStore.OpenAsyncSession())
            {
                var store = new ClientStore(session, FakeLogger <ClientStore> .Create());
                client = await store.FindClientByIdAsync(testClient.ClientId);
            }

            client.Should().NotBeNull();
        }
        private static void Seed(IApplicationBuilder app)
        {
            var options = app.ApplicationServices.GetRequiredService <IOptions <TableStorageConfigurationOptions> >();

            // seed API resources

            var apiResourceLogger = app.ApplicationServices.GetRequiredService <ILogger <ApiResourceTableStore> >();
            var apiResourceStore  = new ApiResourceTableStore(options, apiResourceLogger);

            foreach (var apiResource in Host.Configuration.Resources.GetApiResources())
            {
                apiResourceStore.StoreAsync(apiResource).GetAwaiter().GetResult();
            }

            // seed Identity resources

            var identityResourceLogger = app.ApplicationServices.GetRequiredService <ILogger <IdentityResourceTableStore> >();
            var identityResourceStore  = new IdentityResourceTableStore(options, identityResourceLogger);

            foreach (var identityResource in Host.Configuration.Resources.GetIdentityResources())
            {
                identityResourceStore.StoreAsync(identityResource).GetAwaiter().GetResult();
            }

            // seed Clients

            var clientLogger = app.ApplicationServices.GetRequiredService <ILogger <ClientStore> >();
            var clientStore  = new ClientStore(options, clientLogger);

            foreach (var client in Clients.Get())
            {
                clientStore.StoreAsync(client).GetAwaiter().GetResult();
            }
        }
Exemplo n.º 22
0
        public async Task FindClientByIdAsync_WhenClientDoesNotExist_ExpectNull()
        {
            var store  = new ClientStore(g.configurationDb, FakeLogger <ClientStore> .Create());
            var client = await store.FindClientByIdAsync(Guid.NewGuid().ToString());

            client.Should().BeNull();
        }
Exemplo n.º 23
0
        private async Task <ConsentViewModel> BuildViewModelAsync(string returnUrl, ConsentInputModel model = null)
        {
            var request = await Interaction.GetAuthorizationContextAsync(returnUrl);

            if (request != null)
            {
                var client = await ClientStore.FindEnabledClientByIdAsync(request.ClientId);

                if (client != null)
                {
                    var resources = await ResourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested);

                    if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any()))
                    {
                        return(CreateConsentViewModel(model, returnUrl, request, client, resources));
                    }
                    else
                    {
                        Logger.LogError("No scopes matching: {0}", request.ScopesRequested.Aggregate((x, y) => x + ", " + y));
                    }
                }
                else
                {
                    Logger.LogError("Invalid client id: {0}", request.ClientId);
                }
            }
            else
            {
                Logger.LogError("No consent request matching request: {0}", returnUrl);
            }

            return(null);
        }
        public async override Task <IActionResult> OnGetAsync()
        {
            LoginInput = new LoginInputModel();

            var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);

            if (context != null)
            {
                ShowCancelButton = true;

                LoginInput.UserNameOrEmailAddress = context.LoginHint;

                //TODO: Reference AspNetCore MultiTenancy module and use options to get the tenant key!
                var tenant = context.Parameters[TenantResolverConsts.DefaultTenantKey];
                if (!string.IsNullOrEmpty(tenant))
                {
                    CurrentTenant.Change(Guid.Parse(tenant));
                    Response.Cookies.Append(TenantResolverConsts.DefaultTenantKey, tenant);
                }
            }

            if (context?.IdP != null)
            {
                LoginInput.UserNameOrEmailAddress = context.LoginHint;
                ExternalProviders = new[] { new ExternalProviderModel {
                                                AuthenticationScheme = context.IdP
                                            } };
                return(Page());
            }

            var providers = await GetExternalProviders();

            ExternalProviders = providers.ToList();

            EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

            if (context?.Client?.ClientId != null)
            {
                var client = await ClientStore.FindEnabledClientByIdAsync(context?.Client?.ClientId);

                if (client != null)
                {
                    EnableLocalLogin = client.EnableLocalLogin;

                    if (client.IdentityProviderRestrictions != null && client.IdentityProviderRestrictions.Any())
                    {
                        providers = providers.Where(provider => client.IdentityProviderRestrictions.Contains(provider.AuthenticationScheme)).ToList();
                    }
                }
            }

            if (IsExternalLoginOnly)
            {
                return(await base.OnPostExternalLogin(providers.First().AuthenticationScheme));
            }

            return(Page());
        }
Exemplo n.º 25
0
 public AdminService(IMongoClient client, IMongoDatabase db, StoreSettings settings)
 {
     _client           = client;
     _db               = db;
     _settings         = settings;
     _clientSerializer = new ClientSerializer();
     _clientStore      = new ClientStore(db, settings, _clientSerializer);
     _scopeStore       = new ScopeStore(db, settings);
 }
Exemplo n.º 26
0
 public HomeController(ClientStore cs, BookCatalog bc, MusicCatalog muc, MovieCatalog moc, MagazineCatalog mac, Search search)
 {
     _cs        = cs;
     _bookc     = bc;
     _moviec    = moc;
     _musicc    = muc;
     _magazinec = mac;
     _search    = search;
 }
Exemplo n.º 27
0
 public IActionResult OnGet(Guid id)
 {
     Client = ClientStore.GetClientById(id);
     if (Client == null)
     {
         return(RedirectToPage("./Add"));
     }
     return(Page());
 }
Exemplo n.º 28
0
 public IActionResult OnPostAsync()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     ClientStore.AddCliente(Client);
     return(RedirectToPage("./Index"));
 }
Exemplo n.º 29
0
 public TransactionServer(Bank bank, Dispatcher dispatcher)
 {
     _bank            = bank;
     _bank.Dispatcher = dispatcher;
     clients          = new ClientStore();
     ThreadedReceiver.ServerDataReceived += ThreadedReceiver_ServerDataReceived;
     listenerThread = new ThreadedListener(tx);
     listenerThread.Run(clients);
 }
        public async Task FindClientByIdAsync_WhenClientsExistWithManyCollections_ExpectClientReturnedInUnderFiveSeconds()
        {
            var storeHolder = GetConfigurationDocumentStoreHolder();

            var testClient = new Client
            {
                ClientId          = "test_client_with_uris",
                ClientName        = "Test client with URIs",
                AllowedScopes     = { "openid", "profile", "api1" },
                AllowedGrantTypes = GrantTypes.CodeAndClientCredentials
            };

            for (int i = 0; i < 50; i++)
            {
                testClient.RedirectUris.Add($"https://localhost/{i}");
                testClient.PostLogoutRedirectUris.Add($"https://localhost/{i}");
                testClient.AllowedCorsOrigins.Add($"https://localhost:{i}");
            }

            using (var session = storeHolder.OpenAsyncSession())
            {
                await session.StoreAsync(testClient.ToEntity());

                for (int i = 0; i < 50; i++)
                {
                    await session.StoreAsync(new Client
                    {
                        ClientId               = testClient.ClientId + i,
                        ClientName             = testClient.ClientName,
                        AllowedScopes          = testClient.AllowedScopes,
                        AllowedGrantTypes      = testClient.AllowedGrantTypes,
                        RedirectUris           = testClient.RedirectUris,
                        PostLogoutRedirectUris = testClient.PostLogoutRedirectUris,
                        AllowedCorsOrigins     = testClient.AllowedCorsOrigins,
                    }.ToEntity());
                }

                await session.SaveChangesAsync();
            }

            WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore());

            var store = new ClientStore(storeHolder, FakeLogger <ClientStore> .Create());

            const int timeout = 5000;
            var       task    = Task.Run(() => store.FindClientByIdAsync(testClient.ClientId));

            if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
            {
                var client = task.Result;
                client.Should().BeEquivalentTo(testClient);
            }
            else
            {
                throw new TestTimeoutException(timeout);
            }
        }
 public SetupController(
     Contexts.IDS4Context context,
     LuigiTrabacchin.IdentityServer4.EntityFramework.Identity.UserManager<Int32> userManager,
     ScopeStore<Int32> scopeStore,
     ClientStore<Int32> clientStore
 )
 {
     this.Context = context;
     this._userManager = userManager;
     this._scopeStore = scopeStore;
     this._clientStore = clientStore;
 }