Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias <ilovemilk@wusa.io>2020-03-31 20:15:30 +0300
committerMatthias <ilovemilk@wusa.io>2020-03-31 20:15:30 +0300
commit9bc1a9180af141ed6349344ce2fd00a7b2ddefe7 (patch)
tree72f5bd77b3e024306d2a7b13fd99fcbfc38fa037
parentf5dc1c05f0907a282bd91db89a460d23b70a5c99 (diff)
remove storage wrapper
-rw-r--r--lib/AppInfo/Application.php33
-rw-r--r--lib/StorageWrapper.php259
-rw-r--r--tests/Unit/StorageWrapperTest.php203
3 files changed, 0 insertions, 495 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 287c7f2..a07ee35 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -185,7 +185,6 @@ class Application extends App
$sequenceAnalyzer = $this->getContainer()->query(SequenceAnalyzer::class);
$event->getServer()->addPlugin(new RequestPlugin($logger, $config, $userSession, $session, $service, $notifications, $classifier, $sequenceAnalyzer));
});
- //Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
Util::connectHook('OC_Filesystem', 'post_create', FilesHooks::class, 'onFileCreate');
Util::connectHook('OC_Filesystem', 'post_update', FilesHooks::class, 'onFileUpdate');
Util::connectHook('OC_Filesystem', 'post_rename', FilesHooks::class, 'onFileRename');
@@ -196,38 +195,6 @@ class Application extends App
$this->registerNotificationNotifier();
}
- /**
- * @internal
- */
- public function addStorageWrapper()
- {
- Filesystem::addStorageWrapper(self::APP_ID, [$this, 'addStorageWrapperCallback'], -10);
- }
-
- /**
- * @internal
- *
- * @param string $mountPoint
- * @param IStorage $storage
- *
- * @return StorageWrapper|IStorage
- */
- public function addStorageWrapperCallback($mountPoint, IStorage $storage)
- {
- if (!\OC::$CLI && !$storage->instanceOfStorage('OCA\Files_Sharing\SharedStorage')) {
- /** @var Monitor $monitor */
- $monitor = $this->getContainer()->query(Monitor::class);
-
- return new StorageWrapper([
- 'storage' => $storage,
- 'mountPoint' => $mountPoint,
- 'monitor' => $monitor,
- ]);
- }
-
- return $storage;
- }
-
protected function registerNotificationNotifier()
{
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
diff --git a/lib/StorageWrapper.php b/lib/StorageWrapper.php
deleted file mode 100644
index 17f18e3..0000000
--- a/lib/StorageWrapper.php
+++ /dev/null
@@ -1,259 +0,0 @@
-<?php
-
-/**
- * @copyright Copyright (c) 2017 Matthias Held <matthias.held@uni-konstanz.de>
- * @author Matthias Held <matthias.held@uni-konstanz.de>
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace OCA\RansomwareDetection;
-
-use OC\Files\Storage\Wrapper\Wrapper;
-use OCP\Files\Storage\IStorage;
-
-class StorageWrapper extends Wrapper
-{
- /** @var Monitor */
- protected $monitor;
-
- /** @var string */
- public $mountPoint;
-
- /**
- * @param array $parameters
- */
- public function __construct(
- $parameters
- ) {
- parent::__construct($parameters);
- $this->monitor = $parameters['monitor'];
- $this->mountPoint = $parameters['mountPoint'];
- }
-
- /**
- * see http://php.net/manual/en/function.mkdir.php.
- *
- * @param string $path
- *
- * @return bool
- */
- public function mkdir($path)
- {
- $this->analyze($this, [$path], Monitor::CREATE);
-
- return $this->storage->mkdir($path);
- }
-
- /**
- * see http://php.net/manual/en/function.rmdir.php.
- *
- * @param string $path
- *
- * @return bool
- */
- public function rmdir($path)
- {
- $this->analyze($this, [$path], Monitor::DELETE);
-
- return $this->storage->rmdir($path);
- }
-
- /**
- * see http://php.net/manual/en/function.file_get_contents.php.
- *
- * @param string $path
- *
- * @return string
- */
- public function file_get_contents($path)
- {
- $this->analyze($this, [$path], Monitor::READ);
-
- return $this->storage->file_get_contents($path);
- }
-
- /**
- * see http://php.net/manual/en/function.file_put_contents.php.
- *
- * @param string $path
- * @param string $data
- *
- * @return bool
- */
- public function file_put_contents($path, $data)
- {
- $this->analyze($this, [$path], Monitor::WRITE);
-
- return $this->storage->file_put_contents($path, $data);
- }
-
- /**
- * see http://php.net/manual/en/function.unlink.php.
- *
- * @param string $path
- *
- * @return bool
- */
- public function unlink($path)
- {
- $this->analyze($this, [$path], Monitor::DELETE);
-
- return $this->storage->unlink($path);
- }
-
- /**
- * see http://php.net/manual/en/function.rename.php.
- *
- * @param string $path1
- * @param string $path2
- *
- * @return bool
- */
- public function rename($path1, $path2)
- {
- $this->analyze($this, [$path1, $path2], Monitor::RENAME);
-
- return $this->storage->rename($path1, $path2);
- }
-
- /**
- * see http://php.net/manual/en/function.copy.php.
- *
- * @param string $path1
- * @param string $path2
- *
- * @return bool
- */
- public function copy($path1, $path2)
- {
- $this->analyze($this, [$path1, $path2], Monitor::WRITE);
-
- return $this->storage->copy($path1, $path2);
- }
-
- /**
- * see http://php.net/manual/en/function.fopen.php.
- *
- * @param string $path
- * @param string $mode
- *
- * @return resource
- */
- public function fopen($path, $mode)
- {
- $fileMode = Monitor::READ;
- switch ($mode) {
- case 'r+':
- case 'rb+':
- case 'w+':
- case 'wb+':
- case 'x+':
- case 'xb+':
- case 'a+':
- case 'ab+':
- case 'w':
- case 'wb':
- case 'x':
- case 'xb':
- case 'a':
- case 'ab':
- $fileMode = Monitor::WRITE;
- }
- $this->analyze($this, [$path], $fileMode);
-
- return $this->storage->fopen($path, $mode);
- }
-
- /**
- * see http://php.net/manual/en/function.touch.php
- * If the backend does not support the operation, false should be returned.
- *
- * @param string $path
- * @param int $mtime
- *
- * @return bool
- */
- public function touch($path, $mtime = null)
- {
- $this->analyze($this, [$path], Monitor::WRITE);
-
- return $this->storage->touch($path, $mtime);
- }
-
- /**
- * get a cache instance for the storage.
- *
- * @param string $path
- * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
- *
- * @return \OC\Files\Cache\Cache
- */
- public function getCache($path = '', $storage = null)
- {
- if (!$storage) {
- $storage = $this;
- }
- $cache = $this->storage->getCache($path, $storage);
-
- return new CacheWrapper($cache, $storage, $this->monitor);
- }
-
- /**
- * @param \OCP\Files\Storage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- *
- * @return bool
- */
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath)
- {
- if ($sourceStorage === $this) {
- return $this->copy($sourceInternalPath, $targetInternalPath);
- }
- $this->analyze($this, [$targetInternalPath], Monitor::WRITE);
-
- return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
- }
-
- /**
- * @param \OCP\Files\Storage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- *
- * @return bool
- */
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath)
- {
- if ($sourceStorage === $this) {
- return $this->rename($sourceInternalPath, $targetInternalPath);
- }
- $this->analyze($this, [$targetInternalPath], Monitor::WRITE);
-
- return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
- }
-
- /**
- * Makes it easier to test.
- *
- * @param IStorage $storage
- * @param string $path
- * @param int $mode
- */
- protected function analyze(IStorage $storage, $path, $mode)
- {
- return $this->monitor->analyze($storage, $path, $mode);
- }
-}
diff --git a/tests/Unit/StorageWrapperTest.php b/tests/Unit/StorageWrapperTest.php
deleted file mode 100644
index b3b2f23..0000000
--- a/tests/Unit/StorageWrapperTest.php
+++ /dev/null
@@ -1,203 +0,0 @@
-<?php
-
-/**
- * @copyright Copyright (c) 2017 Matthias Held <matthias.held@uni-konstanz.de>
- * @author Matthias Held <matthias.held@uni-konstanz.de>
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace OCA\RansomwareDetection\tests\Unit;
-
-use OCA\RansomwareDetection\Monitor;
-use Test\TestCase;
-
-class StorageWrapperTest extends TestCase
-{
- /** @var \OCP\Files\Storage\IStorage|\PHPUnit_Framework_MockObject_MockObject */
- protected $storage;
-
- /** @var \OCA\RansomwareDetection\Monitor|\PHPUnit_Framework_MockObject_MockObject */
- protected $monitor;
-
- protected function setUp(): void
- {
- parent::setUp();
-
- $this->storage = $this->getMockBuilder('OCP\Files\Storage\IStorage')
- ->setConstructorArgs([array()])
- ->getMock();
-
- $this->monitor = $this->getMockBuilder('OCA\RansomwareDetection\Monitor')
- ->disableOriginalConstructor()
- ->getMock();
- }
-
- protected function getInstance(array $methods = [])
- {
- return $this->getMockBuilder('OCA\RansomwareDetection\StorageWrapper')
- ->setConstructorArgs([
- [
- 'storage' => $this->storage,
- 'mountPoint' => 'mountPoint',
- 'monitor' => $this->monitor,
- ],
- ])
- ->setMethods($methods)
- ->getMock();
- }
-
- public function dataAnalyze()
- {
- return [
- ['path1', Monitor::READ],
- ['path2', Monitor::WRITE],
- ['path3', Monitor::RENAME],
- ['path4', Monitor::DELETE],
- ];
- }
-
- /**
- * @dataProvider dataAnalyze
- *
- * @param string $path
- * @param int $mode
- */
- public function testAnalyze($path, $mode)
- {
- $storage = $this->getInstance();
-
- $this->monitor->expects($this->once())
- ->method('analyze')
- ->with($storage, $path, $mode);
-
- $this->monitor->analyze($storage, $path, $mode);
- }
-
- public function dataSinglePath()
- {
- $tests = [];
- $tests[] = ['file_get_contents', 'path1', Monitor::READ, true];
- $tests[] = ['file_get_contents', 'path2', Monitor::READ, false];
- $tests[] = ['unlink', 'path1', Monitor::DELETE, true];
- $tests[] = ['unlink', 'path2', Monitor::DELETE, false];
- $tests[] = ['mkdir', 'path1', Monitor::CREATE, true];
- $tests[] = ['mkdir', 'path2', Monitor::CREATE, false];
- $tests[] = ['rmdir', 'path1', Monitor::DELETE, true];
- $tests[] = ['rmdir', 'path2', Monitor::DELETE, false];
-
- return $tests;
- }
-
- /**
- * @dataProvider dataSinglePath
- *
- * @param string $method
- * @param string $path
- * @param int $mode
- * @param bool $return
- */
- public function testSinglePath($method, $path, $mode, $return)
- {
- $storage = $this->getInstance(['analyze']);
-
- $storage->expects($this->once())
- ->method('analyze')
- ->with($storage, [$path], $mode);
-
- $this->storage->expects($this->once())
- ->method($method)
- ->with($path)
- ->willReturn($return);
-
- $this->assertSame($return, $this->invokePrivate($storage, $method, [$path, $mode]));
- }
-
- public function dataDoublePath()
- {
- $tests = [];
- $tests[] = ['rename', 'path1', 'path1', Monitor::RENAME, true];
- $tests[] = ['rename', 'path2', 'path2', Monitor::RENAME, false];
- $tests[] = ['copy', 'path1', 'path1', Monitor::WRITE, true];
- $tests[] = ['copy', 'path2', 'path2', Monitor::WRITE, false];
-
- return $tests;
- }
-
- /**
- * @dataProvider dataDoublePath
- *
- * @param string $method
- * @param string $path1
- * @param string $path2
- * @param int $mode
- * @param bool $return
- */
- public function testDoublePath($method, $path1, $path2, $mode, $return)
- {
- $storage = $this->getInstance(['analyze']);
-
- $storage->expects($this->once())
- ->method('analyze')
- ->with($storage, [$path2, $path1], $mode);
-
- $this->storage->expects($this->once())
- ->method($method)
- ->with($path1, $path2)
- ->willReturn($return);
-
- $this->assertSame($return, $this->invokePrivate($storage, $method, [$path1, $path2, $mode]));
- }
-
- public function dataTwoParameters()
- {
- $tests = [];
- $tests[] = ['file_put_contents', 'path1', 'data', Monitor::WRITE, true];
- $tests[] = ['file_put_contents', 'path1', 'data', Monitor::WRITE, false];
- $tests[] = ['fopen', 'path1', 'z', Monitor::READ, true];
- $tests[] = ['fopen', 'path1', 'z', Monitor::READ, false];
- $tests[] = ['fopen', 'path1', 'x', Monitor::WRITE, true];
- $tests[] = ['fopen', 'path1', 'x', Monitor::WRITE, false];
- $tests[] = ['touch', 'path1', null, Monitor::WRITE, true];
- $tests[] = ['touch', 'path1', null, Monitor::WRITE, false];
-
- return $tests;
- }
-
- /**
- * @dataProvider dataTwoParameters
- *
- * @param string $method
- * @param string $path
- * @param string $param2
- * @param int $mode
- * @param bool $return
- */
- public function testTwoParameters($method, $path, $param2, $mode, $return)
- {
- $storage = $this->getInstance(['analyze']);
-
- $storage->expects($this->once())
- ->method('analyze')
- ->with($storage, [$path], $mode);
-
- $this->storage->expects($this->once())
- ->method($method)
- ->with($path, $param2)
- ->willReturn($return);
-
- $this->assertSame($return, $this->invokePrivate($storage, $method, [$path, $param2, $mode]));
- }
-}