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 all commits
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
10 changes: 10 additions & 0 deletions php/src/vaas/Message/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace VaasSdk\Message;

class Detection
{
public ?int $engine;
public string $fileName;
public string $virus;
}
43 changes: 0 additions & 43 deletions php/src/vaas/Message/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,12 @@
class Error extends BaseMessage
{
public string $type;

public string $requestId;

public string $text;

public ?ProblemDetails $problem_details;

public function __construct()
{
$this->kind = Kind::Error;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @return Kind
*/
public function getKind(): Kind
{
return $this->kind;
}

/**
* @return ProblemDetails
*/
public function getProblemDetails(): ProblemDetails
{
return $this->problem_details;
}

/**
* @return string
*/
public function getRequestId(): string
{
return $this->requestId;
}

/**
* @return string
*/
public function getText(): string
{
return $this->text;
}
}
9 changes: 9 additions & 0 deletions php/src/vaas/Message/LibMagic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace VaasSdk\Message;

class LibMagic
{
public string $fileType;
public string $mimeType;
}
19 changes: 1 addition & 18 deletions php/src/vaas/Message/ProblemDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,5 @@
class ProblemDetails
{
public string $type;

public string $detail;

/**
* @return string
*/
public function getDetail(): string
{
return $this->detail;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
}
}
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;
}
2 changes: 2 additions & 0 deletions php/src/vaas/Message/VerdictResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class VerdictResponse extends BaseMessage
public string $guid;
public string $sha256;
public ?string $upload_token;
public ?LibMagic $libMagic;
public ?array $detections;
}
4 changes: 2 additions & 2 deletions php/src/vaas/Vaas.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ private function _waitForVerdict(string $guid): VerdictResponse
private function _handleWebSocketErrorResponse(Error $errorResponse): void
{
if (isset($errorResponse->problem_details->detail)) {
$details = $errorResponse->problem_details->getDetail();
$details = $errorResponse->problem_details->detail;
} else {
$details = null;
}
$errorType = $errorResponse->getType();
$errorType = $errorResponse->type;
if ($errorType == "ClientError") {
throw new VaasClientException($details);
}
Expand Down
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->mimeType);
$this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus"));
}
}
Loading