Skip to content

Commit

Permalink
fixes the casing for detections and mime-types
Browse files Browse the repository at this point in the history
  • Loading branch information
ata-no-one committed Mar 13, 2024
1 parent dadea1b commit d2947ae
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 42 deletions.
6 changes: 3 additions & 3 deletions dotnet/Vaas/src/Vaas/Messages/Detection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public class Detection
{
[JsonPropertyName("engine")]
public int? Engine { get; init; }
[JsonPropertyName("fileName")]

[JsonPropertyName("file_name")]
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.

[JsonPropertyName("virus")]
public string Virus { get; init; }

Check warning on line 14 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 'Virus' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
6 changes: 3 additions & 3 deletions dotnet/Vaas/src/Vaas/Messages/LibMagic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Vaas.Messages;

public class LibMagic
{
[JsonPropertyName("fileType")]
[JsonPropertyName("file_type")]
public string FileType { get; init; }

Check warning on line 8 in dotnet/Vaas/src/Vaas/Messages/LibMagic.cs

View workflow job for this annotation

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

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

Check warning on line 8 in dotnet/Vaas/src/Vaas/Messages/LibMagic.cs

View workflow job for this annotation

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

Non-nullable property 'FileType' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[JsonPropertyName("mimeType")]

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

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

View workflow job for this annotation

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

Non-nullable property 'MimeType' 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/LibMagic.cs

View workflow job for this annotation

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

Non-nullable property 'MimeType' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
8 changes: 4 additions & 4 deletions dotnet/Vaas/src/Vaas/Messages/VerdictResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public VerdictResponse(string sha256, Verdict verdict)
Sha256 = sha256;
Verdict = verdict;
}

[JsonPropertyName("kind")]
public string Kind { get; init; } = "VerdictResponse";

Expand All @@ -33,11 +33,11 @@ public VerdictResponse(string sha256, Verdict verdict)

[JsonPropertyName("upload_token")]
public string? UploadToken { get; init; }

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

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

[MemberNotNullWhen(true, nameof(Sha256), nameof(Guid))]
Expand Down
2 changes: 1 addition & 1 deletion golang/vaas/pkg/messages/detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 2 additions & 2 deletions golang/vaas/pkg/messages/lib_magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 1 addition & 1 deletion golang/vaas/pkg/messages/verdict_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion java/src/main/java/de/gdata/vaas/messages/Detection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.gdata.vaas.messages;

import com.google.gson.annotations.SerializedName;

import lombok.Getter;
import lombok.NonNull;

Expand All @@ -8,8 +10,9 @@ public class Detection {
int engine;

@NonNull
@SerializedName("file_name")
String fileName;

@NonNull
String virus;
}
6 changes: 5 additions & 1 deletion java/src/main/java/de/gdata/vaas/messages/LibMagic.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class VerdictResponse extends MessageType {
@SerializedName("detections")
ArrayList<Detection> detections;
@Getter
@SerializedName("libMagic")
@SerializedName("lib_magic")
LibMagic libMagic;

private VerdictResponse() {
Expand Down
2 changes: 1 addition & 1 deletion php/src/vaas/Message/Detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
class Detection
{
public ?int $engine;
public string $fileName;
public string $file_name;
public string $virus;
}
4 changes: 2 additions & 2 deletions php/src/vaas/Message/LibMagic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class LibMagic
{
public string $fileType;
public string $mimeType;
public string $file_type;
public string $mime_type;
}
2 changes: 1 addition & 1 deletion php/src/vaas/Message/VaasVerdict.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion php/src/vaas/Message/VerdictResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions php/tests/vaas/VaasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
6 changes: 3 additions & 3 deletions typescript/src/Vaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions typescript/src/messages/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}
) { }
}
6 changes: 3 additions & 3 deletions typescript/src/messages/lib_magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) { }
}
2 changes: 1 addition & 1 deletion typescript/src/messages/verdict_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions typescript/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,16 @@ 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*`,
);
stream.push(null);
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 () => {
Expand All @@ -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");
});
});

Expand All @@ -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);
});
Expand Down

0 comments on commit d2947ae

Please sign in to comment.