summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-08-09 19:48:19 +0200
committerMichael Weimann <mail@michael-weimann.eu>2018-08-09 19:48:19 +0200
commit0017cbe18ab5242a721faa4b28e27b85f911a52b (patch)
treec2a09f26ba524f41fff872f461000dd04456c0b6 /tests
parentb2e60e365dde53e405cb4a1fe9be687d33ec08ef (diff)
downloadnextcloud-server-0017cbe18ab5242a721faa4b28e27b85f911a52b.tar.gz
nextcloud-server-0017cbe18ab5242a721faa4b28e27b85f911a52b.zip
Adds a test for the app directory permission check.
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'tests')
-rw-r--r--tests/Settings/Controller/CheckSetupControllerTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index 305e2ba22ce..5bed7e322eb 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,35 @@ 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')
+ );
+ }
+
public function testIsBuggyNss400() {
$this->config->expects($this->any())
->method('getSystemValue')