mirror of
https://github.com/bitwarden/server
synced 2025-12-24 04:03:25 +00:00
fix(2fa): [PM-22323] Do not show 2FA warning for 2FA setup and login emails
* Added configuration to not display 2FA setup instruction * Refactored to new service. * Linting. * Dependency injection * Changed to scoped to have access to ICurrentContext. * Inverted logic for EmailTotpAction * Fixed tests. * Fixed tests. * More tests. * Fixed tests. * Linting. * Added tests at controller level. * Linting * Fixed error in test. * Review updates. * Accidentally deleted imports.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Auth.Services;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Api;
|
||||
@@ -26,6 +27,7 @@ public class DeviceValidatorTests
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IDistributedCache _distributedCache;
|
||||
private readonly ITwoFactorEmailService _twoFactorEmailService;
|
||||
private readonly Logger<DeviceValidator> _logger;
|
||||
|
||||
private readonly DeviceValidator _sut;
|
||||
@@ -39,6 +41,7 @@ public class DeviceValidatorTests
|
||||
_currentContext = Substitute.For<ICurrentContext>();
|
||||
_userService = Substitute.For<IUserService>();
|
||||
_distributedCache = Substitute.For<IDistributedCache>();
|
||||
_twoFactorEmailService = Substitute.For<ITwoFactorEmailService>();
|
||||
_logger = new Logger<DeviceValidator>(Substitute.For<ILoggerFactory>());
|
||||
_sut = new DeviceValidator(
|
||||
_deviceService,
|
||||
@@ -48,6 +51,7 @@ public class DeviceValidatorTests
|
||||
_currentContext,
|
||||
_userService,
|
||||
_distributedCache,
|
||||
_twoFactorEmailService,
|
||||
_logger);
|
||||
}
|
||||
|
||||
@@ -580,7 +584,7 @@ public class DeviceValidatorTests
|
||||
var result = await _sut.ValidateRequestDeviceAsync(request, context);
|
||||
|
||||
// Assert
|
||||
await _userService.Received(1).SendNewDeviceVerificationEmailAsync(context.User);
|
||||
await _twoFactorEmailService.Received(1).SendNewDeviceVerificationEmailAsync(context.User);
|
||||
await _deviceService.Received(0).SaveAsync(Arg.Any<Device>());
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
Reference in New Issue
Block a user