public async Task FindIdentityResourcesByScopeNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned() { using var ravenStore = GetDocumentStore(); await new IdentityResourceIndex().ExecuteAsync(ravenStore); var resource = CreateIdentityTestResource(); using (var session = ravenStore.OpenSession()) { session.Store(resource.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <IdentityResource> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name, "non-existent" })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); var foundScope = resources.Single(); Assert.Equal(resource.Name, foundScope.Name); Assert.NotNull(foundScope.UserClaims); Assert.NotEmpty(foundScope.UserClaims); }
public void FindApiResourceAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.ApiResources.Add(resource.ToEntity()); context.SaveChanges(); } ApiResource foundResource; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); foundResource = store.FindApiResourceAsync(resource.Name).Result; } Assert.NotNull(foundResource); Assert.NotNull(foundResource.UserClaims); Assert.NotEmpty(foundResource.UserClaims); Assert.NotNull(foundResource.ApiSecrets); Assert.NotEmpty(foundResource.ApiSecrets); Assert.NotNull(foundResource.Scopes); Assert.NotEmpty(foundResource.Scopes); Assert.True(foundResource.Scopes.Any(x => x.UserClaims.Any())); }
public void FindApiResourcesByScopeAsync_WhenMultipleResourcesExist_ExpectOnlyRequestedResourcesReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.ApiResources.Add(resource.ToEntity()); context.ApiResources.Add(CreateApiTestResource().ToEntity()); context.ApiResources.Add(CreateApiTestResource().ToEntity()); context.SaveChanges(); } IList <ApiResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = store.FindApiResourcesByScopeAsync(new List <string> { resource.Scopes.First().Name }).Result.ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.Equal(1, resources.Count); }
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); }
public void IsOriginAllowedAsync_WhenOriginIsNotAllowed_ExpectFalse(DbContextOptions <ConfigurationDbContext> options) { using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.Clients.Add(new Client { ClientId = Guid.NewGuid().ToString(), ClientName = Guid.NewGuid().ToString(), AllowedCorsOrigins = new List <string> { "https://www.identityserver.com" } }.ToEntity()); context.SaveChanges(); } bool result; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var svcs = new ServiceCollection(); svcs.AddSingleton <IConfigurationDbContext>(context); var provider = svcs.BuildServiceProvider(); var service = new CorsPolicyService(provider, FakeLogger <CorsPolicyService> .Create()); result = service.IsOriginAllowedAsync("InvalidOrigin").Result; } Assert.False(result); }
public async Task StoreDeviceAuthorizationAsync_WhenSuccessful_ExpectDataStored() { var storeHolder = GetOperationalDocumentStoreHolder(); var deviceCode = Guid.NewGuid().ToString(); var userCode = Guid.NewGuid().ToString(); var data = new DeviceCode { ClientId = Guid.NewGuid().ToString(), CreationTime = DateTime.UtcNow, Lifetime = 300 }; var store = new DeviceFlowStore(storeHolder, new PersistentGrantSerializer(), FakeLogger <DeviceFlowStore> .Create()); await store.StoreDeviceAuthorizationAsync(deviceCode, userCode, data); using (var session = storeHolder.OpenAsyncSession()) { var foundDeviceFlowCodes = await session.Query <DeviceFlowCode>().FirstOrDefaultAsync(x => x.DeviceCode == deviceCode); foundDeviceFlowCodes.Should().NotBeNull(); var deserializedData = new PersistentGrantSerializer().Deserialize <DeviceCode>(foundDeviceFlowCodes?.Data); deserializedData.CreationTime.Should().BeCloseTo(data.CreationTime); deserializedData.ClientId.Should().Be(data.ClientId); deserializedData.Lifetime.Should().Be(data.Lifetime); } }
public async Task Store_should_update_record_if_key_already_exists(DbContextOptions <PersistedGrantDbContext> options) { var persistedGrant = CreateTestObject(); using (var context = new PersistedGrantDbContext(options, StoreOptions)) { context.PersistedGrants.Add(persistedGrant.ToEntity()); context.SaveChanges(); } var newDate = persistedGrant.Expiration.Value.AddHours(1); using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var store = new PersistedGrantStore(context, FakeLogger <PersistedGrantStore> .Create()); persistedGrant.Expiration = newDate; await store.StoreAsync(persistedGrant); } using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var foundGrant = context.PersistedGrants.FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.NotNull(foundGrant); Assert.Equal(newDate, persistedGrant.Expiration); } }
public async Task FindApiResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyResourcesRequestedReturned() { var testIdentityResource = CreateIdentityTestResource(); var testApiResource = CreateApiResourceTestResource(); var testApiScope = CreateApiScopeTestResource(); testApiResource.Scopes.Add(testApiScope.Name); await _context.IdentityResources.AddAsync(testIdentityResource.ToEntity()); await _context.ApiResources.AddAsync(testApiResource.ToEntity()); await _context.ApiScopes.AddAsync(testApiScope.ToEntity()); await _context.IdentityResources.AddAsync(CreateIdentityTestResource().ToEntity()); await _context.ApiResources.AddAsync(CreateApiResourceTestResource().ToEntity()); await _context.ApiScopes.AddAsync(CreateApiScopeTestResource().ToEntity()); IEnumerable <ApiResource> resources; var store = new ResourceStore(_context, FakeLogger <ResourceStore> .Create()); resources = await store.FindApiResourcesByScopeNameAsync(new[] { testApiScope.Name }); Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == testApiResource.Name)); }
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(); }
public async Task GetAsync_WithKeyAndPersistedGrantExists_ExpectPersistedGrantReturned() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { session.Store(persistedGrant.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); PersistedGrant foundPersistedGrant; using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); foundPersistedGrant = await store.GetAsync(persistedGrant.Key); } Assert.NotNull(foundPersistedGrant); }
public async Task GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { session.Store(persistedGrant.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <PersistedGrant> foundPersistedGrants; using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); var filter = new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId }; foundPersistedGrants = (await store.GetAllAsync(filter)).ToList(); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task Store_should_update_record_if_key_already_exists() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { session.Store(persistedGrant.ToEntity()); session.SaveChanges(); } var newDate = persistedGrant.Expiration.Value.AddHours(1); using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); persistedGrant.Expiration = newDate; await store.StoreAsync(persistedGrant); } using (var session = ravenStore.OpenSession()) { var foundGrant = session.Query <Storage.Entities.PersistedGrant>() .FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.NotNull(foundGrant); Assert.Equal(newDate, persistedGrant.Expiration); } }
public async Task Store_should_create_new_record_if_key_does_not_exist() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { var foundGrant = session.Query <PersistedGrant>().FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.Null(foundGrant); } using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); await store.StoreAsync(persistedGrant); } WaitForIndexing(ravenStore); WaitForUserToContinueTheTest(ravenStore); using (var session = ravenStore.OpenSession()) { var foundGrant = session.Query <PersistedGrant>() .FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.NotNull(foundGrant); } }
public async Task RemoveAsync_WhenSubIdClientIdAndTypeOfExistingReceived_ExpectGrantDeleted() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { session.Store(persistedGrant.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); var filter = new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId, ClientId = persistedGrant.ClientId, Type = persistedGrant.Type }; await store.RemoveAllAsync(filter); } using (var session = ravenStore.OpenSession()) { var foundGrant = session.Query <PersistedGrant>() .FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.Null(foundGrant); } }
public async Task FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiScopeTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.ApiScopes.Add(resource.ToEntity()); context.ApiScopes.Add(CreateApiScopeTestResource().ToEntity()); context.SaveChanges(); } IList <ApiScope> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = (await store.FindApiScopesByNameAsync(new List <string> { resource.Name })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
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"); }
public async Task FindApiResourcesByNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiResourceTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.ApiResources.Add(resource.ToEntity()); context.SaveChanges(); } ApiResource foundResource; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); foundResource = (await store.FindApiResourcesByNameAsync(new[] { resource.Name })).SingleOrDefault(); } Assert.NotNull(foundResource); Assert.True(foundResource.Name == resource.Name); Assert.NotNull(foundResource.UserClaims); Assert.NotEmpty(foundResource.UserClaims); Assert.NotNull(foundResource.ApiSecrets); Assert.NotEmpty(foundResource.ApiSecrets); Assert.NotNull(foundResource.Scopes); Assert.NotEmpty(foundResource.Scopes); }
public async Task FindApiResourcesByScopeNameAsync_WhenResourcesExist_ExpectResourcesReturned() { using var ravenStore = GetDocumentStore(); await new ApiResourceIndex().ExecuteAsync(ravenStore); var testApiResource = CreateApiResourceTestResource(); var testApiScope = CreateApiScopeTestResource(); testApiResource.Scopes.Add(testApiScope.Name); using (var session = ravenStore.OpenSession()) { session.Store(testApiResource.ToEntity()); //session.Store(testApiScope.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IEnumerable <ApiResource> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); resources = await store.FindApiResourcesByScopeNameAsync(new List <string> { testApiScope.Name }); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == testApiResource.Name)); }
public async Task RemoveAllAsync_WhenSubIdClientIdAndTypeOfExistingReceived_ExpectGrantDeleted(DbContextOptions <PersistedGrantDbContext> options) { var persistedGrant = CreateTestObject(); using (var context = new PersistedGrantDbContext(options, StoreOptions)) { context.PersistedGrants.Add(persistedGrant.ToEntity()); context.SaveChanges(); } using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var store = new PersistedGrantStore(context, FakeLogger <PersistedGrantStore> .Create()); await store.RemoveAllAsync(new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId, ClientId = persistedGrant.ClientId, Type = persistedGrant.Type }); } using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var foundGrant = context.PersistedGrants.FirstOrDefault(x => x.Key == persistedGrant.Key); Assert.Null(foundGrant); } }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { using var ravenStore = GetDocumentStore(); await new IdentityResourceIndex().ExecuteAsync(ravenStore); var resource = CreateIdentityTestResource(); using (var session = ravenStore.OpenSession()) { session.Store(resource.ToEntity()); session.Store(CreateIdentityTestResource().ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <IdentityResource> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
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(); }
public async Task FindApiScopesByNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned() { using var ravenStore = GetDocumentStore(); await new ApiResourceIndex().ExecuteAsync(ravenStore); var resource = CreateApiScopeTestResource(); using (var session = ravenStore.OpenSession()) { //session.Store(resource.ToEntity()); session.SaveChanges(); } IList <ApiScope> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); //resources = (await store.FindApiScopesByNameAsync(new List<string> //{ // resource.Name //})).ToList(); } //Assert.NotNull(resources); //Assert.NotEmpty(resources); //var foundScope = resources.Single(); //Assert.Equal(resource.Name, foundScope.Name); //Assert.NotNull(foundScope.UserClaims); //Assert.NotEmpty(foundScope.UserClaims); }
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 FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { using var ravenStore = GetDocumentStore(); await new ApiResourceIndex().ExecuteAsync(ravenStore); var resource = CreateApiScopeTestResource(); using (var session = ravenStore.OpenSession()) { //session.Store(resource.ToEntity()); //session.Store(CreateApiScopeTestResource().ToEntity()); session.SaveChanges(); } IList <ApiScope> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); //resources = (await store.FindApiScopesByNameAsync(new List<string> //{ // resource.Name //})).ToList(); } //Assert.NotNull(resources); //Assert.NotEmpty(resources); //Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public void FindIdentityResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateIdentityTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.IdentityResources.Add(resource.ToEntity()); context.SaveChanges(); } IList <IdentityResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = store.FindIdentityResourcesByScopeAsync(new List <string> { resource.Name }).Result.ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); var foundScope = resources.Single(); Assert.Equal(resource.Name, foundScope.Name); Assert.NotNull(foundScope.UserClaims); Assert.NotEmpty(foundScope.UserClaims); }
public async Task FindApiResourcesByNameAsync_WhenResourcesExist_ExpectOnlyResourcesRequestedReturned() { using var ravenStore = GetDocumentStore(); await new ApiResourceIndex().ExecuteAsync(ravenStore); var resource = CreateApiResourceTestResource(); using (var session = ravenStore.OpenSession()) { session.Store(resource.ToEntity()); session.Store(CreateApiResourceTestResource().ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); ApiResource foundResource; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); foundResource = (await store.FindApiResourcesByNameAsync(new[] { resource.Name })).SingleOrDefault(); } Assert.NotNull(foundResource); Assert.True(foundResource.Name == resource.Name); Assert.NotNull(foundResource.UserClaims); Assert.NotEmpty(foundResource.UserClaims); Assert.NotNull(foundResource.ApiSecrets); Assert.NotEmpty(foundResource.ApiSecrets); Assert.NotNull(foundResource.Scopes); Assert.NotEmpty(foundResource.Scopes); }
public void FindApiResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.ApiResources.Add(resource.ToEntity()); context.SaveChanges(); } IList <ApiResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = store.FindApiResourcesByScopeAsync(new List <string> { resource.Scopes.First().Name }).Result.ToList(); } Assert.NotEmpty(resources); Assert.NotNull(resources); Assert.NotNull(resources.First().UserClaims); Assert.NotEmpty(resources.First().UserClaims); Assert.NotNull(resources.First().ApiSecrets); Assert.NotEmpty(resources.First().ApiSecrets); Assert.NotNull(resources.First().Scopes); Assert.NotEmpty(resources.First().Scopes); Assert.True(resources.First().Scopes.Any(x => x.UserClaims.Any())); }
public async Task FindApiResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyResourcesRequestedReturned(DbContextOptions <ConfigurationDbContext> options) { var testIdentityResource = CreateIdentityTestResource(); var testApiResource = CreateApiResourceTestResource(); var testApiScope = CreateApiScopeTestResource(); testApiResource.Scopes.Add(testApiScope.Name); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.IdentityResources.Add(testIdentityResource.ToEntity()); context.ApiResources.Add(testApiResource.ToEntity()); context.ApiScopes.Add(testApiScope.ToEntity()); context.IdentityResources.Add(CreateIdentityTestResource().ToEntity()); context.ApiResources.Add(CreateApiResourceTestResource().ToEntity()); context.ApiScopes.Add(CreateApiScopeTestResource().ToEntity()); context.SaveChanges(); } IEnumerable <ApiResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = await store.FindApiResourcesByScopeNameAsync(new[] { testApiScope.Name }); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == testApiResource.Name)); }
public void FindResourcesAsync_WhenResourcesExist_ExpectResourcesReturned(DbContextOptions <ConfigurationDbContext> options) { var testIdentityResource = CreateIdentityTestResource(); var testApiResource = CreateApiTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.IdentityResources.Add(testIdentityResource.ToEntity()); context.ApiResources.Add(testApiResource.ToEntity()); context.SaveChanges(); } Resources resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = store.FindResourcesByScopeAsync(new List <string> { testIdentityResource.Name, testApiResource.Scopes.First().Name }).Result; } Assert.NotNull(resources); Assert.NotNull(resources.IdentityResources); Assert.NotEmpty(resources.IdentityResources); Assert.NotNull(resources.ApiResources); Assert.NotEmpty(resources.ApiResources); Assert.NotNull(resources.IdentityResources.FirstOrDefault(x => x.Name == testIdentityResource.Name)); Assert.NotNull(resources.ApiResources.FirstOrDefault(x => x.Name == testApiResource.Name)); }
public async Task FindApiScopesByNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateApiScopeTestResource(); using (var context = new ConfigurationDbContext(options)) { context.ApiScopes.Add(resource.ToEntity()); context.SaveChanges(); } IList <ApiScope> resources; using (var context = new ConfigurationDbContext(options)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create(), new NoneCancellationTokenProvider()); resources = (await store.FindApiScopesByNameAsync(new List <string> { resource.Name })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); var foundScope = resources.Single(); Assert.Equal(resource.Name, foundScope.Name); Assert.NotNull(foundScope.UserClaims); Assert.NotEmpty(foundScope.UserClaims); }