Skip to content

Commit

Permalink
PHP implementation of #390
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartdohmann committed Mar 12, 2024
1 parent d42ad3c commit 86f9b42
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
40 changes: 40 additions & 0 deletions php/src/vaas/Message/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace VaasSdk\Message;

class Detection
{
public ?int $engine;
public string $fileName;
public string $virus;

public function getEngine(): int
{
return $this->engine;
}

public function setEngine(int $engine): void
{
$this->engine = $engine;
}

public function getFileName(): string
{
return $this->fileName;
}

public function setFileName(string $fileName): void
{
$this->fileName = $fileName;
}

public function getVirus(): string
{
return $this->virus;
}

public function setVirus(string $virus): void
{
$this->virus = $virus;
}
}
29 changes: 29 additions & 0 deletions php/src/vaas/Message/LibMagic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace VaasSdk\Message;

class LibMagic
{
public string $fileType;
public string $mimeType;

public function getMimeType(): string
{
return $this->mimeType;
}

public function setMimeType(string $mimeType): void
{
$this->mimeType = $mimeType;
}

public function getFileType(): string
{
return $this->fileType;
}

public function setFileType(string $fileType): void
{
$this->fileType = $fileType;
}
}
4 changes: 4 additions & 0 deletions php/src/vaas/Message/VaasVerdict.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ 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->Detections = $verdictResponse->detections ?? null;
}

public string $Sha256;
public Verdict $Verdict;
public string $Guid;
public ?LibMagic $LibMagic;
public ?array $Detections;
}
3 changes: 3 additions & 0 deletions php/src/vaas/Message/VerdictResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ class VerdictResponse extends BaseMessage
public string $guid;
public string $sha256;
public ?string $upload_token;
public ?LibMagic $libMagic;

public ?array $detections;
}
15 changes: 15 additions & 0 deletions php/tests/vaas/VaasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,19 @@ public function testForStream_WithEicarUrlContentAsStream_ReturnsMalicious()

$this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict);
}

public function testForStream_WithEicarUrlContentAsStream_ReturnsMaliciousWithDetectionAndMimeType()
{
$vaas = $this->_getVaas();
$vaas->Connect($this->getClientCredentialsGrantAuthenticator()->getToken());
$httpClient = new Client();
$response = $httpClient->get(self::MALICIOUS_URL);
$stream = new Stream($response->getBody()->detach());

$verdict = $vaas->ForStream($stream);

$this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict);
$this->assertEquals("text/plain", $verdict->LibMagic->getMimeType());
$this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus"));
}
}

0 comments on commit 86f9b42

Please sign in to comment.