Skip to content

Commit

Permalink
Merge pull request #438 from GDATASoftwareAG/typescript/fix-detection…
Browse files Browse the repository at this point in the history
…-and-file-mime-type

fix detection and mime file type
  • Loading branch information
lennartdohmann authored Apr 29, 2024
2 parents 8aa7a11 + 65e5eba commit 477de7f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 48 deletions.
8 changes: 4 additions & 4 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.lib_magic),
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detection, verdictResponse.file_type, verdictResponse.mime_type),
);
},
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.lib_magic),
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detection, verdictResponse.file_type, verdictResponse.mime_type),
);
},
reject: (reason) => reject(reason),
Expand Down Expand Up @@ -263,8 +263,8 @@ export class Vaas {
resolve: async (verdictResponse: VerdictResponse) => {
this.verdictPromises.delete(guid);
resolve(
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic),
);
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detection, verdictResponse.file_type, verdictResponse.mime_type),
);
},
reject: (reason) => reject(reason),
});
Expand Down
10 changes: 0 additions & 10 deletions typescript/src/messages/detection.ts

This file was deleted.

9 changes: 0 additions & 9 deletions typescript/src/messages/lib_magic.ts

This file was deleted.

7 changes: 3 additions & 4 deletions typescript/src/messages/vaas_verdict.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { JsonProperty, JsonObject } from "typescript-json-serializer";
import { Verdict } from "../Verdict";
import { Detection } from "./detection";
import { LibMagic } from "./lib_magic";

@JsonObject()
export class VaasVerdict {
public constructor(
@JsonProperty() public sha256: string,
@JsonProperty() public verdict: Verdict,
@JsonProperty() public detections: Detection[] | undefined,
@JsonProperty() public libMagic: LibMagic | undefined,
@JsonProperty() public detection: string | undefined,
@JsonProperty() public file_type: string | undefined,
@JsonProperty() public mime_type: string | undefined,
) {}
}
7 changes: 3 additions & 4 deletions typescript/src/messages/verdict_response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { JsonProperty, JsonObject } from "typescript-json-serializer";
import { Kind, Message } from "./message";
import { Verdict } from "../Verdict";
import { Detection } from "./detection";
import { LibMagic } from "./lib_magic";

@JsonObject()
export class VerdictResponse extends Message {
Expand All @@ -12,8 +10,9 @@ export class VerdictResponse extends Message {
@JsonProperty() public verdict: Verdict,
@JsonProperty() public upload_token: string | undefined,
@JsonProperty() public url: string | undefined,
@JsonProperty() public detections: Detection[] | undefined,
@JsonProperty() public lib_magic: LibMagic | undefined,
@JsonProperty() public detection: string | undefined,
@JsonProperty() public file_type: string | undefined,
@JsonProperty() public mime_type: string | undefined,
) {
super(Kind.VerdictResponse);
}
Expand Down
34 changes: 17 additions & 17 deletions typescript/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ describe("Test verdict requests", function () {
expect(verdict.sha256.toUpperCase()).to.equal(sha256);
}).timeout(45000);

// it("returns Pup for AMTSO pup sample", async () => {
// const vaas = await createVaasWithClientCredentialsGrantAuthenticator();
// const sha256 =
// "d6f6c6b9fde37694e12b12009ad11ab9ec8dd0f193e7319c523933bdad8a50ad";
// let verdict = await vaas.forSha256(sha256);
// expect(verdict.verdict).to.equal("Pup");
// expect(verdict.sha256).to.equal(sha256);
// });
it("returns Pup for AMTSO pup sample", async () => {
const vaas = await createVaasWithClientCredentialsGrantAuthenticator();
const sha256 =
"d6f6c6b9fde37694e12b12009ad11ab9ec8dd0f193e7319c523933bdad8a50ad";
let verdict = await vaas.forSha256(sha256);
expect(verdict.verdict).to.equal("Pup");
expect(verdict.sha256).to.equal(sha256);
});

it('if a clean url is submitted, a verdict "clean" is expected', async () => {
const vaas = await createVaasWithClientCredentialsGrantAuthenticator();
Expand All @@ -264,9 +264,9 @@ describe("Test verdict requests", function () {
stream.push(null);
const verdict = await vaas.forStream(stream);
expect(verdict.verdict).to.equal("Clean");
expect(verdict.detections).to.be.empty;
expect(verdict.libMagic?.file_type).to.equal("ASCII text, with no line terminators");
expect(verdict.libMagic?.mime_type).to.equal("text/plain");
expect(verdict.detection).to.be.undefined;
expect(verdict.file_type).to.equal("ASCII text, with no line terminators");
expect(verdict.mime_type).to.equal("text/plain");
});

it('if a EICAR stream is submitted, a verdict "malicious" is expected', async () => {
Expand All @@ -279,9 +279,9 @@ describe("Test verdict requests", function () {
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?.file_type).to.equal("EICAR virus test files");
expect(verdict.libMagic?.mime_type).to.equal("text/plain");
expect(verdict.detection).to.be.not.empty;
expect(verdict.file_type).to.equal("EICAR virus test files");
expect(verdict.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,9 +292,9 @@ 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?.file_type).to.equal("EICAR virus test files");
expect(verdict.libMagic?.mime_type).to.equal("text/plain");
expect(verdict.detection).to.be.not.empty;
expect(verdict.file_type).to.equal("EICAR virus test files");
expect(verdict.mime_type).to.equal("text/plain");
});
});

Expand Down

0 comments on commit 477de7f

Please sign in to comment.