Skip to content

Commit

Permalink
Add ForUrl test
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartdohmann committed Mar 12, 2024
1 parent 1f536c6 commit a3644cd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dotnet/Vaas/src/Vaas/Messages/Detection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Check warning on line 11 in dotnet/Vaas/src/Vaas/Messages/Detection.cs

View workflow job for this annotation

GitHub Actions / Build & Test C# SDK (8.0.x)

Non-nullable property 'FileName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 11 in dotnet/Vaas/src/Vaas/Messages/Detection.cs

View workflow job for this annotation

GitHub Actions / Build & Test C# SDK (8.0.x)

Non-nullable property 'FileName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public VerdictResponse(string sha256, Verdict verdict)
public string? UploadToken { get; init; }

[JsonPropertyName("detections")]
public List<Detection> Detections { get; init; }
public List<Detection>? 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)
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Vaas/src/Vaas/VaasVerdict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public VaasVerdict(VerdictResponse verdictResponse)

public string Sha256 { get; init; }
public Verdict Verdict { get; init; }
public List<Detection> Detections { get; init; }
public LibMagic LibMagic { get; init; }
public List<Detection>? Detections { get; init; }
public LibMagic? LibMagic { get; init; }
}
18 changes: 18 additions & 0 deletions dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private async Task<Vaas> 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();
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit a3644cd

Please sign in to comment.