diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-01-08 13:17:36 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-01-08 13:17:36 +0100 |
commit | f642ad39614970de67358d80517bc1d76a006e0e (patch) | |
tree | 3606c38d2a8404307a03cb494e89e55c8206c293 /tests | |
parent | bb443ae937bdbc9f50c352d34abeaa0eaa3fa890 (diff) | |
download | nextcloud-server-f642ad39614970de67358d80517bc1d76a006e0e.tar.gz nextcloud-server-f642ad39614970de67358d80517bc1d76a006e0e.zip |
Prevent deleting storage root
Storage mount points are not deletable, so make sure that the unlink
operation and its hooks aren't run in such cases.
Note that some storages might recursively delete their contents when
calling unlink on their root. This fix prevents that as well.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/view.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index b59cef9f0da..76a7fd5f1ca 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -309,6 +309,48 @@ class View extends \PHPUnit_Framework_TestCase { /** * @medium */ + function testUnlink() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); + + $rootView = new \OC\Files\View(''); + $rootView->file_put_contents('/foo.txt', 'asd'); + $rootView->file_put_contents('/substorage/bar.txt', 'asd'); + + $this->assertTrue($rootView->file_exists('foo.txt')); + $this->assertTrue($rootView->file_exists('substorage/bar.txt')); + + $this->assertTrue($rootView->unlink('foo.txt')); + $this->assertTrue($rootView->unlink('substorage/bar.txt')); + + $this->assertFalse($rootView->file_exists('foo.txt')); + $this->assertFalse($rootView->file_exists('substorage/bar.txt')); + } + + /** + * @medium + */ + function testUnlinkRootMustFail() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); + + $rootView = new \OC\Files\View(''); + $rootView->file_put_contents('/foo.txt', 'asd'); + $rootView->file_put_contents('/substorage/bar.txt', 'asd'); + + $this->assertFalse($rootView->unlink('')); + $this->assertFalse($rootView->unlink('/')); + $this->assertFalse($rootView->unlink('substorage')); + $this->assertFalse($rootView->unlink('/substorage')); + } + + /** + * @medium + */ function testTouch() { $storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch'); |