1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-17 00:33:20 +00:00

[PM-5731] feat: add first test

This commit is contained in:
Andreas Coroiu
2024-01-17 14:01:45 +01:00
parent f9b4e30b0b
commit 32c2f2aac4
4 changed files with 51 additions and 34 deletions

View File

@@ -7,12 +7,14 @@ namespace Bit.Core.Services
{ {
public Task<Fido2AuthenticatorGetAssertionResult> GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams) public Task<Fido2AuthenticatorGetAssertionResult> GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams)
{ {
throw new NotAllowedError();
// TODO: IMPLEMENT this // TODO: IMPLEMENT this
return Task.FromResult(new Fido2AuthenticatorGetAssertionResult // return Task.FromResult(new Fido2AuthenticatorGetAssertionResult
{ // {
AuthenticatorData = new byte[32], // AuthenticatorData = new byte[32],
Signature = new byte[8] // Signature = new byte[8]
}); // });
} }
} }
} }

View File

@@ -0,0 +1,16 @@
namespace Bit.Core.Utilities.Fido2
{
public class Fido2AuthenticatorException : Exception
{
public Fido2AuthenticatorException(string message) : base(message)
{
}
}
public class NotAllowedError : Fido2AuthenticatorException
{
public NotAllowedError() : base("NotAllowedError")
{
}
}
}

View File

@@ -33,22 +33,22 @@ namespace Bit.iOS.Autofill
return; return;
} }
// TODO: Generate the credential Signature and Auth data accordingly // // TODO: Generate the credential Signature and Auth data accordingly
var fido2AssertionResult = await _fido2AuthService.Value.GetAssertionAsync(new Bit.Core.Utilities.Fido2.Fido2AuthenticatorGetAssertionParams // var fido2AssertionResult = await _fido2AuthService.Value.GetAssertionAsync(new Bit.Core.Utilities.Fido2.Fido2AuthenticatorGetAssertionParams
{ // {
RpId = cipherView.Login.MainFido2Credential.RpId, // RpId = cipherView.Login.MainFido2Credential.RpId,
Counter = cipherView.Login.MainFido2Credential.Counter, // Counter = cipherView.Login.MainFido2Credential.Counter,
CredentialId = cipherView.Login.MainFido2Credential.CredentialId // CredentialId = cipherView.Login.MainFido2Credential.CredentialId
}); // });
CompleteAssertionRequest(new ASPasskeyAssertionCredential( // CompleteAssertionRequest(new ASPasskeyAssertionCredential(
cipherView.Login.MainFido2Credential.UserHandle, // cipherView.Login.MainFido2Credential.UserHandle,
cipherView.Login.MainFido2Credential.RpId, // cipherView.Login.MainFido2Credential.RpId,
NSData.FromArray(fido2AssertionResult.Signature), // NSData.FromArray(fido2AssertionResult.Signature),
_context.PasskeyCredentialRequest?.ClientDataHash, // _context.PasskeyCredentialRequest?.ClientDataHash,
NSData.FromArray(fido2AssertionResult.AuthenticatorData), // NSData.FromArray(fido2AssertionResult.AuthenticatorData),
cipherView.Login.MainFido2Credential.CredentialId // cipherView.Login.MainFido2Credential.CredentialId
)); // ));
} }
public void CompleteAssertionRequest(ASPasskeyAssertionCredential assertionCredential) public void CompleteAssertionRequest(ASPasskeyAssertionCredential assertionCredential)

View File

@@ -1,7 +1,9 @@
using System.Threading.Tasks;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture;
using Bit.Core.Utilities.Fido2;
using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes; using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute; using NSubstitute;
@@ -12,26 +14,23 @@ namespace Bit.Core.Test.Services
{ {
public class Fido2AuthenticatorTests public class Fido2AuthenticatorTests
{ {
[Theory] // Spec: If credentialOptions is now empty, return an error code equivalent to "NotAllowedError" and terminate the operation.
public async Task GetAssertionAsync_Throws_InputIsMissingSupportedAlgorithm(Fido2AuthenticatorService sut) [Theory, SutAutoData]
public async Task GetAssertionAsync_Throws_NoCredentialExists(Fido2AuthenticatorService sut)
{ {
await Assert.ThrowsAsync<NotFoundException>(async () => await sut.GetAssertionAsync(new Fido2AuthenticatorGetAssertionParams())); var assertionParams = CreateAssertionParams();
var exception = await Assert.ThrowsAsync<NotAllowedError>(() => sut.GetAssertionAsync(assertionParams));
} }
// it("should throw error when input does not contain any supported algorithms", async () => { private Fido2AuthenticatorGetAssertionParams CreateAssertionParams()
// const result = async () =>
// await authenticator.makeCredential(invalidParams.unsupportedAlgorithm, tab);
// await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotSupported);
// });
private Fido2AuthenticatorGetAssertionParams GetAssertionParams()
{ {
return new Fido2AuthenticatorGetAssertionParams return new Fido2AuthenticatorGetAssertionParams
{ {
RpId = "test", RpId = "bitwarden.com",
Counter = 0, Hash = new byte[32],
CredentialId = new byte[32] AllowCredentialDescriptorList = new PublicKeyCredentialDescriptor[0],
RequireUserVerification = true,
Extensions = new object()
}; };
} }
} }