Skip to content

Commit b90e925

Browse files
Merge pull request #74 from NetDevPack/copilot/fix-pull-request-job-failure
Fix flaky `pull-request` job by honoring `GetLastKeys` arguments
2 parents 3f9b359 + 5e7cd65 commit b90e925

7 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/NetDevPack.Security.Jwt.Core/Jwt/JwtService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public async Task<EncryptingCredentials> GetCurrentEncryptingCredentials()
6161

6262
public Task<ReadOnlyCollection<KeyMaterial>> GetLastKeys(int? i = null)
6363
{
64-
return _store.GetLastKeys(_options.Value.AlgorithmsToKeep, null);
64+
return _store.GetLastKeys(i ?? _options.Value.AlgorithmsToKeep, null);
6565
}
6666

6767
public Task<ReadOnlyCollection<KeyMaterial>> GetLastKeys(int i, JwtKeyType jwtKeyType)
6868
{
69-
return _store.GetLastKeys(_options.Value.AlgorithmsToKeep, jwtKeyType);
69+
return _store.GetLastKeys(i, jwtKeyType);
7070
}
7171

7272
private async Task<bool> CheckCompatibility(KeyMaterial currentKey, JwtKeyType jwtKeyType)

tests/NetDevPack.Security.Jwt.Tests/JwtTests/JweTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace NetDevPack.Security.Jwt.Tests.JwtTests
1919
{
20+
[Collection(InMemoryStoreCollection.Name)]
2021
public class JweTests : IClassFixture<WarmupInMemoryStore>
2122
{
2223
private readonly IJwtService _jwksService;

tests/NetDevPack.Security.Jwt.Tests/JwtTests/JwtServiceTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace NetDevPack.Security.Jwt.Tests.JwtTests
1515
{
16+
[Collection(InMemoryStoreCollection.Name)]
1617
public class JwtServiceTest : IClassFixture<WarmupInMemoryStore>
1718
{
1819
private readonly IJwtService _jwksService;
@@ -80,7 +81,8 @@ public async Task ShouldGenerateFiveKeys()
8081
keysGenerated.Add(sign);
8182
}
8283

83-
var current = await _jwksService.GetLastKeys(5);
84+
var current = await _jwksService.GetLastKeys(5, NetDevPack.Security.Jwt.Core.Jwa.JwtKeyType.Jws);
85+
current.Should().HaveCount(5);
8486
foreach (var securityKey in current)
8587
{
8688
keysGenerated.Should().Contain(s => s.KeyId == securityKey.KeyId);

tests/NetDevPack.Security.Jwt.Tests/JwtTests/JwtTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace NetDevPack.Security.Jwt.Tests.JwtTests
1616
{
17+
[Collection(InMemoryStoreCollection.Name)]
1718
public class JwsTests : IClassFixture<WarmupInMemoryStore>
1819
{
1920
private readonly IJwtService _service;

tests/NetDevPack.Security.Jwt.Tests/StoreTests/GenericStoreServiceTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ public async Task Should_Generate_Different_Keys_For_JWS_And_JWE_And_Retrieve_Th
533533
var getLastJwe = (await _jwtService.GetLastKeys(1, JwtKeyType.Jwe)).First();
534534
var getLastJws = (await _jwtService.GetLastKeys(1, JwtKeyType.Jws)).First();
535535

536+
getLast2DefaultVal.Should().HaveCount(2);
536537
jws.KeyId.Should().NotBe(jwe.KeyId);
537538
getLastJws.KeyId.Should().NotBe(getLastJwe.KeyId);
538539
defaultVal.KeyId.Should().Be(jws.KeyId);

tests/NetDevPack.Security.Jwt.Tests/StoreTests/InMemoryStoreTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace NetDevPack.Security.Jwt.Tests.StoreTests;
55

6+
[Collection(InMemoryStoreCollection.Name)]
67
[Trait("Category", "InMemory Tests")]
78
public class InMemoryStoreTests : GenericStoreServiceTest<WarmupInMemoryStore>
89
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Xunit;
2+
3+
namespace NetDevPack.Security.Jwt.Tests.Warmups;
4+
5+
[CollectionDefinition(Name)]
6+
public class InMemoryStoreCollection
7+
{
8+
public const string Name = "InMemory Store";
9+
}

0 commit comments

Comments
 (0)