Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP implementation of #390 #393

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

unglaublicherdude marked this conversation as resolved.
Show resolved Hide resolved
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"));
}
}
Loading