diff --git a/typescript/src/Vaas.ts b/typescript/src/Vaas.ts index 7cc6b123..b5959c43 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), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), ); }, 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), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), ); }, reject: (reason) => reject(reason), @@ -257,7 +257,7 @@ export class Vaas { ); } resolve( - new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict), + new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic), ); }, reject: (reason) => reject(reason), diff --git a/typescript/src/messages/detection.ts b/typescript/src/messages/detection.ts new file mode 100644 index 00000000..a25ac8a2 --- /dev/null +++ b/typescript/src/messages/detection.ts @@ -0,0 +1,10 @@ +import { JsonProperty, JsonObject } from "typescript-json-serializer"; + +@JsonObject() +export class Detection { + public constructor( + @JsonProperty() public engine: number, + @JsonProperty() public fileName: string, + @JsonProperty() public virus: string, + ) {} +} diff --git a/typescript/src/messages/lib_magic.ts b/typescript/src/messages/lib_magic.ts new file mode 100644 index 00000000..f43d6ac6 --- /dev/null +++ b/typescript/src/messages/lib_magic.ts @@ -0,0 +1,9 @@ +import { JsonProperty, JsonObject } from "typescript-json-serializer"; + +@JsonObject() +export class LibMagic { + public constructor( + @JsonProperty() public fileType: number, + @JsonProperty() public mimeType: string, + ) {} +} diff --git a/typescript/src/messages/vaas_verdict.ts b/typescript/src/messages/vaas_verdict.ts index e6d3535b..f4487b11 100644 --- a/typescript/src/messages/vaas_verdict.ts +++ b/typescript/src/messages/vaas_verdict.ts @@ -1,10 +1,14 @@ 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, ) {} } diff --git a/typescript/src/messages/verdict_response.ts b/typescript/src/messages/verdict_response.ts index dd143eb4..1f836e42 100644 --- a/typescript/src/messages/verdict_response.ts +++ b/typescript/src/messages/verdict_response.ts @@ -1,6 +1,8 @@ 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 { @@ -10,6 +12,8 @@ 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 libMagic: LibMagic | undefined, ) { super(Kind.VerdictResponse); } diff --git a/typescript/tests/test.ts b/typescript/tests/test.ts index 32286443..c4838d3d 100644 --- a/typescript/tests/test.ts +++ b/typescript/tests/test.ts @@ -264,6 +264,8 @@ 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.undefined; + expect(verdict.libMagic).to.be.undefined; }); it('if a EICAR stream is submitted, a verdict "malicious" is expected', async () => { @@ -276,9 +278,12 @@ 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?.fileType).to.equal("EICAR virus test files"); + expect(verdict.libMagic?.mimeType).to.equal("text/plain"); }); - it('if a EICAR stream from an url is submitted, a verdict "malicious" is expected', async () => { + it('if a EICAR stream from an url is submitted, a response with verdict, libmagic & detections is expected', async () => { const vaas = await createVaasWithClientCredentialsGrantAuthenticator(); const response = await axios.get( "https://secure.eicar.org/eicar.com.txt", @@ -286,6 +291,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?.fileType).to.equal("EICAR virus test files"); + expect(verdict.libMagic?.mimeType).to.equal("text/plain"); }); });