mirror of
https://github.com/bitwarden/server
synced 2026-02-22 04:13:43 +00:00
fix(register): [PM-27084] Account Register Uses New Data Types - Fixed up tests a little more.
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
#nullable disable
|
||||
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Auth.Enums;
|
||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||
@@ -41,7 +38,7 @@ public class AccountsController : Controller
|
||||
private readonly IFeatureService _featureService;
|
||||
private readonly IDataProtectorTokenFactory<RegistrationEmailVerificationTokenable> _registrationEmailVerificationTokenDataFactory;
|
||||
|
||||
private readonly byte[] _defaultKdfHmacKey = null;
|
||||
private readonly byte[]? _defaultKdfHmacKey = null;
|
||||
private static readonly List<UserKdfInformation> _defaultKdfResults =
|
||||
[
|
||||
// The first result (index 0) should always return the "normal" default.
|
||||
@@ -147,7 +144,7 @@ public class AccountsController : Controller
|
||||
User user = model.ToUser();
|
||||
|
||||
// Users will either have an emailed token or an email verification token - not both.
|
||||
IdentityResult identityResult = null;
|
||||
IdentityResult? identityResult = null;
|
||||
|
||||
// PM-28143 - Just use the MasterPasswordAuthenticationData.MasterPasswordAuthenticationHash
|
||||
string masterPasswordHash = model.MasterPasswordAuthentication?.MasterPasswordAuthenticationHash
|
||||
@@ -159,14 +156,14 @@ public class AccountsController : Controller
|
||||
identityResult = await _registerUserCommand.RegisterUserViaEmailVerificationToken(
|
||||
user,
|
||||
masterPasswordHash,
|
||||
model.EmailVerificationToken);
|
||||
model.EmailVerificationToken!);
|
||||
return ProcessRegistrationResult(identityResult, user);
|
||||
|
||||
case RegisterFinishTokenType.OrganizationInvite:
|
||||
identityResult = await _registerUserCommand.RegisterUserViaOrganizationInviteToken(
|
||||
user,
|
||||
masterPasswordHash,
|
||||
model.OrgInviteToken,
|
||||
model.OrgInviteToken!,
|
||||
model.OrganizationUserId);
|
||||
return ProcessRegistrationResult(identityResult, user);
|
||||
|
||||
@@ -174,23 +171,23 @@ public class AccountsController : Controller
|
||||
identityResult = await _registerUserCommand.RegisterUserViaOrganizationSponsoredFreeFamilyPlanInviteToken(
|
||||
user,
|
||||
masterPasswordHash,
|
||||
model.OrgSponsoredFreeFamilyPlanToken);
|
||||
model.OrgSponsoredFreeFamilyPlanToken!);
|
||||
return ProcessRegistrationResult(identityResult, user);
|
||||
|
||||
case RegisterFinishTokenType.EmergencyAccessInvite:
|
||||
identityResult = await _registerUserCommand.RegisterUserViaAcceptEmergencyAccessInviteToken(
|
||||
user,
|
||||
masterPasswordHash,
|
||||
model.AcceptEmergencyAccessInviteToken,
|
||||
(Guid)model.AcceptEmergencyAccessId);
|
||||
model.AcceptEmergencyAccessInviteToken!,
|
||||
(Guid)model.AcceptEmergencyAccessId!);
|
||||
return ProcessRegistrationResult(identityResult, user);
|
||||
|
||||
case RegisterFinishTokenType.ProviderInvite:
|
||||
identityResult = await _registerUserCommand.RegisterUserViaProviderInviteToken(
|
||||
user,
|
||||
masterPasswordHash,
|
||||
model.ProviderInviteToken,
|
||||
(Guid)model.ProviderUserId);
|
||||
model.ProviderInviteToken!,
|
||||
(Guid)model.ProviderUserId!);
|
||||
return ProcessRegistrationResult(identityResult, user);
|
||||
|
||||
default:
|
||||
|
||||
@@ -11,7 +11,6 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.KeyManagement.Models.Api.Request;
|
||||
using Bit.Core.KeyManagement.Models.Data;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
@@ -963,7 +962,7 @@ public class AccountsControllerTests : IDisposable
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Assert.ThrowsAsync<BadRequestException>(() => _sut.PostRegisterFinish(model));
|
||||
Assert.Equal("KdfType couldn't be found on either the MasterPasswordUnlockData or the Kdf property passed in.", ex.Message);
|
||||
Assert.Equal("KdfType couldn't be found on either the MasterPasswordUnlock or the Kdf property passed in.", ex.Message);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
@@ -1001,7 +1000,7 @@ public class AccountsControllerTests : IDisposable
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Assert.ThrowsAsync<BadRequestException>(() => _sut.PostRegisterFinish(model));
|
||||
Assert.Equal("KdfIterations couldn't be found on either the MasterPasswordUnlockData or the KdfIterations property passed in.", ex.Message);
|
||||
Assert.Equal("KdfIterations couldn't be found on either the MasterPasswordUnlock or the KdfIterations property passed in.", ex.Message);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
@@ -1192,7 +1191,7 @@ public class AccountsControllerTests : IDisposable
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<BadRequestException>(() => model.Validate(ctx).ToList());
|
||||
Assert.Equal("Master password hash and hash are not equal.", ex.Message);
|
||||
Assert.Equal("AuthenticationData MasterPasswordHash and root level MasterPasswordHash provided and are not equal. Only provide one.", ex.Message);
|
||||
}
|
||||
|
||||
private void SetDefaultKdfHmacKey(byte[]? newKey)
|
||||
|
||||
Reference in New Issue
Block a user