Merge pull request #994 from abpframework/maliming/identityserver

Improve Identity Server unit testing.
pull/1162/head
Halil İbrahim Kalkan 7 years ago committed by GitHub
commit 444414add8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants;
@ -14,7 +16,8 @@ namespace Volo.Abp.IdentityServer
private readonly IApiResourceRepository _apiResourceRepository;
private readonly IClientRepository _clientRepository;
private readonly IIdentityResourceRepository _identityResourceRepository;
//private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository;
private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly AbpIdentityServerTestData _testData;
public AbpIdentityServerTestDataBuilder(
@ -22,15 +25,17 @@ namespace Volo.Abp.IdentityServer
IApiResourceRepository apiResourceRepository,
IClientRepository clientRepository,
IIdentityResourceRepository identityResourceRepository,
AbpIdentityServerTestData testData
/*IPersistentGrantRepository persistentGrantRepository*/)
IIdentityClaimTypeRepository identityClaimTypeRepository,
AbpIdentityServerTestData testData,
IPersistentGrantRepository persistentGrantRepository)
{
_testData = testData;
_guidGenerator = guidGenerator;
_apiResourceRepository = apiResourceRepository;
_clientRepository = clientRepository;
_identityResourceRepository = identityResourceRepository;
//_persistentGrantRepository = persistentGrantRepository;
_identityClaimTypeRepository = identityClaimTypeRepository;
_persistentGrantRepository = persistentGrantRepository;
}
public void Build()
@ -39,13 +44,30 @@ namespace Volo.Abp.IdentityServer
AddIdentityResources();
AddApiResources();
AddClients();
AddClaimTypes();
}
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()
@ -105,5 +127,12 @@ namespace Volo.Abp.IdentityServer
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2"));
_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);
}
}
}

@ -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