Skip to content

Commit

Permalink
Get socket from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspikes committed Apr 26, 2018
1 parent 835da24 commit baf4c90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ before_script:
- composer install --prefer-source --no-interaction --dev

script:
- phpunit --colors --verbose --coverage-clover build/logs/clover.xml
- php vendor/bin/phpunit --colors --verbose --coverage-clover build/logs/clover.xml

after_script: if [ $(phpenv version-name) = "5.6" ]; then php vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml; fi
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Custom Laravel 5 anti-virus validator for file uploads.
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Configuration](#configuration)
* [Author](#author)

<a name="requirements"></a>
Expand Down Expand Up @@ -65,6 +66,13 @@ $rules = array(
);
```

<a name="configuration"></a>
## Configuration

By default the package will try to connect the clamav daemon via the default socket file (/var/run/clamav/clamd.ctl) and if it fails it will try the tcp port (127.0.0.1:3310)

But you can set the `CLAMAV_UNIX_SOCKET` (socket file path) or `CLAMAV_LOCAL_TCP_SOCKET` (host:port) environment variables to override this.

<a name="author"></a>
## Author

Expand Down
23 changes: 19 additions & 4 deletions tests/ValidatorClamavTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Sunspikes\Tests\ClamavValidator;

use Illuminate\Contracts\Translation\Translator;
use Mockery;
use Illuminate\Contracts\Translation\Translator;
use Sunspikes\ClamavValidator\ClamavValidator;
use Sunspikes\ClamavValidator\ClamavValidatorException;

Expand All @@ -21,13 +21,13 @@ public function setUp()
$this->translator = Mockery::mock(Translator::class);
$this->translator->shouldReceive('trans');
$this->clean_data = [
'file' => dirname(__FILE__) . '/files/test1.txt'
'file' => $this->getTempPath(__DIR__ . '/files/test1.txt')
];
$this->virus_data = [
'file' => dirname(__FILE__) . '/files/test2.txt'
'file' => $this->getTempPath(__DIR__ . '/files/test2.txt')
];
$this->error_data = [
'file' => dirname(__FILE__) . '/files/test3.txt'
'file' => $this->getTempPath(__DIR__ . '/files/test3.txt')
];
$this->messages = [];
}
Expand Down Expand Up @@ -77,4 +77,19 @@ public function testValidatesError()

$validator->passes();
}

/**
* Move to temp dir, so that clamav can access the file
*
* @param $file
* @return string
*/
private function getTempPath($file)
{
$tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename($file);
copy($file, $tempPath);
chmod($tempPath, 0644);

return $tempPath;
}
}

0 comments on commit baf4c90

Please sign in to comment.