Skip to content

Commit

Permalink
Adds a test for the app directory permission check.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
  • Loading branch information
weeman1337 committed Aug 4, 2018
1 parent dba75ad commit f33bdd1
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/Settings/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Tests\Settings\Controller;

use OC;
use OC\DB\Connection;
use OC\Settings\Controller\CheckSetupController;
use OCP\AppFramework\Http;
Expand All @@ -44,6 +45,7 @@
/**
* Class CheckSetupControllerTest
*
* @backupStaticAttributes
* @package Tests\Settings\Controller
*/
class CheckSetupControllerTest extends TestCase {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -135,9 +144,23 @@ public function setUp() {
'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')
Expand Down Expand Up @@ -425,6 +448,11 @@ public function testCheck() {
->method('hasPassedCheck')
->willReturn(true);

$this->checkSetupController
->expects($this->once())
->method('getAppDirsWithDifferentOwner')
->willReturn([]);

$expected = new DataResponse(
[
'isGetenvServerWorking' => true,
Expand Down Expand Up @@ -465,6 +493,7 @@ public function testCheck() {
'missingIndexes' => [],
'isPhpMailerUsed' => false,
'mailSettingsDocumentation' => 'https://server/index.php/settings/admin',
'appDirsWithDifferentOwner' => [],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
Expand Down Expand Up @@ -571,6 +600,35 @@ public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion1() {
$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')
Expand Down

0 comments on commit f33bdd1

Please sign in to comment.