mirror of
https://github.com/bitwarden/server.git
synced 2025-06-20 10:58:07 -05:00
Fix tests
This commit is contained in:
parent
3c0ca482a9
commit
cc68b91188
@ -38,6 +38,9 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
public async Task RejectsEmailChange(SutProvider<RotateUserAccountKeysCommand> sutProvider, User user,
|
public async Task RejectsEmailChange(SutProvider<RotateUserAccountKeysCommand> sutProvider, User user,
|
||||||
RotateUserAccountKeysData model)
|
RotateUserAccountKeysData model)
|
||||||
{
|
{
|
||||||
|
user.PublicKey = "old-public";
|
||||||
|
user.PrivateKey = "2.xxx";
|
||||||
|
|
||||||
user.Kdf = Enums.KdfType.Argon2id;
|
user.Kdf = Enums.KdfType.Argon2id;
|
||||||
user.KdfIterations = 3;
|
user.KdfIterations = 3;
|
||||||
user.KdfMemory = 64;
|
user.KdfMemory = 64;
|
||||||
@ -48,6 +51,10 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
model.MasterPasswordUnlockData.KdfIterations = 3;
|
model.MasterPasswordUnlockData.KdfIterations = 3;
|
||||||
model.MasterPasswordUnlockData.KdfMemory = 64;
|
model.MasterPasswordUnlockData.KdfMemory = 64;
|
||||||
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
||||||
|
model.UserKeyEncryptedAccountPrivateKey = "2.xxx";
|
||||||
|
|
||||||
|
model.AccountPublicKey = user.PublicKey;
|
||||||
|
model.AccountKeys.PublicKeyEncryptionKeyPairData.PublicKey = user.PublicKey;
|
||||||
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sutProvider.Sut.RotateUserAccountKeysAsync(user, model));
|
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sutProvider.Sut.RotateUserAccountKeysAsync(user, model));
|
||||||
@ -57,6 +64,9 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
public async Task RejectsKdfChange(SutProvider<RotateUserAccountKeysCommand> sutProvider, User user,
|
public async Task RejectsKdfChange(SutProvider<RotateUserAccountKeysCommand> sutProvider, User user,
|
||||||
RotateUserAccountKeysData model)
|
RotateUserAccountKeysData model)
|
||||||
{
|
{
|
||||||
|
user.PublicKey = "old-public";
|
||||||
|
user.PrivateKey = "2.xxx";
|
||||||
|
|
||||||
user.Kdf = Enums.KdfType.Argon2id;
|
user.Kdf = Enums.KdfType.Argon2id;
|
||||||
user.KdfIterations = 3;
|
user.KdfIterations = 3;
|
||||||
user.KdfMemory = 64;
|
user.KdfMemory = 64;
|
||||||
@ -67,6 +77,7 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
model.MasterPasswordUnlockData.KdfIterations = 600000;
|
model.MasterPasswordUnlockData.KdfIterations = 600000;
|
||||||
model.MasterPasswordUnlockData.KdfMemory = null;
|
model.MasterPasswordUnlockData.KdfMemory = null;
|
||||||
model.MasterPasswordUnlockData.KdfParallelism = null;
|
model.MasterPasswordUnlockData.KdfParallelism = null;
|
||||||
|
model.UserKeyEncryptedAccountPrivateKey = "2.xxx";
|
||||||
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sutProvider.Sut.RotateUserAccountKeysAsync(user, model));
|
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sutProvider.Sut.RotateUserAccountKeysAsync(user, model));
|
||||||
@ -79,6 +90,7 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
{
|
{
|
||||||
user.PublicKey = "old-public";
|
user.PublicKey = "old-public";
|
||||||
user.PrivateKey = "2.xxx";
|
user.PrivateKey = "2.xxx";
|
||||||
|
|
||||||
user.Kdf = Enums.KdfType.Argon2id;
|
user.Kdf = Enums.KdfType.Argon2id;
|
||||||
user.KdfIterations = 3;
|
user.KdfIterations = 3;
|
||||||
user.KdfMemory = 64;
|
user.KdfMemory = 64;
|
||||||
@ -116,7 +128,6 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
var result = await sutProvider.Sut.RotateUserAccountKeysAsync(user, model);
|
var result = await sutProvider.Sut.RotateUserAccountKeysAsync(user, model);
|
||||||
|
|
||||||
Assert.Equal(IdentityResult.Success, result);
|
Assert.Equal(IdentityResult.Success, result);
|
||||||
@ -132,6 +143,7 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
user.KdfMemory = 64;
|
user.KdfMemory = 64;
|
||||||
user.KdfParallelism = 4;
|
user.KdfParallelism = 4;
|
||||||
user.PublicKey = "v2-public-key";
|
user.PublicKey = "v2-public-key";
|
||||||
|
user.PrivateKey = "2.xxx";
|
||||||
// Remove signature key pair
|
// Remove signature key pair
|
||||||
if (model.AccountKeys != null)
|
if (model.AccountKeys != null)
|
||||||
{
|
{
|
||||||
@ -143,6 +155,8 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
model.MasterPasswordUnlockData.KdfMemory = 64;
|
model.MasterPasswordUnlockData.KdfMemory = 64;
|
||||||
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
||||||
model.AccountPublicKey = user.PublicKey;
|
model.AccountPublicKey = user.PublicKey;
|
||||||
|
model.UserKeyEncryptedAccountPrivateKey = "2.xxx";
|
||||||
|
model.AccountKeys.PublicKeyEncryptionKeyPairData.PublicKey = user.PublicKey;
|
||||||
sutProvider.GetDependency<IUserSignatureKeyPairRepository>().GetByUserIdAsync(user.Id)
|
sutProvider.GetDependency<IUserSignatureKeyPairRepository>().GetByUserIdAsync(user.Id)
|
||||||
.Returns((SignatureKeyPairData)null);
|
.Returns((SignatureKeyPairData)null);
|
||||||
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
||||||
@ -159,6 +173,7 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
user.KdfMemory = 64;
|
user.KdfMemory = 64;
|
||||||
user.KdfParallelism = 4;
|
user.KdfParallelism = 4;
|
||||||
user.PublicKey = "v2-public-key";
|
user.PublicKey = "v2-public-key";
|
||||||
|
user.PrivateKey = "2.xxx";
|
||||||
// Ensure signature key pair is present
|
// Ensure signature key pair is present
|
||||||
if (model.AccountKeys != null)
|
if (model.AccountKeys != null)
|
||||||
{
|
{
|
||||||
@ -171,6 +186,8 @@ public class RotateUserAccountKeysCommandTests
|
|||||||
model.MasterPasswordUnlockData.KdfMemory = 64;
|
model.MasterPasswordUnlockData.KdfMemory = 64;
|
||||||
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
model.MasterPasswordUnlockData.KdfParallelism = 4;
|
||||||
model.AccountPublicKey = user.PublicKey;
|
model.AccountPublicKey = user.PublicKey;
|
||||||
|
model.UserKeyEncryptedAccountPrivateKey = "2.xxx";
|
||||||
|
model.AccountKeys.PublicKeyEncryptionKeyPairData.PublicKey = user.PublicKey;
|
||||||
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
sutProvider.GetDependency<IUserService>().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
var result = await sutProvider.Sut.RotateUserAccountKeysAsync(user, model);
|
var result = await sutProvider.Sut.RotateUserAccountKeysAsync(user, model);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user