Browse Source

Merge pull request #994 from abpframework/maliming/identityserver

Improve Identity Server unit testing.
pull/1162/head
Halil İbrahim Kalkan 8 years ago
committed by GitHub
parent
commit
444414add8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs
  2. 0
      modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs
  3. 0
      modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs
  4. 11
      modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs
  5. 11
      modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs
  6. 45
      modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs
  7. 62
      modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs

0
modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs → modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs

0
modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs → modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs

0
modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs → modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs

11
modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.IdentityServer
{
public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
{
}
}

11
modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.IdentityServer
{
public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests<AbpIdentityServerMongoDbTestModule>
{
}
}

45
modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs

@ -1,6 +1,8 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.Grants;
@ -14,7 +16,8 @@ namespace Volo.Abp.IdentityServer
private readonly IApiResourceRepository _apiResourceRepository; private readonly IApiResourceRepository _apiResourceRepository;
private readonly IClientRepository _clientRepository; private readonly IClientRepository _clientRepository;
private readonly IIdentityResourceRepository _identityResourceRepository; private readonly IIdentityResourceRepository _identityResourceRepository;
//private readonly IPersistentGrantRepository _persistentGrantRepository; private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository;
private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly AbpIdentityServerTestData _testData; private readonly AbpIdentityServerTestData _testData;
public AbpIdentityServerTestDataBuilder( public AbpIdentityServerTestDataBuilder(
@ -22,15 +25,17 @@ namespace Volo.Abp.IdentityServer
IApiResourceRepository apiResourceRepository, IApiResourceRepository apiResourceRepository,
IClientRepository clientRepository, IClientRepository clientRepository,
IIdentityResourceRepository identityResourceRepository, IIdentityResourceRepository identityResourceRepository,
AbpIdentityServerTestData testData IIdentityClaimTypeRepository identityClaimTypeRepository,
/*IPersistentGrantRepository persistentGrantRepository*/) AbpIdentityServerTestData testData,
IPersistentGrantRepository persistentGrantRepository)
{ {
_testData = testData; _testData = testData;
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
_apiResourceRepository = apiResourceRepository; _apiResourceRepository = apiResourceRepository;
_clientRepository = clientRepository; _clientRepository = clientRepository;
_identityResourceRepository = identityResourceRepository; _identityResourceRepository = identityResourceRepository;
//_persistentGrantRepository = persistentGrantRepository; _identityClaimTypeRepository = identityClaimTypeRepository;
_persistentGrantRepository = persistentGrantRepository;
} }
public void Build() public void Build()
@ -39,13 +44,30 @@ namespace Volo.Abp.IdentityServer
AddIdentityResources(); AddIdentityResources();
AddApiResources(); AddApiResources();
AddClients(); AddClients();
AddClaimTypes();
} }
private void AddPersistedGrants() private void AddPersistedGrants()
{ {
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())); _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())); {
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
Key = "PersistedGrantKey1",
SubjectId = "PersistedGrantSubjectId1",
ClientId = "PersistedGrantClientId1",
Type = "PersistedGrantType1"
});
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{
Key = "PersistedGrantKey2",
SubjectId = "PersistedGrantSubjectId2"
});
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{
Key = "PersistedGrantKey3",
SubjectId = "PersistedGrantSubjectId3"
});
} }
private void AddIdentityResources() private void AddIdentityResources()
@ -105,5 +127,12 @@ namespace Volo.Abp.IdentityServer
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2"));
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3"));
} }
private void AddClaimTypes()
{
var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null,
IdentityClaimValueType.Int);
_identityClaimTypeRepository.Insert(ageClaim);
}
} }
} }

62
modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.Modularity;
using Xunit;
namespace Volo.Abp.IdentityServer
{
public abstract class PersistentGrantRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IPersistentGrantRepository _persistentGrantRepository;
protected PersistentGrantRepository_Tests()
{
_persistentGrantRepository = GetRequiredService<IPersistentGrantRepository>();
}
[Fact]
public async Task FindByKeyAsync()
{
(await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1")).ShouldNotBeNull();
}
[Fact]
public async Task GetListBySubjectIdAsync()
{
var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1");
persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1");
}
[Fact]
public async Task DeleteBySubjectIdAndClientId()
{
await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1");
var persistedGrants = await _persistentGrantRepository.GetListAsync();
persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldNotContain(x =>
x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" &&
x.ClientId == "PersistedGrantClientId1");
}
[Fact]
public async Task DeleteBySubjectIdAndClientIdAndType()
{
await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1",
"PersistedGrantClientId1");
var persistedGrants = await _persistentGrantRepository.GetListAsync();
persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldNotContain(x =>
x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" &&
x.ClientId == "PersistedGrantClientId1" && x.Type == "PersistedGrantClientId1");
}
}
}
Loading…
Cancel
Save