using Bit.Core.Auth.Entities; using Bit.Core.Auth.Repositories; using Bit.Core.Auth.UserFeatures.WebAuthnLogin.Implementations; using Bit.Core.Entities; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using Fido2NetLib; using Fido2NetLib.Objects; using NSubstitute; using Xunit; namespace Bit.Core.Test.Auth.UserFeatures.WebAuthnLogin; [SutProviderCustomize] public class GetWebAuthnLoginCredentialCreateOptionsTests { [Theory, BitAutoData] internal async Task NoExistingCredentials_ReturnsOptionsWithoutExcludedCredentials(SutProvider sutProvider, User user) { // Arrange sutProvider.GetDependency() .GetManyByUserIdAsync(user.Id) .Returns(new List()); // Act var result = await sutProvider.Sut.GetWebAuthnLoginCredentialCreateOptionsAsync(user); // Assert sutProvider.GetDependency() .Received() .RequestNewCredential( Arg.Any(), Arg.Is>(list => list.Count == 0), Arg.Any(), Arg.Any(), Arg.Any()); } [Theory, BitAutoData] internal async Task HasExistingCredential_ReturnsOptionsWithExcludedCredential(SutProvider sutProvider, User user, WebAuthnCredential credential) { // Arrange sutProvider.GetDependency() .GetManyByUserIdAsync(user.Id) .Returns(new List { credential }); // Act var result = await sutProvider.Sut.GetWebAuthnLoginCredentialCreateOptionsAsync(user); // Assert sutProvider.GetDependency() .Received() .RequestNewCredential( Arg.Any(), Arg.Is>(list => list.Count == 1), Arg.Any(), Arg.Any(), Arg.Any()); } }