mirror of
https://github.com/bitwarden/server.git
synced 2024-11-23 12:25:16 +01:00
5268f2781e
* Start switch to System.Text.Json * Work on switching to System.Text.Json * Main work on STJ refactor * Fix build errors * Run formatting * Delete unused file * Use legacy for two factor providers * Run formatter * Add TokenProviderTests * Run formatting * Fix merge issues * Switch to use JsonSerializer * Address PR feedback * Fix formatting * Ran formatter * Switch to async * Ensure Enums are serialized as strings * Fix formatting * Enqueue single items as arrays * Remove CreateAsync method on AzureQueueService
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Identity;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Identity
|
|
{
|
|
public class U2fTokenProviderTests : BaseTokenProviderTests<U2fTokenProvider>
|
|
{
|
|
public override TwoFactorProviderType TwoFactorProviderType => TwoFactorProviderType.U2f;
|
|
|
|
public static IEnumerable<object[]> CanGenerateTwoFactorTokenAsyncData()
|
|
{
|
|
return new[]
|
|
{
|
|
new object[]
|
|
{
|
|
new Dictionary<string, object>
|
|
{
|
|
["Something"] = "Hello"
|
|
},
|
|
true, // canAccessPremium
|
|
true, // expectedResponse
|
|
},
|
|
new object[]
|
|
{
|
|
new Dictionary<string, object>(),
|
|
true, // canAccessPremium
|
|
false, // expectedResponse
|
|
},
|
|
new object[]
|
|
{
|
|
new Dictionary<string, object>
|
|
{
|
|
["Key"] = "Value"
|
|
},
|
|
false, // canAccessPremium
|
|
false, // expectedResponse
|
|
},
|
|
};
|
|
}
|
|
|
|
[Theory, BitMemberAutoData(nameof(CanGenerateTwoFactorTokenAsyncData))]
|
|
public async Task CanGenerateTwoFactorTokenAsync_Success(Dictionary<string, object> metaData, bool canAccessPremium,
|
|
bool expectedResponse, User user, SutProvider<U2fTokenProvider> sutProvider)
|
|
{
|
|
var userManager = SubstituteUserManager();
|
|
MockDatabase(user, metaData);
|
|
AdditionalSetup(sutProvider, user)
|
|
.CanAccessPremium(user)
|
|
.Returns(canAccessPremium);
|
|
|
|
var response = await sutProvider.Sut.CanGenerateTwoFactorTokenAsync(userManager, user);
|
|
Assert.Equal(expectedResponse, response);
|
|
}
|
|
}
|
|
}
|