diff --git a/src/Open.IdentityServer/src/Stores/Compatibility/IdentityServerSigningCredentialStore.cs b/src/Open.IdentityServer/src/Stores/Compatibility/IdentityServerSigningCredentialStore.cs index f177df7f5..12588c90c 100644 --- a/src/Open.IdentityServer/src/Stores/Compatibility/IdentityServerSigningCredentialStore.cs +++ b/src/Open.IdentityServer/src/Stores/Compatibility/IdentityServerSigningCredentialStore.cs @@ -28,6 +28,6 @@ public async Task GetSigningCredentialsAsync() .Select(dataProtectedIdentityServerKeyMaterialConverter.Convert) .OrderByDescending(x => x.Created) .Select(x => x.Credentials) - .First(); + .FirstOrDefault(); } } \ No newline at end of file diff --git a/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerSigningCredentialStoreTests.cs b/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerSigningCredentialStoreTests.cs index 9bf6fd918..302e18a60 100644 --- a/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerSigningCredentialStoreTests.cs +++ b/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerSigningCredentialStoreTests.cs @@ -325,4 +325,17 @@ public async Task GetSigningCredentialsAsync_WhenProtected_AndSingleECDsaKeyWrap actual.Should().BeEquivalentTo(expectedSigningCredentials); } + + [Fact] + public async Task GetSigningCredentialsAsync_WhenTableIsEmpty_ShouldReturnNull() + { + Mock.Get(_identityServerKeyStore) + .Setup(x => x.GetKeys()) + .Returns([]); + + var sut = CreateSut(); + var actual = await sut.GetSigningCredentialsAsync(); + + actual.Should().BeNull(); + } } \ No newline at end of file diff --git a/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerValidationKeysStoreTests.cs b/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerValidationKeysStoreTests.cs index d9b145d5c..6f0ae28c5 100644 --- a/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerValidationKeysStoreTests.cs +++ b/src/Open.IdentityServer/test/Open.IdentityServer.UnitTests/Stores/Compatibility/IdentityServerValidationKeysStoreTests.cs @@ -177,4 +177,17 @@ public async Task GetValidationKeysAsync_ShouldReturnCollectionSecurityKeyInfo_A actual.Should().BeEquivalentTo(expectedCredentials); } + + [Fact] + public async Task GetValidationKeysAsync_WhenTableIsEmpty_ShouldReturnEmptyList() + { + Mock.Get(_identityServerKeyStore) + .Setup(x => x.GetKeys()) + .Returns([]); + + var sut = CreateSut(); + var actual = await sut.GetValidationKeysAsync(); + + actual.Should().BeEmpty(); + } } \ No newline at end of file