Skip to content

Commit

Permalink
Merge pull request #387 from GDATASoftwareAG/typescript/detections-mi…
Browse files Browse the repository at this point in the history
…metypes-filetypes

add libmagic & detections in response
  • Loading branch information
doxthree authored Mar 11, 2024
2 parents d612b3b + 8c388fb commit a9daa50
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
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),
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic),
);
},
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),
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.libMagic),
);
},
reject: (reason) => reject(reason),
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions typescript/src/messages/detection.ts
Original file line number Diff line number Diff line change
@@ -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,
) {}
}
9 changes: 9 additions & 0 deletions typescript/src/messages/lib_magic.ts
Original file line number Diff line number Diff line change
@@ -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,
) {}
}
4 changes: 4 additions & 0 deletions typescript/src/messages/vaas_verdict.ts
Original file line number Diff line number Diff line change
@@ -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,
) {}
}
4 changes: 4 additions & 0 deletions typescript/src/messages/verdict_response.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion typescript/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -276,16 +278,22 @@ 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<Readable>(
"https://secure.eicar.org/eicar.com.txt",
{ responseType: "stream" },
);
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");
});
});

Expand Down

0 comments on commit a9daa50

Please sign in to comment.