From d2947ae33595ee0b1980d8337374c6d3f6410e3e Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Wed, 13 Mar 2024 17:02:47 +0100 Subject: [PATCH] fixes the casing for detections and mime-types --- dotnet/Vaas/src/Vaas/Messages/Detection.cs | 6 +++--- dotnet/Vaas/src/Vaas/Messages/LibMagic.cs | 6 +++--- .../Vaas/src/Vaas/Messages/VerdictResponse.cs | 8 ++++---- golang/vaas/pkg/messages/detection.go | 2 +- golang/vaas/pkg/messages/lib_magic.go | 4 ++-- golang/vaas/pkg/messages/verdict_response.go | 2 +- .../java/de/gdata/vaas/messages/Detection.java | 5 ++++- .../java/de/gdata/vaas/messages/LibMagic.java | 6 +++++- .../gdata/vaas/messages/VerdictResponse.java | 2 +- php/src/vaas/Message/Detection.php | 2 +- php/src/vaas/Message/LibMagic.php | 4 ++-- php/src/vaas/Message/VaasVerdict.php | 2 +- php/src/vaas/Message/VerdictResponse.php | 2 +- php/tests/vaas/VaasTest.php | 4 ++-- typescript/src/Vaas.ts | 6 +++--- typescript/src/messages/detection.ts | 4 ++-- typescript/src/messages/lib_magic.ts | 6 +++--- typescript/src/messages/verdict_response.ts | 2 +- typescript/tests/test.ts | 18 +++++++++--------- 19 files changed, 49 insertions(+), 42 deletions(-) diff --git a/dotnet/Vaas/src/Vaas/Messages/Detection.cs b/dotnet/Vaas/src/Vaas/Messages/Detection.cs index bf3ae184..2c45f5c2 100644 --- a/dotnet/Vaas/src/Vaas/Messages/Detection.cs +++ b/dotnet/Vaas/src/Vaas/Messages/Detection.cs @@ -6,10 +6,10 @@ public class Detection { [JsonPropertyName("engine")] public int? Engine { get; init; } - - [JsonPropertyName("fileName")] + + [JsonPropertyName("file_name")] public string FileName { get; init; } - + [JsonPropertyName("virus")] public string Virus { get; init; } } \ No newline at end of file diff --git a/dotnet/Vaas/src/Vaas/Messages/LibMagic.cs b/dotnet/Vaas/src/Vaas/Messages/LibMagic.cs index 42c29583..aba3bd7e 100644 --- a/dotnet/Vaas/src/Vaas/Messages/LibMagic.cs +++ b/dotnet/Vaas/src/Vaas/Messages/LibMagic.cs @@ -4,9 +4,9 @@ namespace Vaas.Messages; public class LibMagic { - [JsonPropertyName("fileType")] + [JsonPropertyName("file_type")] public string FileType { get; init; } - - [JsonPropertyName("mimeType")] + + [JsonPropertyName("mime_type")] public string MimeType { get; init; } } \ No newline at end of file diff --git a/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs b/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs index 6e0cd4d0..04dee71f 100644 --- a/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs +++ b/dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs @@ -14,7 +14,7 @@ public VerdictResponse(string sha256, Verdict verdict) Sha256 = sha256; Verdict = verdict; } - + [JsonPropertyName("kind")] public string Kind { get; init; } = "VerdictResponse"; @@ -33,11 +33,11 @@ public VerdictResponse(string sha256, Verdict verdict) [JsonPropertyName("upload_token")] public string? UploadToken { get; init; } - + [JsonPropertyName("detections")] public List? Detections { get; init; } - - [JsonPropertyName("libMagic")] + + [JsonPropertyName("lib_magic")] public LibMagic? LibMagic { get; init; } [MemberNotNullWhen(true, nameof(Sha256), nameof(Guid))] diff --git a/golang/vaas/pkg/messages/detection.go b/golang/vaas/pkg/messages/detection.go index bbf8f461..41a2d532 100644 --- a/golang/vaas/pkg/messages/detection.go +++ b/golang/vaas/pkg/messages/detection.go @@ -4,6 +4,6 @@ package messages // TokenResponse represents a response containing an access token. type Detection struct { Engine int `json:"engine"` - FileName string `json:"fileName"` + FileName string `json:"file_name"` Virus string `json:"virus"` } diff --git a/golang/vaas/pkg/messages/lib_magic.go b/golang/vaas/pkg/messages/lib_magic.go index 1ca94454..7704c62d 100644 --- a/golang/vaas/pkg/messages/lib_magic.go +++ b/golang/vaas/pkg/messages/lib_magic.go @@ -3,6 +3,6 @@ package messages // TokenResponse represents a response containing an access token. type LibMagic struct { - FileType string `json:"fileType"` - MimeType string `json:"mimeType"` + FileType string `json:"file_type"` + MimeType string `json:"mime_type"` } diff --git a/golang/vaas/pkg/messages/verdict_response.go b/golang/vaas/pkg/messages/verdict_response.go index eda72965..863d71e6 100644 --- a/golang/vaas/pkg/messages/verdict_response.go +++ b/golang/vaas/pkg/messages/verdict_response.go @@ -10,7 +10,7 @@ type VerdictResponse struct { URL string `json:"url"` UploadToken string `json:"upload_token"` Detections []Detection `json:"detections"` - LibMagic LibMagic `json:"libMagic"` + LibMagic LibMagic `json:"lib_magic"` } // IsValid checks if the VerdictResponse is valid. diff --git a/java/src/main/java/de/gdata/vaas/messages/Detection.java b/java/src/main/java/de/gdata/vaas/messages/Detection.java index 87e9ca82..6fe96af5 100644 --- a/java/src/main/java/de/gdata/vaas/messages/Detection.java +++ b/java/src/main/java/de/gdata/vaas/messages/Detection.java @@ -1,5 +1,7 @@ package de.gdata.vaas.messages; +import com.google.gson.annotations.SerializedName; + import lombok.Getter; import lombok.NonNull; @@ -8,8 +10,9 @@ public class Detection { int engine; @NonNull + @SerializedName("file_name") String fileName; - + @NonNull String virus; } diff --git a/java/src/main/java/de/gdata/vaas/messages/LibMagic.java b/java/src/main/java/de/gdata/vaas/messages/LibMagic.java index 9a0b6a31..5b594b1f 100644 --- a/java/src/main/java/de/gdata/vaas/messages/LibMagic.java +++ b/java/src/main/java/de/gdata/vaas/messages/LibMagic.java @@ -1,13 +1,17 @@ package de.gdata.vaas.messages; +import com.google.gson.annotations.SerializedName; + import lombok.Getter; import lombok.NonNull; @Getter public class LibMagic { @NonNull + @SerializedName("file_type") String fileType; - + @NonNull + @SerializedName("mime_type") String mimeType; } diff --git a/java/src/main/java/de/gdata/vaas/messages/VerdictResponse.java b/java/src/main/java/de/gdata/vaas/messages/VerdictResponse.java index 197021b3..8b728238 100644 --- a/java/src/main/java/de/gdata/vaas/messages/VerdictResponse.java +++ b/java/src/main/java/de/gdata/vaas/messages/VerdictResponse.java @@ -30,7 +30,7 @@ public class VerdictResponse extends MessageType { @SerializedName("detections") ArrayList detections; @Getter - @SerializedName("libMagic") + @SerializedName("lib_magic") LibMagic libMagic; private VerdictResponse() { diff --git a/php/src/vaas/Message/Detection.php b/php/src/vaas/Message/Detection.php index c275574f..d6f435d6 100644 --- a/php/src/vaas/Message/Detection.php +++ b/php/src/vaas/Message/Detection.php @@ -5,6 +5,6 @@ class Detection { public ?int $engine; - public string $fileName; + public string $file_name; public string $virus; } diff --git a/php/src/vaas/Message/LibMagic.php b/php/src/vaas/Message/LibMagic.php index e09509f0..2cad3c9f 100644 --- a/php/src/vaas/Message/LibMagic.php +++ b/php/src/vaas/Message/LibMagic.php @@ -4,6 +4,6 @@ class LibMagic { - public string $fileType; - public string $mimeType; + public string $file_type; + public string $mime_type; } diff --git a/php/src/vaas/Message/VaasVerdict.php b/php/src/vaas/Message/VaasVerdict.php index 68bdb945..d2b22873 100644 --- a/php/src/vaas/Message/VaasVerdict.php +++ b/php/src/vaas/Message/VaasVerdict.php @@ -9,7 +9,7 @@ public function __construct(VerdictResponse $verdictResponse) $this->Sha256 = $verdictResponse->sha256 ?? ""; $this->Verdict = $verdictResponse->verdict ?? Verdict::UNKNOWN; $this->Guid = $verdictResponse->guid ?? ""; - $this->LibMagic = $verdictResponse->libMagic ?? null; + $this->LibMagic = $verdictResponse->lib_magic ?? null; $this->Detections = $verdictResponse->detections ?? null; } diff --git a/php/src/vaas/Message/VerdictResponse.php b/php/src/vaas/Message/VerdictResponse.php index fec27bff..79c5db54 100644 --- a/php/src/vaas/Message/VerdictResponse.php +++ b/php/src/vaas/Message/VerdictResponse.php @@ -9,6 +9,6 @@ class VerdictResponse extends BaseMessage public string $guid; public string $sha256; public ?string $upload_token; - public ?LibMagic $libMagic; + public ?LibMagic $lib_magic; public ?array $detections; } diff --git a/php/tests/vaas/VaasTest.php b/php/tests/vaas/VaasTest.php index 22d2a5f5..1723e18f 100644 --- a/php/tests/vaas/VaasTest.php +++ b/php/tests/vaas/VaasTest.php @@ -608,7 +608,7 @@ public function testForStream_WithEicarUrlContentAsStream_ReturnsMaliciousWithDe $verdict = $vaas->ForStream($stream); $this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict); - $this->assertEquals("text/plain", $verdict->LibMagic->mimeType); - $this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus")); + $this->assertEquals("text/plain", $verdict->LibMagic->mime_type); + $this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus")); } } diff --git a/typescript/src/Vaas.ts b/typescript/src/Vaas.ts index b5959c43..f4065c9e 100644 --- a/typescript/src/Vaas.ts +++ b/typescript/src/Vaas.ts @@ -188,7 +188,7 @@ export class Vaas { this.verdictPromises.delete(guid); resolve( - new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic), ); }, reject: (reason) => reject(reason), @@ -216,7 +216,7 @@ export class Vaas { resolve: async (verdictResponse: VerdictResponse) => { this.verdictPromises.delete(guid); resolve( - new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic), ); }, reject: (reason) => reject(reason), @@ -257,7 +257,7 @@ export class Vaas { ); } resolve( - new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic), ); }, reject: (reason) => reject(reason), diff --git a/typescript/src/messages/detection.ts b/typescript/src/messages/detection.ts index a25ac8a2..8ba929ef 100644 --- a/typescript/src/messages/detection.ts +++ b/typescript/src/messages/detection.ts @@ -4,7 +4,7 @@ import { JsonProperty, JsonObject } from "typescript-json-serializer"; export class Detection { public constructor( @JsonProperty() public engine: number, - @JsonProperty() public fileName: string, + @JsonProperty() public file_name: string, @JsonProperty() public virus: string, - ) {} + ) { } } diff --git a/typescript/src/messages/lib_magic.ts b/typescript/src/messages/lib_magic.ts index f43d6ac6..af3a16e7 100644 --- a/typescript/src/messages/lib_magic.ts +++ b/typescript/src/messages/lib_magic.ts @@ -3,7 +3,7 @@ import { JsonProperty, JsonObject } from "typescript-json-serializer"; @JsonObject() export class LibMagic { public constructor( - @JsonProperty() public fileType: number, - @JsonProperty() public mimeType: string, - ) {} + @JsonProperty() public file_type: number, + @JsonProperty() public mime_type: string, + ) { } } diff --git a/typescript/src/messages/verdict_response.ts b/typescript/src/messages/verdict_response.ts index 1f836e42..91168904 100644 --- a/typescript/src/messages/verdict_response.ts +++ b/typescript/src/messages/verdict_response.ts @@ -13,7 +13,7 @@ export class VerdictResponse extends Message { @JsonProperty() public upload_token: string | undefined, @JsonProperty() public url: string | undefined, @JsonProperty() public detections: Detection[] | undefined, - @JsonProperty() public libMagic: LibMagic | undefined, + @JsonProperty() public lib_magic: LibMagic | undefined, ) { super(Kind.VerdictResponse); } diff --git a/typescript/tests/test.ts b/typescript/tests/test.ts index c4838d3d..d59bb371 100644 --- a/typescript/tests/test.ts +++ b/typescript/tests/test.ts @@ -271,7 +271,7 @@ describe("Test verdict requests", function () { it('if a EICAR stream is submitted, a verdict "malicious" is expected', async () => { const vaas = await createVaasWithClientCredentialsGrantAuthenticator(); const stream = new Readable(); - stream._read = () => {}; + stream._read = () => { }; stream.push( `X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*`, ); @@ -279,8 +279,8 @@ describe("Test verdict requests", function () { const verdict = await vaas.forStream(stream); expect(verdict.verdict).to.equal("Malicious"); expect(verdict.detections).to.be.not.empty; - expect(verdict.libMagic?.fileType).to.equal("EICAR virus test files"); - expect(verdict.libMagic?.mimeType).to.equal("text/plain"); + expect(verdict.libMagic?.file_type).to.equal("EICAR virus test files"); + expect(verdict.libMagic?.mime_type).to.equal("text/plain"); }); it('if a EICAR stream from an url is submitted, a response with verdict, libmagic & detections is expected', async () => { @@ -292,8 +292,8 @@ describe("Test verdict requests", function () { const verdict = await vaas.forStream(response.data); expect(verdict.verdict).to.equal("Malicious"); expect(verdict.detections).to.be.not.empty; - expect(verdict.libMagic?.fileType).to.equal("EICAR virus test files"); - expect(verdict.libMagic?.mimeType).to.equal("text/plain"); + expect(verdict.libMagic?.file_type).to.equal("EICAR virus test files"); + expect(verdict.libMagic?.mime_type).to.equal("text/plain"); }); }); @@ -311,10 +311,10 @@ describe("Vaas", async () => { beforeEach(() => { webSocket = { readyState: WebSocket.CONNECTING as number, - onopen: () => {}, - onclose: () => {}, - onmessage: () => {}, - send: (data: any) => {}, + onopen: () => { }, + onclose: () => { }, + onmessage: () => { }, + send: (data: any) => { }, } as any; vaas = new Vaas((url) => webSocket); });