mirror of
https://github.com/bitwarden/server.git
synced 2025-06-20 02:48:03 -05:00
Add test
This commit is contained in:
parent
06d8de67c5
commit
ac06fe7c75
@ -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.");
|
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);
|
var currentSignatureKeyPair = await _userSignatureKeyPairRepository.GetByUserIdAsync(user.Id);
|
||||||
if (model.AccountKeys == null || model.AccountKeys.SignatureKeyPairData == null)
|
if (model.AccountKeys == null || model.AccountKeys.SignatureKeyPairData == null)
|
||||||
|
@ -243,7 +243,8 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
model.AccountKeys.PublicKeyEncryptionKeyPairData = null;
|
model.AccountKeys.PublicKeyEncryptionKeyPairData = null;
|
||||||
model.AccountKeys.SignatureKeyPairData = null;
|
model.AccountKeys.SignatureKeyPairData = null;
|
||||||
var saveEncryptedDataActions = new List<Core.KeyManagement.UserKey.UpdateEncryptedDataForKeyRotation>();
|
var saveEncryptedDataActions = new List<Core.KeyManagement.UserKey.UpdateEncryptedDataForKeyRotation>();
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sutProvider.Sut.UpdateAccountKeys(model, user, saveEncryptedDataActions));
|
var ex = await Assert.ThrowsAsync<InvalidOperationException>(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]
|
[Theory, BitAutoData]
|
||||||
@ -271,4 +272,13 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
var exception = Assert.Throws<InvalidOperationException>(() => sutProvider.Sut.ValidateRotationModelSignatureKeyPairForV1UserAndUpgradeToV2(model, user, encryptedDataActions));
|
var exception = Assert.Throws<InvalidOperationException>(() => 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);
|
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<RotateUserAccountKeysCommand> sutProvider, User user, RotateUserAccountKeysData model)
|
||||||
|
{
|
||||||
|
model.AccountKeys.SignatureKeyPairData = null;
|
||||||
|
var exception = await Assert.ThrowsAsync<InvalidOperationException>(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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user