mirror of
https://github.com/bitwarden/server
synced 2025-12-19 17:53:44 +00:00
Add UpdateAccountCryptographicState repository function (#6669)
* Add user repository update function for account cryptographic state * Remove comment * Remove transaction logic * Fix security version * Apply feedback * Update tests * Add support for external actions
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.KeyManagement.Enums;
|
||||
using Bit.Core.KeyManagement.Models.Data;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
@@ -313,4 +315,66 @@ public class UserRepositoryTests
|
||||
Assert.Equal(sqlUser.MasterPasswordHint, updatedUser.MasterPasswordHint);
|
||||
Assert.Equal(sqlUser.Email, updatedUser.Email);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async Task UpdateAccountCryptographicStateAsync_Works_DataMatches(
|
||||
User user,
|
||||
List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
// Test for V1 user (no signature key pair or security state)
|
||||
var accountKeysDataV1 = new UserAccountKeysData
|
||||
{
|
||||
PublicKeyEncryptionKeyPairData = new PublicKeyEncryptionKeyPairData(
|
||||
wrappedPrivateKey: "v1-wrapped-private-key",
|
||||
publicKey: "v1-public-key"
|
||||
)
|
||||
};
|
||||
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var createdUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.SetV2AccountCryptographicStateAsync(createdUser.Id, accountKeysDataV1);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var updatedUser = await sut.GetByIdAsync(createdUser.Id);
|
||||
Assert.Equal("v1-public-key", updatedUser.PublicKey);
|
||||
Assert.Equal("v1-wrapped-private-key", updatedUser.PrivateKey);
|
||||
Assert.Null(updatedUser.SignedPublicKey);
|
||||
Assert.Null(updatedUser.SecurityState);
|
||||
Assert.Null(updatedUser.SecurityVersion);
|
||||
}
|
||||
|
||||
// Test for V2 user (with signature key pair and security state)
|
||||
var accountKeysDataV2 = new UserAccountKeysData
|
||||
{
|
||||
PublicKeyEncryptionKeyPairData = new PublicKeyEncryptionKeyPairData(
|
||||
wrappedPrivateKey: "v2-wrapped-private-key",
|
||||
publicKey: "v2-public-key",
|
||||
signedPublicKey: "v2-signed-public-key"
|
||||
),
|
||||
SignatureKeyPairData = new SignatureKeyPairData(
|
||||
signatureAlgorithm: SignatureAlgorithm.Ed25519,
|
||||
wrappedSigningKey: "v2-wrapped-signing-key",
|
||||
verifyingKey: "v2-verifying-key"
|
||||
),
|
||||
SecurityStateData = new SecurityStateData
|
||||
{
|
||||
SecurityState = "v2-security-state",
|
||||
SecurityVersion = 2
|
||||
}
|
||||
};
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
await sqlUserRepo.SetV2AccountCryptographicStateAsync(sqlUser.Id, accountKeysDataV2);
|
||||
|
||||
var updatedSqlUser = await sqlUserRepo.GetByIdAsync(sqlUser.Id);
|
||||
Assert.Equal("v2-public-key", updatedSqlUser.PublicKey);
|
||||
Assert.Equal("v2-wrapped-private-key", updatedSqlUser.PrivateKey);
|
||||
Assert.Equal("v2-signed-public-key", updatedSqlUser.SignedPublicKey);
|
||||
Assert.Equal("v2-security-state", updatedSqlUser.SecurityState);
|
||||
Assert.Equal(2, updatedSqlUser.SecurityVersion);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user