mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
Auth/PM-3833 - Remove Deprecated Register and Prelogin endpoints from API (#4206)
* PM-3833 - API - AccountsController.cs && AccountsController.cs - remove prelogin and register endpoints. * PM-3833 - Move Request and Response models that were used for Prelogin and PostRegister from API to Identity. * PM-3833 - FIX LINT * PM-3833 - Fix issues after merge conflict fixes. * PM-3833 - Another test fix
This commit is contained in:
parent
b2b1e3de87
commit
29b47f72ca
@ -16,12 +16,9 @@ using Bit.Core.AdminConsole.Repositories;
|
|||||||
using Bit.Core.AdminConsole.Services;
|
using Bit.Core.AdminConsole.Services;
|
||||||
using Bit.Core.Auth.Entities;
|
using Bit.Core.Auth.Entities;
|
||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||||
using Bit.Core.Auth.Models.Api.Response.Accounts;
|
|
||||||
using Bit.Core.Auth.Models.Data;
|
using Bit.Core.Auth.Models.Data;
|
||||||
using Bit.Core.Auth.Services;
|
|
||||||
using Bit.Core.Auth.UserFeatures.UserKey;
|
using Bit.Core.Auth.UserFeatures.UserKey;
|
||||||
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
||||||
using Bit.Core.Auth.Utilities;
|
|
||||||
using Bit.Core.Billing.Models;
|
using Bit.Core.Billing.Models;
|
||||||
using Bit.Core.Billing.Services;
|
using Bit.Core.Billing.Services;
|
||||||
using Bit.Core.Context;
|
using Bit.Core.Context;
|
||||||
@ -30,18 +27,15 @@ using Bit.Core.Enums;
|
|||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.Api.Response;
|
using Bit.Core.Models.Api.Response;
|
||||||
using Bit.Core.Models.Business;
|
using Bit.Core.Models.Business;
|
||||||
using Bit.Core.Models.Data;
|
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Settings;
|
using Bit.Core.Settings;
|
||||||
using Bit.Core.Tools.Entities;
|
using Bit.Core.Tools.Entities;
|
||||||
using Bit.Core.Tools.Enums;
|
using Bit.Core.Tools.Enums;
|
||||||
using Bit.Core.Tools.Models.Business;
|
using Bit.Core.Tools.Models.Business;
|
||||||
using Bit.Core.Tools.Repositories;
|
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Bit.Core.Vault.Entities;
|
using Bit.Core.Vault.Entities;
|
||||||
using Bit.Core.Vault.Repositories;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -52,17 +46,11 @@ namespace Bit.Api.Auth.Controllers;
|
|||||||
public class AccountsController : Controller
|
public class AccountsController : Controller
|
||||||
{
|
{
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly ICipherRepository _cipherRepository;
|
|
||||||
private readonly IFolderRepository _folderRepository;
|
|
||||||
private readonly IOrganizationService _organizationService;
|
private readonly IOrganizationService _organizationService;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly IProviderUserRepository _providerUserRepository;
|
private readonly IProviderUserRepository _providerUserRepository;
|
||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly ISendRepository _sendRepository;
|
|
||||||
private readonly ISendService _sendService;
|
|
||||||
private readonly ICaptchaValidationService _captchaValidationService;
|
|
||||||
private readonly IPolicyService _policyService;
|
private readonly IPolicyService _policyService;
|
||||||
private readonly ISetInitialMasterPasswordCommand _setInitialMasterPasswordCommand;
|
private readonly ISetInitialMasterPasswordCommand _setInitialMasterPasswordCommand;
|
||||||
private readonly IRotateUserKeyCommand _rotateUserKeyCommand;
|
private readonly IRotateUserKeyCommand _rotateUserKeyCommand;
|
||||||
@ -88,17 +76,11 @@ public class AccountsController : Controller
|
|||||||
|
|
||||||
public AccountsController(
|
public AccountsController(
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
ICipherRepository cipherRepository,
|
|
||||||
IFolderRepository folderRepository,
|
|
||||||
IOrganizationService organizationService,
|
IOrganizationService organizationService,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
IProviderUserRepository providerUserRepository,
|
IProviderUserRepository providerUserRepository,
|
||||||
IPaymentService paymentService,
|
IPaymentService paymentService,
|
||||||
IUserRepository userRepository,
|
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
ISendRepository sendRepository,
|
|
||||||
ISendService sendService,
|
|
||||||
ICaptchaValidationService captchaValidationService,
|
|
||||||
IPolicyService policyService,
|
IPolicyService policyService,
|
||||||
ISetInitialMasterPasswordCommand setInitialMasterPasswordCommand,
|
ISetInitialMasterPasswordCommand setInitialMasterPasswordCommand,
|
||||||
IRotateUserKeyCommand rotateUserKeyCommand,
|
IRotateUserKeyCommand rotateUserKeyCommand,
|
||||||
@ -116,18 +98,12 @@ public class AccountsController : Controller
|
|||||||
IRotationValidator<IEnumerable<WebAuthnLoginRotateKeyRequestModel>, IEnumerable<WebAuthnLoginRotateKeyData>> webAuthnKeyValidator
|
IRotationValidator<IEnumerable<WebAuthnLoginRotateKeyRequestModel>, IEnumerable<WebAuthnLoginRotateKeyData>> webAuthnKeyValidator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
|
||||||
_folderRepository = folderRepository;
|
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_providerUserRepository = providerUserRepository;
|
_providerUserRepository = providerUserRepository;
|
||||||
_paymentService = paymentService;
|
_paymentService = paymentService;
|
||||||
_userRepository = userRepository;
|
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_sendRepository = sendRepository;
|
|
||||||
_sendService = sendService;
|
|
||||||
_captchaValidationService = captchaValidationService;
|
|
||||||
_policyService = policyService;
|
_policyService = policyService;
|
||||||
_setInitialMasterPasswordCommand = setInitialMasterPasswordCommand;
|
_setInitialMasterPasswordCommand = setInitialMasterPasswordCommand;
|
||||||
_rotateUserKeyCommand = rotateUserKeyCommand;
|
_rotateUserKeyCommand = rotateUserKeyCommand;
|
||||||
@ -143,50 +119,6 @@ public class AccountsController : Controller
|
|||||||
_webauthnKeyValidator = webAuthnKeyValidator;
|
_webauthnKeyValidator = webAuthnKeyValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region DEPRECATED (Moved to Identity Service)
|
|
||||||
|
|
||||||
[Obsolete("TDL-136 Moved to Identity (2022-01-12 cloud, 2022-09-19 self-hosted), left for backwards compatability with older clients.")]
|
|
||||||
[HttpPost("prelogin")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
|
|
||||||
{
|
|
||||||
var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email);
|
|
||||||
if (kdfInformation == null)
|
|
||||||
{
|
|
||||||
kdfInformation = new UserKdfInformation
|
|
||||||
{
|
|
||||||
Kdf = KdfType.PBKDF2_SHA256,
|
|
||||||
KdfIterations = AuthConstants.PBKDF2_ITERATIONS.Default,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return new PreloginResponseModel(kdfInformation);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("TDL-136 Moved to Identity (2022-01-12 cloud, 2022-09-19 self-hosted), left for backwards compatability with older clients.")]
|
|
||||||
[HttpPost("register")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
[CaptchaProtected]
|
|
||||||
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
|
||||||
{
|
|
||||||
var user = model.ToUser();
|
|
||||||
var result = await _userService.RegisterUserAsync(user, model.MasterPasswordHash,
|
|
||||||
model.Token, model.OrganizationUserId);
|
|
||||||
if (result.Succeeded)
|
|
||||||
{
|
|
||||||
var captchaBypassToken = _captchaValidationService.GenerateCaptchaBypassToken(user);
|
|
||||||
return new RegisterResponseModel(captchaBypassToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var error in result.Errors.Where(e => e.Code != "DuplicateUserName"))
|
|
||||||
{
|
|
||||||
ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(2000);
|
|
||||||
throw new BadRequestException(ModelState);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[HttpPost("password-hint")]
|
[HttpPost("password-hint")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
@ -18,6 +18,8 @@ using Bit.Core.Tools.Enums;
|
|||||||
using Bit.Core.Tools.Models.Business;
|
using Bit.Core.Tools.Models.Business;
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
|
using Bit.Identity.Models.Response.Accounts;
|
||||||
using Bit.SharedWeb.Utilities;
|
using Bit.SharedWeb.Utilities;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -61,7 +63,6 @@ public class AccountsController : Controller
|
|||||||
_referenceEventService = referenceEventService;
|
_referenceEventService = referenceEventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moved from API, If you modify this endpoint, please update API as well. Self hosted installs still use the API endpoints.
|
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
[CaptchaProtected]
|
[CaptchaProtected]
|
||||||
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
||||||
@ -138,5 +139,4 @@ public class AccountsController : Controller
|
|||||||
Token = token
|
Token = token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Request.Accounts;
|
namespace Bit.Identity.Models.Request.Accounts;
|
||||||
|
|
||||||
public class PreloginRequestModel
|
public class PreloginRequestModel
|
||||||
{
|
{
|
@ -1,10 +1,13 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Bit.Core;
|
||||||
|
using Bit.Core.Auth.Models.Api;
|
||||||
|
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Request.Accounts;
|
namespace Bit.Identity.Models.Request.Accounts;
|
||||||
|
|
||||||
public class RegisterRequestModel : IValidatableObject, ICaptchaProtectedModel
|
public class RegisterRequestModel : IValidatableObject, ICaptchaProtectedModel
|
||||||
{
|
{
|
@ -1,5 +1,4 @@
|
|||||||
namespace Bit.Core.Auth.Models.Api.Response.Accounts;
|
namespace Bit.Identity.Models.Response.Accounts;
|
||||||
|
|
||||||
public interface ICaptchaProtectedResponseModel
|
public interface ICaptchaProtectedResponseModel
|
||||||
{
|
{
|
||||||
public string CaptchaBypassToken { get; set; }
|
public string CaptchaBypassToken { get; set; }
|
@ -1,7 +1,7 @@
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Response.Accounts;
|
namespace Bit.Identity.Models.Response.Accounts;
|
||||||
|
|
||||||
public class PreloginResponseModel
|
public class PreloginResponseModel
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
using Bit.Core.Models.Api;
|
using Bit.Core.Models.Api;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Response.Accounts;
|
namespace Bit.Identity.Models.Response.Accounts;
|
||||||
|
|
||||||
public class RegisterResponseModel : ResponseModel, ICaptchaProtectedResponseModel
|
public class RegisterResponseModel : ResponseModel, ICaptchaProtectedResponseModel
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.IntegrationTestCommon.Factories;
|
using Bit.IntegrationTestCommon.Factories;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
|
@ -7,29 +7,23 @@ using Bit.Api.Auth.Models.Request.WebAuthn;
|
|||||||
using Bit.Api.Auth.Validators;
|
using Bit.Api.Auth.Validators;
|
||||||
using Bit.Api.Tools.Models.Request;
|
using Bit.Api.Tools.Models.Request;
|
||||||
using Bit.Api.Vault.Models.Request;
|
using Bit.Api.Vault.Models.Request;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
using Bit.Core.AdminConsole.Services;
|
using Bit.Core.AdminConsole.Services;
|
||||||
using Bit.Core.Auth.Entities;
|
using Bit.Core.Auth.Entities;
|
||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||||
using Bit.Core.Auth.Models.Data;
|
using Bit.Core.Auth.Models.Data;
|
||||||
using Bit.Core.Auth.Services;
|
|
||||||
using Bit.Core.Auth.UserFeatures.UserKey;
|
using Bit.Core.Auth.UserFeatures.UserKey;
|
||||||
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
||||||
using Bit.Core.Billing.Services;
|
using Bit.Core.Billing.Services;
|
||||||
using Bit.Core.Context;
|
using Bit.Core.Context;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Enums;
|
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.Data;
|
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Settings;
|
using Bit.Core.Settings;
|
||||||
using Bit.Core.Tools.Entities;
|
using Bit.Core.Tools.Entities;
|
||||||
using Bit.Core.Tools.Repositories;
|
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
using Bit.Core.Vault.Entities;
|
using Bit.Core.Vault.Entities;
|
||||||
using Bit.Core.Vault.Repositories;
|
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
@ -42,17 +36,11 @@ public class AccountsControllerTests : IDisposable
|
|||||||
|
|
||||||
private readonly AccountsController _sut;
|
private readonly AccountsController _sut;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly ICipherRepository _cipherRepository;
|
|
||||||
private readonly IFolderRepository _folderRepository;
|
|
||||||
private readonly IOrganizationService _organizationService;
|
private readonly IOrganizationService _organizationService;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly ISendRepository _sendRepository;
|
|
||||||
private readonly ISendService _sendService;
|
|
||||||
private readonly IProviderUserRepository _providerUserRepository;
|
private readonly IProviderUserRepository _providerUserRepository;
|
||||||
private readonly ICaptchaValidationService _captchaValidationService;
|
|
||||||
private readonly IPolicyService _policyService;
|
private readonly IPolicyService _policyService;
|
||||||
private readonly ISetInitialMasterPasswordCommand _setInitialMasterPasswordCommand;
|
private readonly ISetInitialMasterPasswordCommand _setInitialMasterPasswordCommand;
|
||||||
private readonly IRotateUserKeyCommand _rotateUserKeyCommand;
|
private readonly IRotateUserKeyCommand _rotateUserKeyCommand;
|
||||||
@ -76,17 +64,11 @@ public class AccountsControllerTests : IDisposable
|
|||||||
public AccountsControllerTests()
|
public AccountsControllerTests()
|
||||||
{
|
{
|
||||||
_userService = Substitute.For<IUserService>();
|
_userService = Substitute.For<IUserService>();
|
||||||
_userRepository = Substitute.For<IUserRepository>();
|
|
||||||
_cipherRepository = Substitute.For<ICipherRepository>();
|
|
||||||
_folderRepository = Substitute.For<IFolderRepository>();
|
|
||||||
_organizationService = Substitute.For<IOrganizationService>();
|
_organizationService = Substitute.For<IOrganizationService>();
|
||||||
_organizationUserRepository = Substitute.For<IOrganizationUserRepository>();
|
_organizationUserRepository = Substitute.For<IOrganizationUserRepository>();
|
||||||
_providerUserRepository = Substitute.For<IProviderUserRepository>();
|
_providerUserRepository = Substitute.For<IProviderUserRepository>();
|
||||||
_paymentService = Substitute.For<IPaymentService>();
|
_paymentService = Substitute.For<IPaymentService>();
|
||||||
_globalSettings = new GlobalSettings();
|
_globalSettings = new GlobalSettings();
|
||||||
_sendRepository = Substitute.For<ISendRepository>();
|
|
||||||
_sendService = Substitute.For<ISendService>();
|
|
||||||
_captchaValidationService = Substitute.For<ICaptchaValidationService>();
|
|
||||||
_policyService = Substitute.For<IPolicyService>();
|
_policyService = Substitute.For<IPolicyService>();
|
||||||
_setInitialMasterPasswordCommand = Substitute.For<ISetInitialMasterPasswordCommand>();
|
_setInitialMasterPasswordCommand = Substitute.For<ISetInitialMasterPasswordCommand>();
|
||||||
_rotateUserKeyCommand = Substitute.For<IRotateUserKeyCommand>();
|
_rotateUserKeyCommand = Substitute.For<IRotateUserKeyCommand>();
|
||||||
@ -108,17 +90,11 @@ public class AccountsControllerTests : IDisposable
|
|||||||
|
|
||||||
_sut = new AccountsController(
|
_sut = new AccountsController(
|
||||||
_globalSettings,
|
_globalSettings,
|
||||||
_cipherRepository,
|
|
||||||
_folderRepository,
|
|
||||||
_organizationService,
|
_organizationService,
|
||||||
_organizationUserRepository,
|
_organizationUserRepository,
|
||||||
_providerUserRepository,
|
_providerUserRepository,
|
||||||
_paymentService,
|
_paymentService,
|
||||||
_userRepository,
|
|
||||||
_userService,
|
_userService,
|
||||||
_sendRepository,
|
|
||||||
_sendService,
|
|
||||||
_captchaValidationService,
|
|
||||||
_policyService,
|
_policyService,
|
||||||
_setInitialMasterPasswordCommand,
|
_setInitialMasterPasswordCommand,
|
||||||
_rotateUserKeyCommand,
|
_rotateUserKeyCommand,
|
||||||
@ -140,77 +116,6 @@ public class AccountsControllerTests : IDisposable
|
|||||||
_sut?.Dispose();
|
_sut?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task PostPrelogin_WhenUserExists_ShouldReturnUserKdfInfo()
|
|
||||||
{
|
|
||||||
var userKdfInfo = new UserKdfInformation
|
|
||||||
{
|
|
||||||
Kdf = KdfType.PBKDF2_SHA256,
|
|
||||||
KdfIterations = AuthConstants.PBKDF2_ITERATIONS.Default
|
|
||||||
};
|
|
||||||
_userRepository.GetKdfInformationByEmailAsync(Arg.Any<string>()).Returns(Task.FromResult(userKdfInfo));
|
|
||||||
|
|
||||||
var response = await _sut.PostPrelogin(new PreloginRequestModel { Email = "user@example.com" });
|
|
||||||
|
|
||||||
Assert.Equal(userKdfInfo.Kdf, response.Kdf);
|
|
||||||
Assert.Equal(userKdfInfo.KdfIterations, response.KdfIterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task PostPrelogin_WhenUserDoesNotExist_ShouldDefaultToPBKDF()
|
|
||||||
{
|
|
||||||
_userRepository.GetKdfInformationByEmailAsync(Arg.Any<string>()).Returns(Task.FromResult((UserKdfInformation)null));
|
|
||||||
|
|
||||||
var response = await _sut.PostPrelogin(new PreloginRequestModel { Email = "user@example.com" });
|
|
||||||
|
|
||||||
Assert.Equal(KdfType.PBKDF2_SHA256, response.Kdf);
|
|
||||||
Assert.Equal(AuthConstants.PBKDF2_ITERATIONS.Default, response.KdfIterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task PostRegister_ShouldRegisterUser()
|
|
||||||
{
|
|
||||||
var passwordHash = "abcdef";
|
|
||||||
var token = "123456";
|
|
||||||
var userGuid = new Guid();
|
|
||||||
_userService.RegisterUserAsync(Arg.Any<User>(), passwordHash, token, userGuid)
|
|
||||||
.Returns(Task.FromResult(IdentityResult.Success));
|
|
||||||
var request = new RegisterRequestModel
|
|
||||||
{
|
|
||||||
Name = "Example User",
|
|
||||||
Email = "user@example.com",
|
|
||||||
MasterPasswordHash = passwordHash,
|
|
||||||
MasterPasswordHint = "example",
|
|
||||||
Token = token,
|
|
||||||
OrganizationUserId = userGuid
|
|
||||||
};
|
|
||||||
|
|
||||||
await _sut.PostRegister(request);
|
|
||||||
|
|
||||||
await _userService.Received(1).RegisterUserAsync(Arg.Any<User>(), passwordHash, token, userGuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task PostRegister_WhenUserServiceFails_ShouldThrowBadRequestException()
|
|
||||||
{
|
|
||||||
var passwordHash = "abcdef";
|
|
||||||
var token = "123456";
|
|
||||||
var userGuid = new Guid();
|
|
||||||
_userService.RegisterUserAsync(Arg.Any<User>(), passwordHash, token, userGuid)
|
|
||||||
.Returns(Task.FromResult(IdentityResult.Failed()));
|
|
||||||
var request = new RegisterRequestModel
|
|
||||||
{
|
|
||||||
Name = "Example User",
|
|
||||||
Email = "user@example.com",
|
|
||||||
MasterPasswordHash = passwordHash,
|
|
||||||
MasterPasswordHint = "example",
|
|
||||||
Token = token,
|
|
||||||
OrganizationUserId = userGuid
|
|
||||||
};
|
|
||||||
|
|
||||||
await Assert.ThrowsAsync<BadRequestException>(() => _sut.PostRegister(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostPasswordHint_ShouldNotifyUserService()
|
public async Task PostPasswordHint_ShouldNotifyUserService()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.IntegrationTestCommon.Factories;
|
using Bit.IntegrationTestCommon.Factories;
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -6,7 +6,6 @@ using Bit.Core.AdminConsole.Enums.Provider;
|
|||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
using Bit.Core.Auth.Entities;
|
using Bit.Core.Auth.Entities;
|
||||||
using Bit.Core.Auth.Enums;
|
using Bit.Core.Auth.Enums;
|
||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
|
||||||
using Bit.Core.Auth.Models.Data;
|
using Bit.Core.Auth.Models.Data;
|
||||||
using Bit.Core.Auth.Repositories;
|
using Bit.Core.Auth.Repositories;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
@ -14,6 +13,7 @@ using Bit.Core.Enums;
|
|||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.IntegrationTestCommon.Factories;
|
using Bit.IntegrationTestCommon.Factories;
|
||||||
using Bit.Test.Common.Helpers;
|
using Bit.Test.Common.Helpers;
|
||||||
using Duende.IdentityServer.Models;
|
using Duende.IdentityServer.Models;
|
||||||
|
@ -3,10 +3,10 @@ using Bit.Core;
|
|||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Enums;
|
using Bit.Core.AdminConsole.Enums;
|
||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Identity.IdentityServer;
|
using Bit.Identity.IdentityServer;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.IntegrationTestCommon.Factories;
|
using Bit.IntegrationTestCommon.Factories;
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
using Bit.Test.Common.Helpers;
|
using Bit.Test.Common.Helpers;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.Auth.Enums;
|
using Bit.Core.Auth.Enums;
|
||||||
using Bit.Core.Auth.Models.Api.Request.Accounts;
|
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.IntegrationTestCommon.Factories;
|
using Bit.IntegrationTestCommon.Factories;
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
using Bit.Test.Common.Helpers;
|
using Bit.Test.Common.Helpers;
|
||||||
|
@ -16,6 +16,7 @@ using Bit.Core.Tools.Enums;
|
|||||||
using Bit.Core.Tools.Models.Business;
|
using Bit.Core.Tools.Models.Business;
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
using Bit.Identity.Controllers;
|
using Bit.Identity.Controllers;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -4,6 +4,7 @@ using Bit.Core.Auth.Models.Api.Request.Accounts;
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Bit.Identity;
|
using Bit.Identity;
|
||||||
|
using Bit.Identity.Models.Request.Accounts;
|
||||||
using Bit.Test.Common.Helpers;
|
using Bit.Test.Common.Helpers;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user