Skip to content

Commit

Permalink
Use resource stream for instead of file path (sunspikes#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspikes authored Jul 3, 2018
1 parent baf4c90 commit d52c441
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/ClamavValidator/ClamavValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ public function validateClamav($attribute, $value, $parameters)
// Create a new instance of the Client
$quahog = new Client($socket, self::CLAMAV_SOCKET_READ_TIMEOUT, PHP_NORMAL_READ);

// Check if the file is readable
if (! is_readable($file)) {
throw new ClamavValidatorException(sprintf('The file "%s" is not readable', $file));
}

// Scan the file
$result = $quahog->scanFile($file);
$result = $quahog->scanResourceStream(fopen($file, 'rb'));

if (self::CLAMAV_STATUS_ERROR === $result['status']) {
throw new ClamavValidatorException($result['reason']);
Expand Down
4 changes: 2 additions & 2 deletions tests/ValidatorClamavTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function testValidatesVirus()

public function testValidatesError()
{
$this->setExpectedException(ClamavValidatorException::class, 'is not readable');

$validator = new ClamavValidator(
$this->translator,
$this->error_data,
Expand All @@ -73,8 +75,6 @@ public function testValidatesError()

chmod($this->error_data['file'], 0000);

$this->setExpectedException(ClamavValidatorException::class, 'Access denied.');

$validator->passes();
}

Expand Down

0 comments on commit d52c441

Please sign in to comment.