Browse Source

Added new PersistentGrant tests

pull/190/head
Alper Ebicoglu 9 years ago
parent
commit
06b846c929
  1. 31
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs
  2. 58
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs

31
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs

@ -53,9 +53,38 @@ namespace Volo.Abp.IdentityServer
Key = "38", Key = "38",
ClientId = "TestClientId-38", ClientId = "TestClientId-38",
Type = "TestType-38", Type = "TestType-38",
SubjectId = "TestSubject-38", SubjectId = "TestSubject",
Data = "TestData-38" Data = "TestData-38"
}); });
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{
Key = "37",
ClientId = "TestClientId-37",
Type = "TestType-37",
SubjectId = "TestSubject",
Data = "TestData-37"
});
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{
Key = "36",
ClientId = "TestClientId-X",
Type = "TestType-36",
SubjectId = "TestSubject-X",
Data = "TestData-36"
});
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{
Key = "35",
ClientId = "TestClientId-X",
Type = "TestType-35",
SubjectId = "TestSubject-X",
Data = "TestData-35"
});
} }
} }
} }

58
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs

@ -1,9 +1,11 @@
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using IdentityServer4.Models; using IdentityServer4.Models;
using IdentityServer4.Stores; using IdentityServer4.Stores;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Shouldly; using Shouldly;
using Volo.Abp.Uow;
using Xunit; using Xunit;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
@ -11,10 +13,12 @@ namespace Volo.Abp.IdentityServer.Clients
public class PersistentGrantStore_Tests : AbpIdentityServerTestBase public class PersistentGrantStore_Tests : AbpIdentityServerTestBase
{ {
private readonly IPersistedGrantStore _persistedGrantStore; private readonly IPersistedGrantStore _persistedGrantStore;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public PersistentGrantStore_Tests() public PersistentGrantStore_Tests()
{ {
_persistedGrantStore = ServiceProvider.GetRequiredService<IPersistedGrantStore>(); _persistedGrantStore = ServiceProvider.GetRequiredService<IPersistedGrantStore>();
_unitOfWorkManager = ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
} }
[Fact] [Fact]
@ -33,7 +37,7 @@ namespace Volo.Abp.IdentityServer.Clients
//Assert //Assert
client.ShouldNotBeNull(); client.ShouldNotBeNull();
client.ClientId.ShouldBe("TestClientId-38"); client.ClientId.ShouldBe("TestClientId-38");
client.SubjectId.ShouldBe("TestSubject-38"); client.SubjectId.ShouldBe("TestSubject");
client.Data.ShouldContain("TestData-38"); client.Data.ShouldContain("TestData-38");
client.Type.ShouldContain("TestType-38"); client.Type.ShouldContain("TestType-38");
} }
@ -47,7 +51,7 @@ namespace Volo.Abp.IdentityServer.Clients
Key = "39", Key = "39",
ClientId = "TestClientId-39", ClientId = "TestClientId-39",
Type = "TestType-39", Type = "TestType-39",
SubjectId = "TestSubject-39", SubjectId = "TestSubject",
Data = "TestData-39", Data = "TestData-39",
Expiration = new DateTime(2018, 1, 6, 21, 22, 23), Expiration = new DateTime(2018, 1, 6, 21, 22, 23),
CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) CreationTime = new DateTime(2018, 1, 5, 19, 20, 21)
@ -58,7 +62,7 @@ namespace Volo.Abp.IdentityServer.Clients
persistedGrant.Key.ShouldBe("39"); persistedGrant.Key.ShouldBe("39");
persistedGrant.ClientId.ShouldBe("TestClientId-39"); persistedGrant.ClientId.ShouldBe("TestClientId-39");
persistedGrant.Type.ShouldBe("TestType-39"); persistedGrant.Type.ShouldBe("TestType-39");
persistedGrant.SubjectId.ShouldBe("TestSubject-39"); persistedGrant.SubjectId.ShouldBe("TestSubject");
persistedGrant.Data.ShouldBe("TestData-39"); persistedGrant.Data.ShouldBe("TestData-39");
persistedGrant.Expiration.HasValue.ShouldBe(true); persistedGrant.Expiration.HasValue.ShouldBe(true);
@ -78,10 +82,52 @@ namespace Volo.Abp.IdentityServer.Clients
} }
[Fact] [Fact]
public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() public async Task GetAllAsync_Should_Get_All_PersistedGrants_For_A_Given_SubjectId()
{ {
var persistentGrant = await _persistedGrantStore.GetAllAsync("not-existing-id"); //Act
persistentGrant.ShouldBeNull(); var persistentGrants = await _persistedGrantStore.GetAllAsync("TestSubject");
//Assert
var persistedGrants = persistentGrants as PersistedGrant[] ?? persistentGrants.ToArray();
persistedGrants.ShouldNotBe(null);
persistedGrants.Length.ShouldBe(2);
persistedGrants[0].SubjectId.ShouldBe("TestSubject");
persistedGrants[1].SubjectId.ShouldBe("TestSubject");
}
[Fact]
public async Task RemoveAsync_Should_Remove_PeristedGrant()
{
//Arrange
await _persistedGrantStore.StoreAsync(new PersistedGrant
{
Key = "#1P3R"
});
//Act
await _persistedGrantStore.RemoveAsync("#1P3R");
//Assert
var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R");
persistedGrant.ShouldBe(null);
}
[Fact]
public async Task RemoveAllAsync_Should_RemoveAll_PeristedGrants_For_A_Given_Subject_And_ClientId()
{
//Arrange
var persistedGrantsWithTestSubjectX = await _persistedGrantStore.GetAllAsync("TestSubject-X");
var persistedGrantsWithTestSubjectXBeforeLength = persistedGrantsWithTestSubjectX.ToArray().Length;
//Act
await _persistedGrantStore.RemoveAllAsync("TestSubject-X", "TestClientId-X");
//Assert
persistedGrantsWithTestSubjectXBeforeLength.ShouldBe(2);
var persistedGrants = (await _persistedGrantStore.GetAllAsync("TestClientId-37")).ToArray();
persistedGrants.ShouldNotBe(null);
persistedGrants.Length.ShouldBe(0);
} }
} }

Loading…
Cancel
Save