1
0
mirror of https://github.com/bitwarden/server synced 2025-12-27 05:33:17 +00:00

Added MasterPasswordUnlock to UserDecryptionOptions as part of identity response (#6093)

This commit is contained in:
Maciej Zieniuk
2025-07-28 17:34:42 +02:00
committed by GitHub
parent d407c164b6
commit 59e7bc7438
7 changed files with 247 additions and 27 deletions

View File

@@ -36,7 +36,15 @@ public class IdentityServerSsoTests
public async Task Test_MasterPassword_DecryptionType()
{
// Arrange
using var responseBody = await RunSuccessTestAsync(MemberDecryptionType.MasterPassword);
User? expectedUser = null;
using var responseBody = await RunSuccessTestAsync(async factory =>
{
var database = factory.GetDatabaseContext();
expectedUser = await database.Users.SingleAsync(u => u.Email == TestEmail);
Assert.NotNull(expectedUser);
}, MemberDecryptionType.MasterPassword);
Assert.NotNull(expectedUser);
// Assert
// If the organization has a member decryption type of MasterPassword that should be the only option in the reply
@@ -47,13 +55,33 @@ public class IdentityServerSsoTests
// Expected to look like:
// "UserDecryptionOptions": {
// "Object": "userDecryptionOptions"
// "HasMasterPassword": true
// "HasMasterPassword": true,
// "MasterPasswordUnlock": {
// "Kdf": {
// "KdfType": 0,
// "Iterations": 600000
// },
// "MasterKeyEncryptedUserKey": "2.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==|QmFzZTY0UGFydA==",
// "Salt": "sso_user@email.com"
// }
// }
AssertHelper.AssertJsonProperty(userDecryptionOptions, "HasMasterPassword", JsonValueKind.True);
// One property for the Object and one for master password
Assert.Equal(2, userDecryptionOptions.EnumerateObject().Count());
var objectString = AssertHelper.AssertJsonProperty(userDecryptionOptions, "Object", JsonValueKind.String).ToString();
Assert.Equal("userDecryptionOptions", objectString);
var masterPasswordUnlock = AssertHelper.AssertJsonProperty(userDecryptionOptions, "MasterPasswordUnlock", JsonValueKind.Object);
// MasterPasswordUnlock.Kdf
var kdf = AssertHelper.AssertJsonProperty(masterPasswordUnlock, "Kdf", JsonValueKind.Object);
var kdfType = AssertHelper.AssertJsonProperty(kdf, "KdfType", JsonValueKind.Number).GetInt32();
Assert.Equal((int)expectedUser.Kdf, kdfType);
var kdfIterations = AssertHelper.AssertJsonProperty(kdf, "Iterations", JsonValueKind.Number).GetInt32();
Assert.Equal(expectedUser.KdfIterations, kdfIterations);
// MasterPasswordUnlock.MasterKeyEncryptedUserKey
var masterKeyEncryptedUserKey = AssertHelper.AssertJsonProperty(masterPasswordUnlock, "MasterKeyEncryptedUserKey", JsonValueKind.String).ToString();
Assert.Equal(expectedUser.Key, masterKeyEncryptedUserKey);
// MasterPasswordUnlock.Salt
var salt = AssertHelper.AssertJsonProperty(masterPasswordUnlock, "Salt", JsonValueKind.String).ToString();
Assert.Equal(TestEmail, salt);
}
[Fact]