diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 244b7f33..905bd57d 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -10,8 +10,15 @@ use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Jail; +use OC\Http\Client\ClientService; +use OCA\Files_Antivirus\AppConfig; use OCA\Files_Antivirus\AvirWrapper; +use OCA\Files_Antivirus\Scanner\ExternalClam; +use OCA\Files_Antivirus\Scanner\ExternalKaspersky; +use OCA\Files_Antivirus\Scanner\ICAP; +use OCA\Files_Antivirus\Scanner\LocalClam; use OCA\Files_Antivirus\Scanner\ScannerFactory; +use OCA\Files_Antivirus\StatusFactory; use OCP\Activity\IManager; use OCP\App\IAppManager; use OCP\AppFramework\App; @@ -21,8 +28,10 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IHomeStorage; use OCP\Files\Storage\IStorage; +use OCP\ICertificateManager; use OCP\IL10N; use OCP\Util; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { @@ -33,6 +42,40 @@ public function __construct(array $urlParams = []) { } public function register(IRegistrationContext $context): void { + $context->registerService(ExternalClam::class, function (ContainerInterface $c) { + return new ExternalClam( + $c->get(AppConfig::class), + $c->get(LoggerInterface::class), + $c->get(StatusFactory::class), + ); + }, false); + + $context->registerService(LocalClam::class, function (ContainerInterface $c) { + return new LocalClam( + $c->get(AppConfig::class), + $c->get(LoggerInterface::class), + $c->get(StatusFactory::class), + ); + }, false); + + $context->registerService(ExternalKaspersky::class, function (ContainerInterface $c) { + return new ExternalKaspersky( + $c->get(AppConfig::class), + $c->get(LoggerInterface::class), + $c->get(StatusFactory::class), + $c->get(ClientService::class), + ); + }, false); + + $context->registerService(ICAP::class, function (ContainerInterface $c) { + return new ICAP( + $c->get(AppConfig::class), + $c->get(LoggerInterface::class), + $c->get(StatusFactory::class), + $c->get(ICertificateManager::class), + ); + }, false); + Util::connectHook('OC_Filesystem', 'preSetup', $this, 'setupWrapper'); } diff --git a/tests/Scanner/ScannerFactoryTest.php b/tests/Scanner/ScannerFactoryTest.php new file mode 100644 index 00000000..20a27cba --- /dev/null +++ b/tests/Scanner/ScannerFactoryTest.php @@ -0,0 +1,51 @@ +config = $this->createMock(IConfig::class); + $this->config->method('getAppValue') + ->with('files_antivirus', 'av_mode', 'executable') + ->willReturn('daemon'); + + $this->appConfig = new AppConfig($this->config); + + $this->request = $this->createMock(IRequest::class); + + $this->scannerFactory = new ScannerFactory( + $this->appConfig, + \OC::$server, + $this->request, + ); + } + + public function testGetScanner() { + $instanceA = $this->scannerFactory->getScanner('/dev/null'); + $instanceB = $this->scannerFactory->getScanner('/dev/null'); + + $this->assertNotSame($instanceA, $instanceB); + } + +}