/** * Validate the uploaded file for virus/malware with ClamAV * * @param $attribute string * @param $value mixed * @param $parameters array * @return boolean */ public function validateClamav($attribute, $value, $parameters) { $file = $this->getFilePath($value); $clamavSocket = $this->getClamavSocket(); // Create a new socket instance $socket = (new Factory())->createClient($clamavSocket); // Create a new instance of the Client $quahog = new Client($socket); // Scan the file $result = $quahog->scanFile($file); // Check if scan result is not clean if (self::CLAMAV_STATUS_OK != $result['status']) { return false; } return true; }
public function testScanFile() { $this->socket->expects($this->any())->method('read')->will($this->returnValue('/tmp/quahog/EICAR: Eicar-Test-Signature FOUND')); $result = $this->quahog->scanFile('/tmp/quahog/EICAR'); $this->assertSame(array('filename' => '/tmp/quahog/EICAR', 'reason' => 'Eicar-Test-Signature', 'status' => 'FOUND'), $result); }