1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

[SG-199] Move MP hint to MP change form (#2080)

* chore: backend changes

* fixed: test

* fix: lint
This commit is contained in:
Brandon Maharaj 2022-07-11 09:28:14 -04:00 committed by GitHub
parent e9a88b5505
commit 0a334cc928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 7 deletions

View File

@ -211,7 +211,7 @@ namespace Bit.Api.Controllers
} }
var result = await _userService.ChangePasswordAsync(user, model.MasterPasswordHash, var result = await _userService.ChangePasswordAsync(user, model.MasterPasswordHash,
model.NewMasterPasswordHash, model.Key); model.NewMasterPasswordHash, model.MasterPasswordHint, model.Key);
if (result.Succeeded) if (result.Succeeded)
{ {
return; return;

View File

@ -7,6 +7,8 @@ namespace Bit.Api.Models.Request.Accounts
[Required] [Required]
[StringLength(300)] [StringLength(300)]
public string NewMasterPasswordHash { get; set; } public string NewMasterPasswordHash { get; set; }
[StringLength(50)]
public string MasterPasswordHint { get; set; }
[Required] [Required]
public string Key { get; set; } public string Key { get; set; }
} }

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Entities; using Bit.Core.Entities;
namespace Bit.Api.Models.Request.Accounts namespace Bit.Api.Models.Request.Accounts
@ -8,6 +9,7 @@ namespace Bit.Api.Models.Request.Accounts
[StringLength(50)] [StringLength(50)]
public string Name { get; set; } public string Name { get; set; }
[StringLength(50)] [StringLength(50)]
[Obsolete("Changes will be made via the 'password' endpoint going forward.")]
public string MasterPasswordHint { get; set; } public string MasterPasswordHint { get; set; }
public User ToUser(User existingUser) public User ToUser(User existingUser)

View File

@ -29,7 +29,7 @@ namespace Bit.Core.Services
Task InitiateEmailChangeAsync(User user, string newEmail); Task InitiateEmailChangeAsync(User user, string newEmail);
Task<IdentityResult> ChangeEmailAsync(User user, string masterPassword, string newEmail, string newMasterPassword, Task<IdentityResult> ChangeEmailAsync(User user, string masterPassword, string newEmail, string newMasterPassword,
string token, string key); string token, string key);
Task<IdentityResult> ChangePasswordAsync(User user, string masterPassword, string newMasterPassword, string key); Task<IdentityResult> ChangePasswordAsync(User user, string masterPassword, string newMasterPassword, string passwordHint, string key);
Task<IdentityResult> SetPasswordAsync(User user, string newMasterPassword, string key, string orgIdentifier = null); Task<IdentityResult> SetPasswordAsync(User user, string newMasterPassword, string key, string orgIdentifier = null);
Task<IdentityResult> SetKeyConnectorKeyAsync(User user, string key, string orgIdentifier); Task<IdentityResult> SetKeyConnectorKeyAsync(User user, string key, string orgIdentifier);
Task<IdentityResult> ConvertToKeyConnectorAsync(User user); Task<IdentityResult> ConvertToKeyConnectorAsync(User user);

View File

@ -596,7 +596,7 @@ namespace Bit.Core.Services
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<IdentityResult> ChangePasswordAsync(User user, string masterPassword, string newMasterPassword, public async Task<IdentityResult> ChangePasswordAsync(User user, string masterPassword, string newMasterPassword, string passwordHint,
string key) string key)
{ {
if (user == null) if (user == null)
@ -614,6 +614,7 @@ namespace Bit.Core.Services
user.RevisionDate = user.AccountRevisionDate = DateTime.UtcNow; user.RevisionDate = user.AccountRevisionDate = DateTime.UtcNow;
user.Key = key; user.Key = key;
user.MasterPasswordHint = passwordHint;
await _userRepository.ReplaceAsync(user); await _userRepository.ReplaceAsync(user);
await _eventService.LogUserEventAsync(user.Id, EventType.User_ChangedPassword); await _eventService.LogUserEventAsync(user.Id, EventType.User_ChangedPassword);

View File

@ -279,12 +279,12 @@ namespace Bit.Api.Test.Controllers
{ {
var user = GenerateExampleUser(); var user = GenerateExampleUser();
ConfigureUserServiceToReturnValidPrincipalFor(user); ConfigureUserServiceToReturnValidPrincipalFor(user);
_userService.ChangePasswordAsync(user, default, default, default) _userService.ChangePasswordAsync(user, default, default, default, default)
.Returns(Task.FromResult(IdentityResult.Success)); .Returns(Task.FromResult(IdentityResult.Success));
await _sut.PostPassword(new PasswordRequestModel()); await _sut.PostPassword(new PasswordRequestModel());
await _userService.Received(1).ChangePasswordAsync(user, default, default, default); await _userService.Received(1).ChangePasswordAsync(user, default, default, default, default);
} }
[Fact] [Fact]
@ -302,7 +302,7 @@ namespace Bit.Api.Test.Controllers
{ {
var user = GenerateExampleUser(); var user = GenerateExampleUser();
ConfigureUserServiceToReturnValidPrincipalFor(user); ConfigureUserServiceToReturnValidPrincipalFor(user);
_userService.ChangePasswordAsync(user, default, default, default) _userService.ChangePasswordAsync(user, default, default, default, default)
.Returns(Task.FromResult(IdentityResult.Failed())); .Returns(Task.FromResult(IdentityResult.Failed()));
await Assert.ThrowsAsync<BadRequestException>( await Assert.ThrowsAsync<BadRequestException>(