Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

Fixing GetAllResourcesAsync not populating the Properties collection for identity resources #8

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Stores/ResourceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ where scopes.Contains(identityResource.Name)
public Task<Resources> GetAllResourcesAsync()
{
var identity = _context.IdentityResources
.Include(x => x.UserClaims);
.Include(x => x.UserClaims)
.Include(x => x.Properties)
.AsNoTracking();

var apis = _context.ApiResources
.Include(x => x.Secrets)
Expand Down
41 changes: 34 additions & 7 deletions test/IntegrationTests/Stores/ResourceStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ private static IdentityResource CreateIdentityTestResource()
DisplayName = Guid.NewGuid().ToString(),
Description = Guid.NewGuid().ToString(),
ShowInDiscoveryDocument = true,
UserClaims =
UserClaims =
{
JwtClaimTypes.Subject,
JwtClaimTypes.Name,
},
Properties = new Dictionary<string, string>
{
{ "key1", "value1"},
{ "key2", "value2"}
}
};
}
Expand All @@ -49,7 +54,7 @@ private static ApiResource CreateApiTestResource()
return new ApiResource()
{
Name = Guid.NewGuid().ToString(),
ApiSecrets = new List<Secret> {new Secret("secret".ToSha256())},
ApiSecrets = new List<Secret> { new Secret("secret".ToSha256()) },
Scopes =
new List<Scope>
{
Expand All @@ -59,7 +64,7 @@ private static ApiResource CreateApiTestResource()
UserClaims = {Guid.NewGuid().ToString()}
}
},
UserClaims =
UserClaims =
{
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Expand Down Expand Up @@ -139,11 +144,11 @@ public void GetAllResources_WhenAllResourcesRequested_ExpectAllResourcesIncludin
{
var visibleIdentityResource = CreateIdentityTestResource();
var visibleApiResource = CreateApiTestResource();
var hiddenIdentityResource = new IdentityResource{Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false};
var hiddenIdentityResource = new IdentityResource { Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false };
var hiddenApiResource = new ApiResource
{
Name = Guid.NewGuid().ToString(),
Scopes = new List<Scope> {new Scope {Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false}}
Scopes = new List<Scope> { new Scope { Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false } }
};

using (var context = new ConfigurationDbContext(options, StoreOptions))
Expand Down Expand Up @@ -271,7 +276,7 @@ public void FindApiResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCol
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();
resources = store.FindApiResourcesByScopeAsync(new List<string> { resource.Scopes.First().Name }).Result.ToList();
}

Assert.NotEmpty(resources);
Expand Down Expand Up @@ -303,12 +308,34 @@ public void FindApiResourcesByScopeAsync_WhenMultipleResourcesExist_ExpectOnlyRe
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();
resources = store.FindApiResourcesByScopeAsync(new List<string> { resource.Scopes.First().Name }).Result.ToList();
}

Assert.NotNull(resources);
Assert.NotEmpty(resources);
Assert.Equal(1, resources.Count);
}

[Theory, MemberData(nameof(TestDatabaseProviders))]
public void GetAllResources_WhenIdentityResourceHasProperties_ExpectCollectionPopulated(DbContextOptions<ConfigurationDbContext> options)
{
var identityResourceWithProperties = CreateIdentityTestResource();
using (var context = new ConfigurationDbContext(options, StoreOptions))
{
context.IdentityResources.Add(identityResourceWithProperties.ToEntity());
context.SaveChanges();
}

Resources resources;
using (var context = new ConfigurationDbContext(options, StoreOptions))
{
var store = new ResourceStore(context, FakeLogger<ResourceStore>.Create());
resources = store.GetAllResourcesAsync().Result;
}

Assert.NotNull(resources);
Assert.NotEmpty(resources.IdentityResources);
Assert.Contains(resources.IdentityResources, x => x.Properties.Any());
}
}
}