mirror of
https://github.com/bitwarden/server
synced 2026-02-25 08:53:21 +00:00
[PM-31052][PM-32469] Add V2UpgradeToken for key rotation without logout (#6995)
* User V2UpgradeToken for key rotation without logout * reset old v2 upgrade token on manual key rotation * sql migration fix * missing table column * missing view update * tests for V2UpgradeToken clearing on manual key rotation * V2 to V2 rotation causes logout. Updated wrapped key 1 to be a valid V2 encrypted string in tests. * integration tests failures - increase assert recent for date time type from 2 to 5 seconds (usually for UpdatedAt assertions) * repository test coverage * migration script update * new EF migration scripts * broken EF migration scripts fixed * refresh views due to User table alternation
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using Bit.Core.KeyManagement.Models.Data;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.KeyManagement.Models.Data;
|
||||
|
||||
public class V2UpgradeTokenDataTests
|
||||
{
|
||||
private static readonly string _mockEncryptedType2String =
|
||||
"2.AOs41Hd8OQiCPXjyJKCiDA==|O6OHgt2U2hJGBSNGnimJmg==|iD33s8B69C8JhYYhSa4V1tArjvLr8eEaGqOV7BRo5Jk=";
|
||||
private static readonly string _mockEncryptedType7String = "7.AOs41Hd8OQiCPXjyJKCiDA==";
|
||||
|
||||
[Fact]
|
||||
public void ToJson_SerializesCorrectly()
|
||||
{
|
||||
var data = new V2UpgradeTokenData
|
||||
{
|
||||
WrappedUserKey1 = _mockEncryptedType7String,
|
||||
WrappedUserKey2 = _mockEncryptedType2String
|
||||
};
|
||||
|
||||
var json = data.ToJson();
|
||||
|
||||
var expected = $"{{\"WrappedUserKey1\":\"{_mockEncryptedType7String}\",\"WrappedUserKey2\":\"{_mockEncryptedType2String}\"}}";
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromJson_ValidJson_DeserializesCorrectly()
|
||||
{
|
||||
var json = $"{{\"WrappedUserKey1\":\"{_mockEncryptedType7String}\",\"WrappedUserKey2\":\"{_mockEncryptedType2String}\"}}";
|
||||
|
||||
var result = V2UpgradeTokenData.FromJson(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(_mockEncryptedType7String, result.WrappedUserKey1);
|
||||
Assert.Equal(_mockEncryptedType2String, result.WrappedUserKey2);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void FromJson_NullOrEmptyInput_ReturnsNull(string? input)
|
||||
{
|
||||
var result = V2UpgradeTokenData.FromJson(input);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromJson_InvalidJson_ReturnsNull()
|
||||
{
|
||||
var result = V2UpgradeTokenData.FromJson("{\"invalid\": json}");
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user