aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-08-20 17:08:18 +0200
committerGitHub <noreply@github.com>2018-08-20 17:08:18 +0200
commit37869d9b2f7bf5e9f3779ccd344114649ce459c1 (patch)
tree336dc41c77bb07406537379339aa8f780f344dc0 /tests
parent080572993e891a76721f4f7a7b76c85bc0e4c65d (diff)
parent3f790bb85b3544680f4af2e3e005d736a5aff8a0 (diff)
downloadnextcloud-server-37869d9b2f7bf5e9f3779ccd344114649ce459c1.tar.gz
nextcloud-server-37869d9b2f7bf5e9f3779ccd344114649ce459c1.zip
Merge pull request #10628 from nextcloud/feature/10154/app-directory-permission-check
Adds a permission check for app directories
Diffstat (limited to 'tests')
-rw-r--r--tests/Settings/Controller/CheckSetupControllerTest.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index 305e2ba22ce..677a2a0aa0b 100644
--- a/tests/Settings/Controller/CheckSetupControllerTest.php
+++ b/tests/Settings/Controller/CheckSetupControllerTest.php
@@ -21,6 +21,7 @@
namespace Tests\Settings\Controller;
+use OC;
use OC\DB\Connection;
use OC\Settings\Controller\CheckSetupController;
use OCP\AppFramework\Http;
@@ -44,6 +45,7 @@ use OC\IntegrityCheck\Checker;
/**
* Class CheckSetupControllerTest
*
+ * @backupStaticAttributes
* @package Tests\Settings\Controller
*/
class CheckSetupControllerTest extends TestCase {
@@ -74,6 +76,13 @@ class CheckSetupControllerTest extends TestCase {
/** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */
private $dateTimeFormatter;
+ /**
+ * Holds a list of directories created during tests.
+ *
+ * @var array
+ */
+ private $dirsToRemove = [];
+
public function setUp() {
parent::setUp();
@@ -135,9 +144,23 @@ class CheckSetupControllerTest extends TestCase {
'isSqliteUsed',
'isPhpMailerUsed',
'hasOpcacheLoaded',
+ 'getAppDirsWithDifferentOwner',
])->getMock();
}
+ /**
+ * Removes directories created during tests.
+ *
+ * @after
+ * @return void
+ */
+ public function removeTestDirectories() {
+ foreach ($this->dirsToRemove as $dirToRemove) {
+ rmdir($dirToRemove);
+ }
+ $this->dirsToRemove = [];
+ }
+
public function testIsInternetConnectionWorkingDisabledViaConfig() {
$this->config->expects($this->once())
->method('getSystemValue')
@@ -425,6 +448,11 @@ class CheckSetupControllerTest extends TestCase {
->method('hasPassedCheck')
->willReturn(true);
+ $this->checkSetupController
+ ->expects($this->once())
+ ->method('getAppDirsWithDifferentOwner')
+ ->willReturn([]);
+
$expected = new DataResponse(
[
'isGetenvServerWorking' => true,
@@ -465,6 +493,7 @@ class CheckSetupControllerTest extends TestCase {
'missingIndexes' => [],
'isPhpMailerUsed' => false,
'mailSettingsDocumentation' => 'https://server/index.php/settings/admin',
+ 'appDirsWithDifferentOwner' => [],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
@@ -571,6 +600,56 @@ class CheckSetupControllerTest extends TestCase {
$this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
}
+ /**
+ * Setups a temp directory and some subdirectories.
+ * Then calls the 'getAppDirsWithDifferentOwner' method.
+ * The result is expected to be empty since
+ * there are no directories with different owners than the current user.
+ *
+ * @return void
+ */
+ public function testAppDirectoryOwnersOk() {
+ $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
+ mkdir($tempDir);
+ mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
+ mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
+ $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
+ $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
+ $this->dirsToRemove[] = $tempDir;
+ OC::$APPSROOTS = [
+ [
+ 'path' => $tempDir,
+ 'url' => '/apps',
+ 'writable' => true,
+ ],
+ ];
+ $this->assertSame(
+ [],
+ $this->invokePrivate($this->checkSetupController, 'getAppDirsWithDifferentOwner')
+ );
+ }
+
+ /**
+ * Calls the check for a none existing app root that is marked as not writable.
+ * It's expected that no error happens since the check shouldn't apply.
+ *
+ * @return void
+ */
+ public function testAppDirectoryOwnersNotWritable() {
+ $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
+ OC::$APPSROOTS = [
+ [
+ 'path' => $tempDir,
+ 'url' => '/apps',
+ 'writable' => false,
+ ],
+ ];
+ $this->assertSame(
+ [],
+ $this->invokePrivate($this->checkSetupController, 'getAppDirsWithDifferentOwner')
+ );
+ }
+
public function testIsBuggyNss400() {
$this->config->expects($this->any())
->method('getSystemValue')