From a3644cdf24cfa8fe7ed6809f3fd04c65f4c27d6a Mon Sep 17 00:00:00 2001 From: Lennart Dohmann Date: Tue, 12 Mar 2024 11:22:44 +0100 Subject: [PATCH] Add ForUrl test --- dotnet/Vaas/src/Vaas/Messages/Detection.cs | 2 +- .../Vaas/src/Vaas/Messages/VerdictResponse.cs | 4 ++-- dotnet/Vaas/src/Vaas/VaasVerdict.cs | 4 ++-- dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dotnet/Vaas/src/Vaas/Messages/Detection.cs b/dotnet/Vaas/src/Vaas/Messages/Detection.cs index 09b7bc70..bf3ae184 100644 --- a/dotnet/Vaas/src/Vaas/Messages/Detection.cs +++ b/dotnet/Vaas/src/Vaas/Messages/Detection.cs @@ -5,7 +5,7 @@ namespace Vaas.Messages; public class Detection { [JsonPropertyName("engine")] - public int Engine { get; init; } + public int? Engine { get; init; } [JsonPropertyName("fileName")] public string FileName { get; init; } diff --git a/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs b/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs index 976962f1..6e0cd4d0 100644 --- a/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs +++ b/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs @@ -35,10 +35,10 @@ public VerdictResponse(string sha256, Verdict verdict) public string? UploadToken { get; init; } [JsonPropertyName("detections")] - public List Detections { get; init; } + public List? Detections { get; init; } [JsonPropertyName("libMagic")] - public LibMagic LibMagic { get; init; } + public LibMagic? LibMagic { get; init; } [MemberNotNullWhen(true, nameof(Sha256), nameof(Guid))] public bool IsValid => !string.IsNullOrWhiteSpace(Sha256) diff --git a/dotnet/Vaas/src/Vaas/VaasVerdict.cs b/dotnet/Vaas/src/Vaas/VaasVerdict.cs index 2faa4a4f..d11822a1 100644 --- a/dotnet/Vaas/src/Vaas/VaasVerdict.cs +++ b/dotnet/Vaas/src/Vaas/VaasVerdict.cs @@ -14,6 +14,6 @@ public VaasVerdict(VerdictResponse verdictResponse) public string Sha256 { get; init; } public Verdict Verdict { get; init; } - public List Detections { get; init; } - public LibMagic LibMagic { get; init; } + public List? Detections { get; init; } + public LibMagic? LibMagic { get; init; } } diff --git a/dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs b/dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs index e577f5a7..68598d06 100644 --- a/dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs +++ b/dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs @@ -256,6 +256,7 @@ private async Task AuthenticateWithCredentials() { "VerdictAsAService:Credentials:GrantType", "ClientCredentials" }, { "VerdictAsAService:Credentials:ClientId", AuthenticationEnvironment.ClientId }, { "VerdictAsAService:Credentials:ClientSecret", AuthenticationEnvironment.ClientSecret }, + { "VerdictAsAService:UseCache", "false" } }); ServiceCollectionTools.Output(_output, services); var provider = services.BuildServiceProvider(); @@ -316,6 +317,23 @@ public async Task ForStream_WithEicarUrl_ReturnsMaliciousWithDetectionsAndMimeTy var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None); Assert.Equal(Verdict.Malicious, verdict.Verdict); + Assert.NotNull(verdict.LibMagic); + Assert.NotNull(verdict.Detections); + Assert.Equal("text/plain", verdict.LibMagic.MimeType); + Assert.Contains(verdict.Detections, detection => detection.Virus == "EICAR_TEST_FILE"); + } + + [Fact] + public async Task ForUrl_WithEicarUrl_ReturnsMaliciousWithDetectionAndMimeType() + { + var vaas = await AuthenticateWithCredentials(); + var uri = new Uri("https://secure.eicar.org/eicar.com"); + + var verdict = await vaas.ForUrlAsync(uri, CancellationToken.None); + + Assert.Equal(Verdict.Malicious, verdict.Verdict); + Assert.NotNull(verdict.LibMagic); + Assert.NotNull(verdict.Detections); Assert.Equal("text/plain", verdict.LibMagic.MimeType); Assert.Contains(verdict.Detections, detection => detection.Virus == "EICAR_TEST_FILE"); }