files_antivirus/tests/StatusTest.php

84 строки
3.0 KiB
PHP
Исходник Обычный вид История

2014-02-23 23:35:16 +04:00
<?php
/**
* Copyright (c) 2014 Victor Dubiniuk <victor.dubiniuk@gmail.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
2017-02-03 17:27:10 +03:00
namespace OCA\Files_Antivirus\Tests;
2015-02-07 02:28:05 +03:00
use \OCA\Files_Antivirus\Db\RuleMapper;
use OCP\ILogger;
2015-02-07 02:28:05 +03:00
2017-02-03 17:27:10 +03:00
/**
* @group DB
*/
class StatusTest extends TestBase {
2014-02-23 23:35:16 +04:00
// See OCA\Files_Antivirus\Status::init for details
public const TEST_CLEAN = 0;
public const TEST_INFECTED = 1;
public const TEST_ERROR = 40;
2014-02-23 23:35:16 +04:00
2015-02-07 02:28:05 +03:00
protected $ruleMapper;
protected function setUp(): void {
2015-02-07 02:28:05 +03:00
parent::setUp();
$this->ruleMapper = new RuleMapper($this->db);
$this->ruleMapper->deleteAll();
$this->ruleMapper->populate();
2014-11-14 18:09:34 +03:00
}
public function testParseResponse() {
2014-02-23 23:35:16 +04:00
// Testing status codes
$testStatus = new \OCA\Files_Antivirus\Status(
$this->ruleMapper,
$this->createMock(ILogger::class)
);
2014-02-23 23:35:16 +04:00
2014-11-14 18:09:34 +03:00
$testStatus->parseResponse('dummy : OK', self::TEST_CLEAN);
2014-02-23 23:35:16 +04:00
$cleanScan = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_CLEAN, $cleanScan);
$this->assertEquals("", $testStatus->getDetails());
$scanOutput = "Thu Oct 28 13:02:19 2010 -> /tmp/kitten: Heuristics.Broken.Executable FOUND ";
$testStatus->parseResponse($scanOutput, self::TEST_INFECTED);
$infectedScan = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_INFECTED, $infectedScan);
$this->assertEquals('Heuristics.Broken.Executable', $testStatus->getDetails());
$testStatus->parseResponse('dummy', self::TEST_ERROR);
$failedScan = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_UNCHECKED, $failedScan);
$this->assertEquals('Unknown option passed.', $testStatus->getDetails());
// Testing raw output (e.g. daemon mode)
// Empty content means result is unknown
$testStatus->parseResponse('');
$failedScan2 = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_UNCHECKED, $failedScan2);
2014-11-14 18:09:34 +03:00
$this->assertEquals('No matching rules. Please check antivirus rules.', $testStatus->getDetails());
2014-02-23 23:35:16 +04:00
// No rules matched result is unknown too
$testStatus->parseResponse('123dc');
$failedScan3 = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_UNCHECKED, $failedScan3);
2014-11-14 18:09:34 +03:00
$this->assertEquals('No matching rules. Please check antivirus rules.', $testStatus->getDetails());
2014-02-23 23:35:16 +04:00
// File is clean
$testStatus->parseResponse('Thu Oct 28 13:02:19 2010 -> /tmp/kitten : OK');
$cleanScan2 = $testStatus->getNumericStatus();
2014-11-14 18:09:34 +03:00
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_CLEAN, $cleanScan2);
$this->assertEquals('', $testStatus->getDetails());
2014-02-23 23:35:16 +04:00
// File is infected
2014-11-14 18:09:34 +03:00
$testStatus->parseResponse('Thu Oct 28 13:02:19 2010 -> /tmp/kitten: Heuristics.Broken.Kitten FOUND');
2014-02-23 23:35:16 +04:00
$infectedScan2 = $testStatus->getNumericStatus();
$this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_INFECTED, $infectedScan2);
$this->assertEquals('Heuristics.Broken.Kitten', $testStatus->getDetails());
}
}