Skip to content

Commit

Permalink
Implement API changes for fields detection, filetype and mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartdohmann committed Apr 26, 2024
1 parent 676da7e commit d048dba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 53 deletions.
15 changes: 0 additions & 15 deletions dotnet/Vaas/src/Vaas/Messages/Detection.cs

This file was deleted.

12 changes: 0 additions & 12 deletions dotnet/Vaas/src/Vaas/Messages/LibMagic.cs

This file was deleted.

13 changes: 8 additions & 5 deletions dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public VerdictResponse(string sha256, Verdict verdict)
[JsonPropertyName("upload_token")]
public string? UploadToken { get; init; }

[JsonPropertyName("detections")]
public List<Detection>? Detections { get; init; }

[JsonPropertyName("lib_magic")]
public LibMagic? LibMagic { get; init; }
[JsonPropertyName("detection")]
public string? Detection { get; init; }

[JsonPropertyName("file_type")]
public string? FileType { get; init; }

[JsonPropertyName("mime_type")]
public string? MimeType { get; init; }

[MemberNotNullWhen(true, nameof(Sha256), nameof(Guid))]
public bool IsValid => !string.IsNullOrWhiteSpace(Sha256)
Expand Down
19 changes: 6 additions & 13 deletions dotnet/Vaas/src/Vaas/VaasVerdict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

namespace Vaas.Messages;

public class VaasVerdict
public class VaasVerdict(VerdictResponse verdictResponse)
{
public VaasVerdict(VerdictResponse verdictResponse)
{
Sha256 = verdictResponse.Sha256 ?? "";
Verdict = verdictResponse.Verdict;
Detections = verdictResponse.Detections;
LibMagic = verdictResponse.LibMagic;
}

public string Sha256 { get; init; }
public Verdict Verdict { get; init; }
public List<Detection>? Detections { get; init; }
public LibMagic? LibMagic { get; init; }
public string Sha256 { get; init; } = verdictResponse.Sha256 ?? "";
public Verdict Verdict { get; init; } = verdictResponse.Verdict;
public string? Detection { get; init; } = verdictResponse.Detection;
public string? MimeType { get; init; } = verdictResponse.FileType;
public string? FileType { get; init; } = verdictResponse.MimeType;
}
14 changes: 6 additions & 8 deletions dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,9 @@ 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");
Assert.Equal("text/plain", verdict.FileType);
Assert.Equal("EICAR virus test files", verdict.MimeType);
Assert.Contains("EICAR-Test-File", verdict.Detection);
}

[Fact]
Expand All @@ -332,9 +331,8 @@ public async Task ForUrl_WithEicarUrl_ReturnsMaliciousWithDetectionAndMimeType()
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");
Assert.Equal("text/plain", verdict.FileType);
Assert.Equal("EICAR virus test files", verdict.MimeType);
Assert.Contains("EICAR-Test-File", verdict.Detection);
}
}

0 comments on commit d048dba

Please sign in to comment.