From ac06fe7c754ce699db3f2f06c307489c7c0ed253 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Mon, 9 Jun 2025 14:54:30 +0200 Subject: [PATCH] Add test --- .../Implementations/RotateUserAccountkeysCommand.cs | 2 +- .../UserKey/RotateUserAccountKeysCommandTests.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountkeysCommand.cs b/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountkeysCommand.cs index 3b2f7ea8bd..a9ce3f6e88 100644 --- a/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountkeysCommand.cs +++ b/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountkeysCommand.cs @@ -97,7 +97,7 @@ public class RotateUserAccountKeysCommand( throw new InvalidOperationException("User is in an invalid state for key rotation. User has a signature key pair, but the private key is not in v2 format, or vice versa."); } - async Task ValidateRotationModelSignatureKeyPairForV2User(RotateUserAccountKeysData model, User user) + public async Task ValidateRotationModelSignatureKeyPairForV2User(RotateUserAccountKeysData model, User user) { var currentSignatureKeyPair = await _userSignatureKeyPairRepository.GetByUserIdAsync(user.Id); if (model.AccountKeys == null || model.AccountKeys.SignatureKeyPairData == null) diff --git a/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs b/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs index ea573eb56e..d50d07e00b 100644 --- a/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs +++ b/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs @@ -243,7 +243,8 @@ public class RotateUserAccountKeysCommandTests model.AccountKeys.PublicKeyEncryptionKeyPairData = null; model.AccountKeys.SignatureKeyPairData = null; var saveEncryptedDataActions = new List(); - await Assert.ThrowsAsync(async () => await sutProvider.Sut.UpdateAccountKeys(model, user, saveEncryptedDataActions)); + var ex = await Assert.ThrowsAsync(async () => await sutProvider.Sut.UpdateAccountKeys(model, user, saveEncryptedDataActions)); + Assert.Equal("The provided user key encrypted account private key was not wrapped with AES-256-CBC-HMAC", ex.Message); } [Theory, BitAutoData] @@ -271,4 +272,13 @@ public class RotateUserAccountKeysCommandTests var exception = Assert.Throws(() => sutProvider.Sut.ValidateRotationModelSignatureKeyPairForV1UserAndUpgradeToV2(model, user, encryptedDataActions)); Assert.Equal("The provided public key encryption key pair data does not contain a valid signed public key.", exception.Message); } + + [Theory, BitAutoData] + public async Task ValidateRotationModelSignatureKeyPairForV2User_NoSignatureKeyPairThrows(SutProvider sutProvider, User user, RotateUserAccountKeysData model) + { + model.AccountKeys.SignatureKeyPairData = null; + var exception = await Assert.ThrowsAsync(async () => await sutProvider.Sut.ValidateRotationModelSignatureKeyPairForV2User(model, user)); + Assert.Equal("The provided signing key data is null, but the user already has signing keys.", exception.Message); + } + }