mirror of
https://github.com/bitwarden/server
synced 2026-01-14 14:33:51 +00:00
test(webauthn) [PM-20109]: Update command tests to use global configs.
This commit is contained in:
@@ -3,6 +3,7 @@ using Bit.Core.Auth.Entities;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Auth.UserFeatures.WebAuthnLogin.Implementations;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Fido2NetLib;
|
||||
@@ -10,6 +11,7 @@ using Fido2NetLib.Objects;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
using static Fido2NetLib.Fido2;
|
||||
using GlobalSettings = Bit.Core.Settings.GlobalSettings;
|
||||
|
||||
namespace Bit.Core.Test.Auth.UserFeatures.WebAuthnLogin;
|
||||
|
||||
@@ -17,10 +19,16 @@ namespace Bit.Core.Test.Auth.UserFeatures.WebAuthnLogin;
|
||||
public class CreateWebAuthnLoginCredentialCommandTests
|
||||
{
|
||||
[Theory, BitAutoData]
|
||||
internal async Task ExceedsExistingCredentialsLimit_ReturnsFalse(SutProvider<CreateWebAuthnLoginCredentialCommand> sutProvider, User user, CredentialCreateOptions options, AuthenticatorAttestationRawResponse response, Generator<WebAuthnCredential> credentialGenerator)
|
||||
internal async Task ExceedsExistingCredentialsLimit_ReturnsFalse(SutProvider<CreateWebAuthnLoginCredentialCommand> sutProvider, User user, CredentialCreateOptions options, AuthenticatorAttestationRawResponse response, Generator<WebAuthnCredential> credentialGenerator, bool userCanAccessPremium)
|
||||
{
|
||||
// Arrange
|
||||
var existingCredentials = credentialGenerator.Take(CreateWebAuthnLoginCredentialCommand.MaxCredentialsPerUser).ToList();
|
||||
var webAuthNGlobalSettings = sutProvider.GetDependency<GlobalSettings>().WebAuthN = new GlobalSettings.WebAuthNSettings()
|
||||
{
|
||||
NonPremiumMaximumAllowedCredentials = 5,
|
||||
PremiumMaximumAllowedCredentials = 10,
|
||||
};
|
||||
sutProvider.GetDependency<IUserService>().CanAccessPremium(user).Returns(userCanAccessPremium);
|
||||
var maximumAllowedCredentialCount = userCanAccessPremium ? webAuthNGlobalSettings.PremiumMaximumAllowedCredentials : webAuthNGlobalSettings.NonPremiumMaximumAllowedCredentials;
|
||||
var existingCredentials = credentialGenerator.Take(maximumAllowedCredentialCount).ToList();
|
||||
sutProvider.GetDependency<IWebAuthnCredentialRepository>().GetManyByUserIdAsync(user.Id).Returns(existingCredentials);
|
||||
|
||||
// Act
|
||||
@@ -32,10 +40,17 @@ public class CreateWebAuthnLoginCredentialCommandTests
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
internal async Task DoesNotExceedExistingCredentialsLimit_CreatesCredential(SutProvider<CreateWebAuthnLoginCredentialCommand> sutProvider, User user, CredentialCreateOptions options, AuthenticatorAttestationRawResponse response, Generator<WebAuthnCredential> credentialGenerator)
|
||||
internal async Task DoesNotExceedExistingCredentialsLimit_CreatesCredential(SutProvider<CreateWebAuthnLoginCredentialCommand> sutProvider, User user, CredentialCreateOptions options, AuthenticatorAttestationRawResponse response, Generator<WebAuthnCredential> credentialGenerator, bool userCanAccessPremium)
|
||||
{
|
||||
// Arrange
|
||||
var existingCredentials = credentialGenerator.Take(CreateWebAuthnLoginCredentialCommand.MaxCredentialsPerUser - 1).ToList();
|
||||
var webAuthNGlobalSettings = sutProvider.GetDependency<GlobalSettings>().WebAuthN = new GlobalSettings.WebAuthNSettings()
|
||||
{
|
||||
NonPremiumMaximumAllowedCredentials = 5,
|
||||
PremiumMaximumAllowedCredentials = 10,
|
||||
};
|
||||
sutProvider.GetDependency<IUserService>().CanAccessPremium(user).Returns(userCanAccessPremium);
|
||||
var maximumAllowedCredentialCount = userCanAccessPremium ? webAuthNGlobalSettings.PremiumMaximumAllowedCredentials : webAuthNGlobalSettings.NonPremiumMaximumAllowedCredentials;
|
||||
var existingCredentials = credentialGenerator.Take(maximumAllowedCredentialCount - 1).ToList();
|
||||
sutProvider.GetDependency<IWebAuthnCredentialRepository>().GetManyByUserIdAsync(user.Id).Returns(existingCredentials);
|
||||
sutProvider.GetDependency<IFido2>().MakeNewCredentialAsync(
|
||||
response, options, Arg.Any<IsCredentialIdUniqueToUserAsyncDelegate>(), Arg.Any<byte[]>(), Arg.Any<CancellationToken>()
|
||||
|
||||
Reference in New Issue
Block a user