mirror of
https://github.com/bitwarden/server.git
synced 2025-12-10 17:45:21 -06:00
Enhance TwoFactorIsEnabledQuery to throw NotFoundException for non-existent users
* Updated TwoFactorIsEnabledQuery to throw NotFoundException when a user is not found instead of returning false. * Added a new unit test to verify that the NotFoundException is thrown when a user is not found while premium access query is enabled.
This commit is contained in:
parent
2bd00c2753
commit
dbb8619e21
@ -6,6 +6,7 @@ using Bit.Core.Auth.Models;
|
||||
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
|
||||
using Bit.Core.Billing.Premium.Queries;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
|
||||
@ -101,7 +102,7 @@ public class TwoFactorIsEnabledQuery : ITwoFactorIsEnabledQuery
|
||||
var userEntity = user as User ?? await _userRepository.GetByIdAsync(userId.Value);
|
||||
if (userEntity == null)
|
||||
{
|
||||
return false;
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return await TwoFactorIsEnabledVNextAsync(userEntity);
|
||||
|
||||
@ -3,6 +3,7 @@ using Bit.Core.Auth.Models;
|
||||
using Bit.Core.Auth.UserFeatures.TwoFactorAuth;
|
||||
using Bit.Core.Billing.Premium.Queries;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.Repositories;
|
||||
@ -651,6 +652,32 @@ public class TwoFactorIsEnabledQueryTests
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task TwoFactorIsEnabledAsync_WhenPremiumAccessQueryEnabled_UserNotFound_ThrowsNotFoundException(
|
||||
SutProvider<TwoFactorIsEnabledQuery> sutProvider,
|
||||
Guid userId)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.PremiumAccessQuery)
|
||||
.Returns(true);
|
||||
|
||||
var testUser = new TestTwoFactorProviderUser
|
||||
{
|
||||
Id = userId,
|
||||
TwoFactorProviders = null
|
||||
};
|
||||
|
||||
sutProvider.GetDependency<IUserRepository>()
|
||||
.GetByIdAsync(userId)
|
||||
.Returns((User)null);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<NotFoundException>(
|
||||
async () => await sutProvider.Sut.TwoFactorIsEnabledAsync(testUser));
|
||||
}
|
||||
|
||||
private class TestTwoFactorProviderUser : ITwoFactorProvidersUser
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user