|
21 | 21 | using Microsoft.Extensions.DependencyInjection;
|
22 | 22 | using Microsoft.Extensions.Internal;
|
23 | 23 | using Microsoft.Extensions.Logging;
|
24 |
| - |
| 24 | +using Moq; |
25 | 25 | using NSec.Cryptography;
|
26 | 26 |
|
27 | 27 | using Xunit;
|
@@ -630,6 +630,87 @@ public async Task TestInvalidU2FAttestationASync()
|
630 | 630 | Assert.True(acd.ToByteArray().SequenceEqual(acdBytes));
|
631 | 631 | }
|
632 | 632 |
|
| 633 | + [Fact] |
| 634 | + public async Task TestMdsStatusReportsSuccessAsync() |
| 635 | + { |
| 636 | + var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationNoneOptions.json")); |
| 637 | + var response = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationNoneResponse.json")); |
| 638 | + |
| 639 | + var mockMetadataService = new Mock<IMetadataService>(MockBehavior.Strict); |
| 640 | + mockMetadataService.Setup(m => m.GetEntryAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>())) |
| 641 | + .ReturnsAsync(new MetadataBLOBPayloadEntry() |
| 642 | + { |
| 643 | + StatusReports = new StatusReport[] |
| 644 | + { |
| 645 | + new StatusReport() { Status = AuthenticatorStatus.FIDO_CERTIFIED } |
| 646 | + } |
| 647 | + }); |
| 648 | + mockMetadataService.Setup(m => m.ConformanceTesting()).Returns(false); |
| 649 | + |
| 650 | + var o = AuthenticatorAttestationResponse.Parse(response); |
| 651 | + await o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), mockMetadataService.Object, null, CancellationToken.None); |
| 652 | + } |
| 653 | + |
| 654 | + [Fact] |
| 655 | + public async Task TestMdsStatusReportsUndesiredAsync() |
| 656 | + { |
| 657 | + var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationNoneOptions.json")); |
| 658 | + var response = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationNoneResponse.json")); |
| 659 | + |
| 660 | + var mockMetadataService = new Mock<IMetadataService>(MockBehavior.Strict); |
| 661 | + mockMetadataService.Setup(m => m.GetEntryAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>())) |
| 662 | + .ReturnsAsync(new MetadataBLOBPayloadEntry() |
| 663 | + { |
| 664 | + StatusReports = new StatusReport[] |
| 665 | + { |
| 666 | + new StatusReport() { Status = AuthenticatorStatus.FIDO_CERTIFIED }, |
| 667 | + new StatusReport() { Status = AuthenticatorStatus.REVOKED } |
| 668 | + } |
| 669 | + }); |
| 670 | + mockMetadataService.Setup(m => m.ConformanceTesting()).Returns(false); |
| 671 | + |
| 672 | + var o = AuthenticatorAttestationResponse.Parse(response); |
| 673 | + await Assert.ThrowsAsync<UndesiredMetdatataStatusFido2VerificationException>(() => |
| 674 | + o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), mockMetadataService.Object, null, CancellationToken.None)); |
| 675 | + } |
| 676 | + |
| 677 | + [Fact] |
| 678 | + public async Task TestMdsStatusReportsUndesiredFixedAsync() |
| 679 | + { |
| 680 | + var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationNoneOptions.json")); |
| 681 | + var response = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationNoneResponse.json")); |
| 682 | + |
| 683 | + var mockMetadataService = new Mock<IMetadataService>(MockBehavior.Strict); |
| 684 | + mockMetadataService.Setup(m => m.GetEntryAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>())) |
| 685 | + .ReturnsAsync(new MetadataBLOBPayloadEntry() |
| 686 | + { |
| 687 | + StatusReports = new StatusReport[] |
| 688 | + { |
| 689 | + new StatusReport() { Status = AuthenticatorStatus.FIDO_CERTIFIED }, |
| 690 | + new StatusReport() { Status = AuthenticatorStatus.REVOKED }, |
| 691 | + new StatusReport() { Status = AuthenticatorStatus.UPDATE_AVAILABLE } |
| 692 | + } |
| 693 | + }); |
| 694 | + mockMetadataService.Setup(m => m.ConformanceTesting()).Returns(false); |
| 695 | + |
| 696 | + var o = AuthenticatorAttestationResponse.Parse(response); |
| 697 | + await o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), mockMetadataService.Object, null, CancellationToken.None); |
| 698 | + } |
| 699 | + |
| 700 | + [Fact] |
| 701 | + public async Task TestMdsStatusReportsNullAsync() |
| 702 | + { |
| 703 | + var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationNoneOptions.json")); |
| 704 | + var response = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationNoneResponse.json")); |
| 705 | + |
| 706 | + var mockMetadataService = new Mock<IMetadataService>(MockBehavior.Strict); |
| 707 | + mockMetadataService.Setup(m => m.GetEntryAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync((MetadataBLOBPayloadEntry)null); |
| 708 | + mockMetadataService.Setup(m => m.ConformanceTesting()).Returns(false); |
| 709 | + |
| 710 | + var o = AuthenticatorAttestationResponse.Parse(response); |
| 711 | + await o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), mockMetadataService.Object, null, CancellationToken.None); |
| 712 | + } |
| 713 | + |
633 | 714 | //public void TestHasCorrentAAguid()
|
634 | 715 | //{
|
635 | 716 | // var expectedAaguid = new Uint8Array([
|
|
0 commit comments