diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-19 11:17:01 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-19 11:18:25 +0200 |
commit | c58d174616213f0e569a28f6cb026d8807516b2b (patch) | |
tree | 3b49551538ed2a402994f044f2df32da7a3d6c2f /tests/Settings | |
parent | 392bc0c6b9967d3e33570ada51a391159d4d69aa (diff) | |
download | nextcloud-server-c58d174616213f0e569a28f6cb026d8807516b2b.tar.gz nextcloud-server-c58d174616213f0e569a28f6cb026d8807516b2b.zip |
Move tests/settings to PSR-4
Diffstat (limited to 'tests/Settings')
-rw-r--r-- | tests/Settings/Controller/AppSettingsControllerTest.php | 293 | ||||
-rw-r--r-- | tests/Settings/Controller/CertificateControllerTest.php | 190 | ||||
-rw-r--r-- | tests/Settings/Controller/CheckSetupControllerTest.php | 1063 | ||||
-rw-r--r-- | tests/Settings/Controller/EncryptionControllerTest.php | 155 | ||||
-rw-r--r-- | tests/Settings/Controller/GroupsControllerTest.php | 342 | ||||
-rw-r--r-- | tests/Settings/Controller/LogSettingsControllerTest.php | 75 | ||||
-rw-r--r-- | tests/Settings/Controller/MailSettingsControllerTest.php | 205 | ||||
-rw-r--r-- | tests/Settings/Controller/SecuritySettingsControllerTest.php | 68 | ||||
-rw-r--r-- | tests/Settings/Controller/UsersControllerTest.php | 2032 | ||||
-rw-r--r-- | tests/Settings/Middleware/SubadminMiddlewareTest.php | 99 |
10 files changed, 4522 insertions, 0 deletions
diff --git a/tests/Settings/Controller/AppSettingsControllerTest.php b/tests/Settings/Controller/AppSettingsControllerTest.php new file mode 100644 index 00000000000..9dcc55e135b --- /dev/null +++ b/tests/Settings/Controller/AppSettingsControllerTest.php @@ -0,0 +1,293 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Tests\Settings\Controller; + +use OC\Settings\Controller\AppSettingsController; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\TemplateResponse; +use Test\TestCase; +use OCP\IRequest; +use OCP\IL10N; +use OCP\IConfig; +use OCP\ICache; +use OCP\INavigationManager; +use OCP\App\IAppManager; +use OC\OCSClient; + +/** + * Class AppSettingsControllerTest + * + * @package Tests\Settings\Controller + */ +class AppSettingsControllerTest extends TestCase { + /** @var AppSettingsController */ + private $appSettingsController; + /** @var IRequest */ + private $request; + /** @var IL10N */ + private $l10n; + /** @var IConfig */ + private $config; + /** @var ICache */ + private $cache; + /** @var INavigationManager */ + private $navigationManager; + /** @var IAppManager */ + private $appManager; + /** @var OCSClient */ + private $ocsClient; + + public function setUp() { + parent::setUp(); + + $this->request = $this->getMockBuilder('\OCP\IRequest') + ->disableOriginalConstructor()->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->l10n->expects($this->any()) + ->method('t') + ->will($this->returnArgument(0)); + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $cacheFactory = $this->getMockBuilder('\OCP\ICacheFactory') + ->disableOriginalConstructor()->getMock(); + $this->cache = $this->getMockBuilder('\OCP\ICache') + ->disableOriginalConstructor()->getMock(); + $cacheFactory + ->expects($this->once()) + ->method('create') + ->with('settings') + ->will($this->returnValue($this->cache)); + + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager') + ->disableOriginalConstructor()->getMock(); + $this->appManager = $this->getMockBuilder('\OCP\App\IAppManager') + ->disableOriginalConstructor()->getMock(); + $this->ocsClient = $this->getMockBuilder('\OC\OCSClient') + ->disableOriginalConstructor()->getMock(); + + $this->appSettingsController = new AppSettingsController( + 'settings', + $this->request, + $this->l10n, + $this->config, + $cacheFactory, + $this->navigationManager, + $this->appManager, + $this->ocsClient + ); + } + + public function testChangeExperimentalConfigStateTrue() { + $this->config + ->expects($this->once()) + ->method('setSystemValue') + ->with('appstore.experimental.enabled', true); + $this->appManager + ->expects($this->once()) + ->method('clearAppsCache'); + $this->assertEquals(new DataResponse(), $this->appSettingsController->changeExperimentalConfigState(true)); + } + + public function testChangeExperimentalConfigStateFalse() { + $this->config + ->expects($this->once()) + ->method('setSystemValue') + ->with('appstore.experimental.enabled', false); + $this->appManager + ->expects($this->once()) + ->method('clearAppsCache'); + $this->assertEquals(new DataResponse(), $this->appSettingsController->changeExperimentalConfigState(false)); + } + + public function testListCategoriesCached() { + $this->cache + ->expects($this->exactly(2)) + ->method('get') + ->with('listCategories') + ->will($this->returnValue(['CachedArray'])); + $this->assertSame(['CachedArray'], $this->appSettingsController->listCategories()); + } + + public function testListCategoriesNotCachedWithoutAppStore() { + $expected = [ + [ + 'id' => 0, + 'ident' => 'enabled', + 'displayName' => 'Enabled', + ], + [ + 'id' => 1, + 'ident' => 'disabled', + 'displayName' => 'Not enabled', + ], + ]; + $this->cache + ->expects($this->once()) + ->method('get') + ->with('listCategories') + ->will($this->returnValue(null)); + $this->cache + ->expects($this->once()) + ->method('set') + ->with('listCategories', $expected, 3600); + + + $this->assertSame($expected, $this->appSettingsController->listCategories()); + } + + public function testListCategoriesNotCachedWithAppStore() { + $expected = [ + [ + 'id' => 0, + 'ident' => 'enabled', + 'displayName' => 'Enabled', + ], + [ + 'id' => 1, + 'ident' => 'disabled', + 'displayName' => 'Not enabled', + ], + [ + 'id' => 0, + 'ident' => 'tools', + 'displayName' => 'Tools', + ], + [ + 'id' => 1, + 'ident' => 'games', + 'displayName' => 'Games', + ], + [ + 'id' => 2, + 'ident' => 'productivity', + 'displayName' => 'Productivity', + ], + [ + 'id' => 3, + 'ident' => 'multimedia', + 'displayName' => 'Multimedia', + ], + ]; + + $this->cache + ->expects($this->once()) + ->method('get') + ->with('listCategories') + ->will($this->returnValue(null)); + $this->cache + ->expects($this->once()) + ->method('set') + ->with('listCategories', $expected, 3600); + + $this->ocsClient + ->expects($this->once()) + ->method('isAppStoreEnabled') + ->will($this->returnValue(true)); + $this->ocsClient + ->expects($this->once()) + ->method('getCategories') + ->will($this->returnValue( + [ + 'ownCloud Tools', + 'Games', + 'ownCloud Productivity', + 'Multimedia', + ] + )); + + $this->assertSame($expected, $this->appSettingsController->listCategories()); + } + + public function testViewApps() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('appstore.experimental.enabled', false); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('appstoreenabled', true) + ->will($this->returnValue(true)); + $this->navigationManager + ->expects($this->once()) + ->method('setActiveEntry') + ->with('core_apps'); + + $policy = new ContentSecurityPolicy(); + $policy->addAllowedImageDomain('https://apps.owncloud.com'); + + $expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 'enabled', 'appstoreEnabled' => true], 'user'); + $expected->setContentSecurityPolicy($policy); + + $this->assertEquals($expected, $this->appSettingsController->viewApps()); + } + + public function testViewAppsNotEnabled() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('appstore.experimental.enabled', false); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('appstoreenabled', true) + ->will($this->returnValue(true)); + $this->navigationManager + ->expects($this->once()) + ->method('setActiveEntry') + ->with('core_apps'); + + $policy = new ContentSecurityPolicy(); + $policy->addAllowedImageDomain('https://apps.owncloud.com'); + + $expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 'disabled', 'appstoreEnabled' => true], 'user'); + $expected->setContentSecurityPolicy($policy); + + $this->assertEquals($expected, $this->appSettingsController->viewApps('disabled')); + } + + public function testViewAppsAppstoreNotEnabled() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('appstore.experimental.enabled', false); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('appstoreenabled', true) + ->will($this->returnValue(false)); + $this->navigationManager + ->expects($this->once()) + ->method('setActiveEntry') + ->with('core_apps'); + + $policy = new ContentSecurityPolicy(); + $policy->addAllowedImageDomain('https://apps.owncloud.com'); + + $expected = new TemplateResponse('settings', 'apps', ['experimentalEnabled' => false, 'category' => 'enabled', 'appstoreEnabled' => false], 'user'); + $expected->setContentSecurityPolicy($policy); + + $this->assertEquals($expected, $this->appSettingsController->viewApps()); + } +} diff --git a/tests/Settings/Controller/CertificateControllerTest.php b/tests/Settings/Controller/CertificateControllerTest.php new file mode 100644 index 00000000000..c9ea2a4024f --- /dev/null +++ b/tests/Settings/Controller/CertificateControllerTest.php @@ -0,0 +1,190 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Tests\Settings\Controller; + +use OC\Settings\Controller\CertificateController; +use OCP\App\IAppManager; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; +use OCP\IL10N; +use OCP\ICertificateManager; + +/** + * Class CertificateControllerTest + * + * @package Tests\Settings\Controller + */ +class CertificateControllerTest extends \Test\TestCase { + /** @var CertificateController */ + private $certificateController; + /** @var IRequest */ + private $request; + /** @var ICertificateManager */ + private $certificateManager; + /** @var IL10N */ + private $l10n; + /** @var IAppManager */ + private $appManager; + /** @var ICertificateManager */ + private $systemCertificateManager; + + public function setUp() { + parent::setUp(); + + $this->request = $this->getMock('\OCP\IRequest'); + $this->certificateManager = $this->getMock('\OCP\ICertificateManager'); + $this->systemCertificateManager = $this->getMock('\OCP\ICertificateManager'); + $this->l10n = $this->getMock('\OCP\IL10N'); + $this->appManager = $this->getMock('OCP\App\IAppManager'); + + $this->certificateController = $this->getMockBuilder('OC\Settings\Controller\CertificateController') + ->setConstructorArgs( + [ + 'settings', + $this->request, + $this->certificateManager, + $this->systemCertificateManager, + $this->l10n, + $this->appManager + ] + )->setMethods(['isCertificateImportAllowed'])->getMock(); + + $this->certificateController->expects($this->any()) + ->method('isCertificateImportAllowed')->willReturn(true); + } + + public function testAddPersonalRootCertificateWithEmptyFile() { + $this->request + ->expects($this->once()) + ->method('getUploadedFile') + ->with('rootcert_import') + ->will($this->returnValue(null)); + + $expected = new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate()); + } + + public function testAddPersonalRootCertificateValidCertificate() { + $uploadedFile = [ + 'tmp_name' => __DIR__ . '/../../data/certificates/goodCertificate.crt', + 'name' => 'goodCertificate.crt', + ]; + + $certificate = $this->getMock('\OCP\ICertificate'); + $certificate + ->expects($this->once()) + ->method('getName') + ->will($this->returnValue('Name')); + $certificate + ->expects($this->once()) + ->method('getCommonName') + ->will($this->returnValue('CommonName')); + $certificate + ->expects($this->once()) + ->method('getOrganization') + ->will($this->returnValue('Organization')); + $certificate + ->expects($this->exactly(2)) + ->method('getIssueDate') + ->will($this->returnValue(new \DateTime('@1429099555'))); + $certificate + ->expects($this->exactly(2)) + ->method('getExpireDate') + ->will($this->returnValue(new \DateTime('@1529099555'))); + $certificate + ->expects($this->once()) + ->method('getIssuerName') + ->will($this->returnValue('Issuer')); + $certificate + ->expects($this->once()) + ->method('getIssuerOrganization') + ->will($this->returnValue('IssuerOrganization')); + + $this->request + ->expects($this->once()) + ->method('getUploadedFile') + ->with('rootcert_import') + ->will($this->returnValue($uploadedFile)); + $this->certificateManager + ->expects($this->once()) + ->method('addCertificate') + ->with(file_get_contents($uploadedFile['tmp_name'], 'goodCertificate.crt')) + ->will($this->returnValue($certificate)); + + $this->l10n + ->expects($this->at(0)) + ->method('l') + ->with('date', new \DateTime('@1429099555')) + ->will($this->returnValue('Valid From as String')); + $this->l10n + ->expects($this->at(1)) + ->method('l') + ->with('date', new \DateTime('@1529099555')) + ->will($this->returnValue('Valid Till as String')); + + + $expected = new DataResponse([ + 'name' => 'Name', + 'commonName' => 'CommonName', + 'organization' => 'Organization', + 'validFrom' => 1429099555, + 'validTill' => 1529099555, + 'validFromString' => 'Valid From as String', + 'validTillString' => 'Valid Till as String', + 'issuer' => 'Issuer', + 'issuerOrganization' => 'IssuerOrganization', + ]); + $this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate()); + } + + public function testAddPersonalRootCertificateInvalidCertificate() { + $uploadedFile = [ + 'tmp_name' => __DIR__ . '/../../data/certificates/badCertificate.crt', + 'name' => 'badCertificate.crt', + ]; + + $this->request + ->expects($this->once()) + ->method('getUploadedFile') + ->with('rootcert_import') + ->will($this->returnValue($uploadedFile)); + $this->certificateManager + ->expects($this->once()) + ->method('addCertificate') + ->with(file_get_contents($uploadedFile['tmp_name'], 'badCertificate.crt')) + ->will($this->throwException(new \Exception())); + + $expected = new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate()); + } + + public function testRemoveCertificate() { + $this->certificateManager + ->expects($this->once()) + ->method('removeCertificate') + ->with('CertificateToRemove'); + + $this->assertEquals(new DataResponse(), $this->certificateController->removePersonalRootCertificate('CertificateToRemove')); + } + +} diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php new file mode 100644 index 00000000000..f48e9c04f3d --- /dev/null +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -0,0 +1,1063 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Tests\Settings\Controller; + +use OC\Settings\Controller\CheckSetupController; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataDisplayResponse; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\Http\Client\IClientService; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IRequest; +use OCP\IURLGenerator; +use OC_Util; +use Test\TestCase; +use OC\IntegrityCheck\Checker; + +/** + * Mock version_compare + * @param string $version1 + * @param string $version2 + * @return int + */ +function version_compare($version1, $version2) { + return CheckSetupControllerTest::$version_compare; +} + +/** + * Class CheckSetupControllerTest + * + * @package Tests\Settings\Controller + */ +class CheckSetupControllerTest extends TestCase { + /** @var int */ + public static $version_compare; + + /** @var CheckSetupController */ + private $checkSetupController; + /** @var IRequest */ + private $request; + /** @var IConfig */ + private $config; + /** @var IClientService */ + private $clientService; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var OC_Util */ + private $util; + /** @var IL10N */ + private $l10n; + /** @var Checker */ + private $checker; + + public function setUp() { + parent::setUp(); + + $this->request = $this->getMockBuilder('\OCP\IRequest') + ->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService') + ->disableOriginalConstructor()->getMock(); + $this->util = $this->getMockBuilder('\OC_Util') + ->disableOriginalConstructor()->getMock(); + $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') + ->disableOriginalConstructor()->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->l10n->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($message, array $replace) { + return vsprintf($message, $replace); + })); + $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') + ->disableOriginalConstructor()->getMock(); + $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') + ->setConstructorArgs([ + 'settings', + $this->request, + $this->config, + $this->clientService, + $this->urlGenerator, + $this->util, + $this->l10n, + $this->checker, + ]) + ->setMethods(['getCurlVersion'])->getMock(); + } + + public function testIsInternetConnectionWorkingDisabledViaConfig() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(false)); + + $this->assertFalse( + self::invokePrivate( + $this->checkSetupController, + 'isInternetConnectionWorking' + ) + ); + } + + public function testIsInternetConnectionWorkingCorrectly() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []); + $client->expects($this->at(1)) + ->method('get') + ->with('http://www.owncloud.org/', []); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + + $this->assertTrue( + self::invokePrivate( + $this->checkSetupController, + 'isInternetConnectionWorking' + ) + ); + } + + public function testIsInternetConnectionHttpsFail() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []) + ->will($this->throwException(new \Exception())); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + $this->assertFalse( + self::invokePrivate( + $this->checkSetupController, + 'isInternetConnectionWorking' + ) + ); + } + + public function testIsInternetConnectionHttpFail() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []); + $client->expects($this->at(1)) + ->method('get') + ->with('http://www.owncloud.org/', []) + ->will($this->throwException(new \Exception())); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + $this->assertFalse( + self::invokePrivate( + $this->checkSetupController, + 'isInternetConnectionWorking' + ) + ); + } + + public function testIsMemcacheConfiguredFalse() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('memcache.local', null) + ->will($this->returnValue(null)); + + $this->assertFalse( + self::invokePrivate( + $this->checkSetupController, + 'isMemcacheConfigured' + ) + ); + } + + public function testIsMemcacheConfiguredTrue() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('memcache.local', null) + ->will($this->returnValue('SomeProvider')); + + $this->assertTrue( + self::invokePrivate( + $this->checkSetupController, + 'isMemcacheConfigured' + ) + ); + } + + public function testIsPhpSupportedFalse() { + self::$version_compare = -1; + + $this->assertEquals( + ['eol' => true, 'version' => PHP_VERSION], + self::invokePrivate($this->checkSetupController, 'isPhpSupported') + ); + } + + public function testIsPhpSupportedTrue() { + self::$version_compare = 0; + + $this->assertEquals( + ['eol' => false, 'version' => PHP_VERSION], + self::invokePrivate($this->checkSetupController, 'isPhpSupported') + ); + + + self::$version_compare = 1; + + $this->assertEquals( + ['eol' => false, 'version' => PHP_VERSION], + self::invokePrivate($this->checkSetupController, 'isPhpSupported') + ); + } + + public function testForwardedForHeadersWorkingFalse() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('trusted_proxies', []) + ->willReturn(['1.2.3.4']); + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn('1.2.3.4'); + + $this->assertFalse( + self::invokePrivate( + $this->checkSetupController, + 'forwardedForHeadersWorking' + ) + ); + } + + public function testForwardedForHeadersWorkingTrue() { + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('trusted_proxies', []) + ->willReturn(['1.2.3.4']); + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn('4.3.2.1'); + + $this->assertTrue( + self::invokePrivate( + $this->checkSetupController, + 'forwardedForHeadersWorking' + ) + ); + } + + public function testCheck() { + $this->config->expects($this->at(0)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + $this->config->expects($this->at(1)) + ->method('getSystemValue') + ->with('memcache.local', null) + ->will($this->returnValue('SomeProvider')); + $this->config->expects($this->at(2)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(false)); + $this->config->expects($this->at(3)) + ->method('getSystemValue') + ->with('trusted_proxies', []) + ->willReturn(['1.2.3.4']); + + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn('4.3.2.1'); + + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []); + $client->expects($this->at(1)) + ->method('get') + ->with('http://www.owncloud.org/', []) + ->will($this->throwException(new \Exception())); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + $this->urlGenerator->expects($this->at(0)) + ->method('linkToDocs') + ->with('admin-performance') + ->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance'); + $this->urlGenerator->expects($this->at(1)) + ->method('linkToDocs') + ->with('admin-security') + ->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html'); + self::$version_compare = -1; + $this->urlGenerator->expects($this->at(2)) + ->method('linkToDocs') + ->with('admin-reverse-proxy') + ->willReturn('reverse-proxy-doc-link'); + + $expected = new DataResponse( + [ + 'serverHasInternetConnection' => false, + 'isMemcacheConfigured' => true, + 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance', + 'isUrandomAvailable' => self::invokePrivate($this->checkSetupController, 'isUrandomAvailable'), + 'securityDocs' => 'https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html', + 'isUsedTlsLibOutdated' => '', + 'phpSupported' => [ + 'eol' => true, + 'version' => PHP_VERSION + ], + 'forwardedForHeadersWorking' => true, + 'reverseProxyDocs' => 'reverse-proxy-doc-link', + 'isCorrectMemcachedPHPModuleInstalled' => true, + 'hasPassedCodeIntegrityCheck' => null, + 'codeIntegrityCheckerDocumentation' => null, + ] + ); + $this->assertEquals($expected, $this->checkSetupController->check()); + } + + public function testGetCurlVersion() { + $checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') + ->setConstructorArgs([ + 'settings', + $this->request, + $this->config, + $this->clientService, + $this->urlGenerator, + $this->util, + $this->l10n, + $this->checker + ]) + ->setMethods(null)->getMock(); + + $this->assertArrayHasKey('ssl_version', $this->invokePrivate($checkSetupController, 'getCurlVersion')); + } + + public function testIsUsedTlsLibOutdatedWithAnotherLibrary() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'SSLlib'])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithMisbehavingCurl() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue([])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithOlderOpenSsl() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1c'])); + $this->assertSame('cURL is using an outdated OpenSSL version (OpenSSL/1.0.1c). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithOlderOpenSslAndWithoutAppstore() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1c'])); + $this->assertSame('cURL is using an outdated OpenSSL version (OpenSSL/1.0.1c). Please update your operating system or features such as Federated Cloud Sharing will not work reliably.', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithOlderOpenSsl1() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.2a'])); + $this->assertSame('cURL is using an outdated OpenSSL version (OpenSSL/1.0.2a). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1d'])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion1() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.2b'])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsBuggyNss400() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b'])); + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException') + ->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface') + ->disableOriginalConstructor()->getMock(); + $response->expects($this->once()) + ->method('getStatusCode') + ->will($this->returnValue(400)); + $exception->expects($this->once()) + ->method('getResponse') + ->will($this->returnValue($response)); + + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []) + ->will($this->throwException($exception)); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + $this->assertSame('cURL is using an outdated NSS version (NSS/1.0.2b). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + + public function testIsBuggyNss200() { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnValue(true)); + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b'])); + $client = $this->getMockBuilder('\OCP\Http\Client\IClient') + ->disableOriginalConstructor()->getMock(); + $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException') + ->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface') + ->disableOriginalConstructor()->getMock(); + $response->expects($this->once()) + ->method('getStatusCode') + ->will($this->returnValue(200)); + $exception->expects($this->once()) + ->method('getResponse') + ->will($this->returnValue($response)); + + $client->expects($this->at(0)) + ->method('get') + ->with('https://www.owncloud.org/', []) + ->will($this->throwException($exception)); + + $this->clientService->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithInternetDisabled() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(false)); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingEnabled() { + // Appstore is disabled by default in EE + $appStoreDefault = false; + if (\OC_Util::getEditionString() === '') { + $appStoreDefault = true; + } + + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('appstoreenabled', $appStoreDefault) + ->will($this->returnValue(false)); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes') + ->will($this->returnValue('no')); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes') + ->will($this->returnValue('yes')); + + $this->checkSetupController + ->expects($this->once()) + ->method('getCurlVersion') + ->will($this->returnValue([])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingDisabled() { + // Appstore is disabled by default in EE + $appStoreDefault = false; + if (\OC_Util::getEditionString() === '') { + $appStoreDefault = true; + } + + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->will($this->returnValue(true)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('appstoreenabled', $appStoreDefault) + ->will($this->returnValue(false)); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes') + ->will($this->returnValue('no')); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes') + ->will($this->returnValue('no')); + + $this->checkSetupController + ->expects($this->never()) + ->method('getCurlVersion') + ->will($this->returnValue([])); + $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); + } + + public function testRescanFailedIntegrityCheck() { + $this->checker + ->expects($this->once()) + ->method('runInstanceVerification'); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRoute') + ->with('settings_admin') + ->will($this->returnValue('/admin')); + + $expected = new RedirectResponse('/admin'); + $this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck()); + } + + public function testGetFailedIntegrityCheckDisabled() { + $this->checker + ->expects($this->once()) + ->method('isCodeCheckEnforced') + ->willReturn(false); + + $expected = new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.'); + $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles()); + } + + + public function testGetFailedIntegrityCheckFilesWithNoErrorsFound() { + $this->checker + ->expects($this->once()) + ->method('isCodeCheckEnforced') + ->willReturn(true); + $this->checker + ->expects($this->once()) + ->method('getResults') + ->will($this->returnValue([])); + + $expected = new DataDisplayResponse( + 'No errors have been found.', + Http::STATUS_OK, + [ + 'Content-Type' => 'text/plain', + ] + ); + $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles()); + } + + public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() { + $this->checker + ->expects($this->once()) + ->method('isCodeCheckEnforced') + ->willReturn(true); + $this->checker + ->expects($this->once()) + ->method('getResults') + ->will($this->returnValue(array ( 'core' => array ( 'EXTRA_FILE' => array('/testfile' => array()), 'INVALID_HASH' => array ( '/.idea/workspace.xml' => array ( 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ), '/lib/private/integritycheck/checker.php' => array ( 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ), '/settings/controller/checksetupcontroller.php' => array ( 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ), ), ), 'bookmarks' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'dav' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'encryption' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'external' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'federation' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_antivirus' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_drop' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_external' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_pdfviewer' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_sharing' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_trashbin' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_versions' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_videoviewer' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'firstrunwizard' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'gitsmart' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'logreader' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ), ), 'password_policy' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'provisioning_api' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'sketch' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'threatblock' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'two_factor_auth' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'user_ldap' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'user_shibboleth' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), ))); + + $expected = new DataDisplayResponse( + 'Technical information +===================== +The following list covers which files have failed the integrity check. Please read +the previous linked documentation to learn more about the errors and how to fix +them. + +Results +======= +- core + - EXTRA_FILE + - /testfile + - INVALID_HASH + - /.idea/workspace.xml + - /lib/private/integritycheck/checker.php + - /settings/controller/checksetupcontroller.php +- bookmarks + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- dav + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- encryption + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- external + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- federation + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_antivirus + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_drop + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_external + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_pdfviewer + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_sharing + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_trashbin + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_versions + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- files_videoviewer + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- firstrunwizard + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- gitsmart + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- logreader + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature could not get verified. +- password_policy + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- provisioning_api + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- sketch + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- threatblock + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- two_factor_auth + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- user_ldap + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. +- user_shibboleth + - EXCEPTION + - OC\IntegrityCheck\Exceptions\InvalidSignatureException + - Signature data not found. + +Raw output +========== +Array +( + [core] => Array + ( + [EXTRA_FILE] => Array + ( + [/testfile] => Array + ( + ) + + ) + + [INVALID_HASH] => Array + ( + [/.idea/workspace.xml] => Array + ( + [expected] => f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216 + [current] => ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094 + ) + + [/lib/private/integritycheck/checker.php] => Array + ( + [expected] => c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea + [current] => 88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585 + ) + + [/settings/controller/checksetupcontroller.php] => Array + ( + [expected] => 3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4 + [current] => 09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a + ) + + ) + + ) + + [bookmarks] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [dav] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [encryption] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [external] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [federation] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_antivirus] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_drop] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_external] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_pdfviewer] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_sharing] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_trashbin] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_versions] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [files_videoviewer] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [firstrunwizard] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [gitsmart] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [logreader] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature could not get verified. + ) + + ) + + [password_policy] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [provisioning_api] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [sketch] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [threatblock] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [two_factor_auth] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [user_ldap] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + + [user_shibboleth] => Array + ( + [EXCEPTION] => Array + ( + [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException + [message] => Signature data not found. + ) + + ) + +) +', + Http::STATUS_OK, + [ + 'Content-Type' => 'text/plain', + ] + ); + $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles()); + } +} diff --git a/tests/Settings/Controller/EncryptionControllerTest.php b/tests/Settings/Controller/EncryptionControllerTest.php new file mode 100644 index 00000000000..adbbe2cf6a4 --- /dev/null +++ b/tests/Settings/Controller/EncryptionControllerTest.php @@ -0,0 +1,155 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Tests\Settings\Controller; + +use OC\DB\Connection; +use OC\Files\View; +use OC\Settings\Controller\EncryptionController; +use OCP\IConfig; +use OCP\IL10N; +use OCP\ILogger; +use OCP\IRequest; +use OCP\IUserManager; +use Test\TestCase; + +/** + * Class EncryptionControllerTest + * + * @package Tests\Settings\Controller + */ +class EncryptionControllerTest extends TestCase { + /** @var IRequest */ + private $request; + /** @var IL10N */ + private $l10n; + /** @var IConfig */ + private $config; + /** @var Connection */ + private $connection; + /** @var IUserManager */ + private $userManager; + /** @var View */ + private $view; + /** @var ILogger */ + private $logger; + /** @var EncryptionController */ + private $encryptionController; + + public function setUp() { + $this->request = $this->getMockBuilder('\\OCP\\IRequest') + ->disableOriginalConstructor()->getMock(); + $this->l10n = $this->getMockBuilder('\\OCP\\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->l10n->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($message, array $replace) { + return vsprintf($message, $replace); + })); + $this->config = $this->getMockBuilder('\\OCP\\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->connection = $this->getMockBuilder('\\OC\\DB\\Connection') + ->disableOriginalConstructor()->getMock(); + $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager') + ->disableOriginalConstructor()->getMock(); + $this->view = $this->getMockBuilder('\\OC\\Files\\View') + ->disableOriginalConstructor()->getMock(); + $this->logger = $this->getMockBuilder('\\OCP\\ILogger') + ->disableOriginalConstructor()->getMock(); + + $this->encryptionController = $this->getMockBuilder('\\OC\\Settings\\Controller\\EncryptionController') + ->setConstructorArgs([ + 'settings', + $this->request, + $this->l10n, + $this->config, + $this->connection, + $this->userManager, + $this->view, + $this->logger, + ]) + ->setMethods(['getMigration']) + ->getMock(); + } + + public function testStartMigrationSuccessful() { + // we need to be able to autoload the class we're mocking + \OC_App::registerAutoloading('encryption', \OC_App::getAppPath('encryption')); + + $migration = $this->getMockBuilder('\\OCA\\Encryption\\Migration') + ->disableOriginalConstructor()->getMock(); + $this->encryptionController + ->expects($this->once()) + ->method('getMigration') + ->with($this->config, $this->view, $this->connection, $this->logger) + ->will($this->returnValue($migration)); + $migration + ->expects($this->once()) + ->method('reorganizeSystemFolderStructure'); + $migration + ->expects($this->once()) + ->method('updateDB'); + $backend = $this->getMockBuilder('\OCP\UserInterface') + ->getMock(); + $this->userManager + ->expects($this->once()) + ->method('getBackends') + ->will($this->returnValue([$backend])); + $backend + ->expects($this->once()) + ->method('getUsers') + ->will($this->returnValue(['User 1', 'User 2'])); + $migration + ->expects($this->exactly(2)) + ->method('reorganizeFolderStructureForUser') + ->withConsecutive( + ['User 1'], + ['User 2'] + ); + $migration + ->expects($this->once()) + ->method('finalCleanUp'); + + $expected = [ + 'data' => [ + 'message' => 'Migration Completed', + ], + 'status' => 'success', + ]; + $this->assertSame($expected, $this->encryptionController->startMigration()); + } + + public function testStartMigrationException() { + $this->encryptionController + ->expects($this->once()) + ->method('getMigration') + ->with($this->config, $this->view, $this->connection, $this->logger) + ->will($this->throwException(new \Exception('My error message'))); + + $expected = [ + 'data' => [ + 'message' => 'A problem occurred, please check your log files (Error: My error message)', + ], + 'status' => 'error', + ]; + $this->assertSame($expected, $this->encryptionController->startMigration()); + } +} diff --git a/tests/Settings/Controller/GroupsControllerTest.php b/tests/Settings/Controller/GroupsControllerTest.php new file mode 100644 index 00000000000..70cb8282b26 --- /dev/null +++ b/tests/Settings/Controller/GroupsControllerTest.php @@ -0,0 +1,342 @@ +<?php +/** + * @author Lukas Reschke + * @copyright 2014 Lukas Reschke lukas@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Tests\Settings\Controller; + +use OC\Group\Group; +use OC\Group\MetaData; +use \OC\Settings\Application; +use OC\Settings\Controller\GroupsController; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; + +/** + * @package Tests\Settings\Controller + */ +class GroupsControllerTest extends \Test\TestCase { + + /** @var \OCP\AppFramework\IAppContainer */ + private $container; + + /** @var GroupsController */ + private $groupsController; + + protected function setUp() { + $app = new Application(); + $this->container = $app->getContainer(); + $this->container['AppName'] = 'settings'; + $this->container['GroupManager'] = $this->getMockBuilder('\OCP\IGroupManager') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') + ->disableOriginalConstructor()->getMock(); + $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->container['IsAdmin'] = true; + $this->container['L10N'] + ->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters = array()) { + return vsprintf($text, $parameters); + })); + $this->groupsController = $this->container['GroupsController']; + + } + + /** + * TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked + * to test for subadmins. Thus the test always assumes you have admin permissions... + */ + public function testIndexSortByName() { + $firstGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $firstGroup + ->method('getGID') + ->will($this->returnValue('firstGroup')); + $firstGroup + ->method('count') + ->will($this->returnValue(12)); + $secondGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $secondGroup + ->method('getGID') + ->will($this->returnValue('secondGroup')); + $secondGroup + ->method('count') + ->will($this->returnValue(25)); + $thirdGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $thirdGroup + ->method('getGID') + ->will($this->returnValue('thirdGroup')); + $thirdGroup + ->method('count') + ->will($this->returnValue(14)); + $fourthGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $fourthGroup + ->method('getGID') + ->will($this->returnValue('admin')); + $fourthGroup + ->method('count') + ->will($this->returnValue(18)); + /** @var \OC\Group\Group[] $groups */ + $groups = array(); + $groups[] = $firstGroup; + $groups[] = $secondGroup; + $groups[] = $thirdGroup; + $groups[] = $fourthGroup; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('MyAdminUser')); + $this->container['GroupManager'] + ->method('search') + ->will($this->returnValue($groups)); + + $expectedResponse = new DataResponse( + array( + 'data' => array( + 'adminGroups' => array( + 0 => array( + 'id' => 'admin', + 'name' => 'admin', + 'usercount' => 0,//User count disabled 18, + ) + ), + 'groups' => + array( + 0 => array( + 'id' => 'firstGroup', + 'name' => 'firstGroup', + 'usercount' => 0,//User count disabled 12, + ), + 1 => array( + 'id' => 'secondGroup', + 'name' => 'secondGroup', + 'usercount' => 0,//User count disabled 25, + ), + 2 => array( + 'id' => 'thirdGroup', + 'name' => 'thirdGroup', + 'usercount' => 0,//User count disabled 14, + ), + ) + ) + ) + ); + $response = $this->groupsController->index('', false, MetaData::SORT_GROUPNAME); + $this->assertEquals($expectedResponse, $response); + } + + /** + * TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked + * to test for subadmins. Thus the test always assumes you have admin permissions... + */ + public function testIndexSortbyCount() { + $firstGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $firstGroup + ->method('getGID') + ->will($this->returnValue('firstGroup')); + $firstGroup + ->method('count') + ->will($this->returnValue(12)); + $secondGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $secondGroup + ->method('getGID') + ->will($this->returnValue('secondGroup')); + $secondGroup + ->method('count') + ->will($this->returnValue(25)); + $thirdGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $thirdGroup + ->method('getGID') + ->will($this->returnValue('thirdGroup')); + $thirdGroup + ->method('count') + ->will($this->returnValue(14)); + $fourthGroup = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $fourthGroup + ->method('getGID') + ->will($this->returnValue('admin')); + $fourthGroup + ->method('count') + ->will($this->returnValue(18)); + /** @var \OC\Group\Group[] $groups */ + $groups = array(); + $groups[] = $firstGroup; + $groups[] = $secondGroup; + $groups[] = $thirdGroup; + $groups[] = $fourthGroup; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('MyAdminUser')); + $this->container['GroupManager'] + ->method('search') + ->will($this->returnValue($groups)); + + $expectedResponse = new DataResponse( + array( + 'data' => array( + 'adminGroups' => array( + 0 => array( + 'id' => 'admin', + 'name' => 'admin', + 'usercount' => 18, + ) + ), + 'groups' => + array( + 0 => array( + 'id' => 'secondGroup', + 'name' => 'secondGroup', + 'usercount' => 25, + ), + 1 => array( + 'id' => 'thirdGroup', + 'name' => 'thirdGroup', + 'usercount' => 14, + ), + 2 => array( + 'id' => 'firstGroup', + 'name' => 'firstGroup', + 'usercount' => 12, + ), + ) + ) + ) + ); + $response = $this->groupsController->index(); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateWithExistingGroup() { + $this->container['GroupManager'] + ->expects($this->once()) + ->method('groupExists') + ->with('ExistingGroup') + ->will($this->returnValue(true)); + + $expectedResponse = new DataResponse( + array( + 'message' => 'Group already exists.' + ), + Http::STATUS_CONFLICT + ); + $response = $this->groupsController->create('ExistingGroup'); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateSuccessful() { + $this->container['GroupManager'] + ->expects($this->once()) + ->method('groupExists') + ->with('NewGroup') + ->will($this->returnValue(false)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('createGroup') + ->with('NewGroup') + ->will($this->returnValue(true)); + + $expectedResponse = new DataResponse( + array( + 'groupname' => 'NewGroup' + ), + Http::STATUS_CREATED + ); + $response = $this->groupsController->create('NewGroup'); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateUnsuccessful() { + $this->container['GroupManager'] + ->expects($this->once()) + ->method('groupExists') + ->with('NewGroup') + ->will($this->returnValue(false)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('createGroup') + ->with('NewGroup') + ->will($this->returnValue(false)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'error', + 'data' => array('message' => 'Unable to add group.') + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->groupsController->create('NewGroup'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroySuccessful() { + $group = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('get') + ->with('ExistingGroup') + ->will($this->returnValue($group)); + $group + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue(true)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'success', + 'data' => array('groupname' => 'ExistingGroup') + ), + Http::STATUS_NO_CONTENT + ); + $response = $this->groupsController->destroy('ExistingGroup'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroyUnsuccessful() { + $this->container['GroupManager'] + ->expects($this->once()) + ->method('get') + ->with('ExistingGroup') + ->will($this->returnValue(null)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'error', + 'data' => array('message' => 'Unable to delete group.') + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->groupsController->destroy('ExistingGroup'); + $this->assertEquals($expectedResponse, $response); + } + +} diff --git a/tests/Settings/Controller/LogSettingsControllerTest.php b/tests/Settings/Controller/LogSettingsControllerTest.php new file mode 100644 index 00000000000..092c04aecc7 --- /dev/null +++ b/tests/Settings/Controller/LogSettingsControllerTest.php @@ -0,0 +1,75 @@ +<?php +/** + * @author Georg Ehrke + * @copyright 2014 Georg Ehrke <georg@ownCloud.com> + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Tests\Settings\Controller; + +use \OC\Settings\Application; +use OC\Settings\Controller\LogSettingsController; + +/** + * @package Tests\Settings\Controller + */ +class LogSettingsControllerTest extends \Test\TestCase { + + /** @var \OCP\AppFramework\IAppContainer */ + private $container; + + /** @var LogSettingsController */ + private $logSettingsController; + + protected function setUp() { + $app = new Application(); + $this->container = $app->getContainer(); + $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->container['AppName'] = 'settings'; + $this->logSettingsController = $this->container['LogSettingsController']; + } + + /** + * @dataProvider logLevelData + */ + public function testSetLogLevel($level, $inRange) { + if ($inRange) { + $this->container['Config'] + ->expects($this->once()) + ->method('setSystemValue') + ->with('loglevel', $level); + } + + $response = $this->logSettingsController->setLogLevel($level)->getData(); + + if ($inRange) { + $expectedResponse = ['level' => $level]; + } else { + $expectedResponse = ['message' => 'log-level out of allowed range']; + } + + $this->assertSame($expectedResponse, $response); + } + + public function logLevelData() { + return [ + [-1, false], + [0, true], + [1, true], + [2, true], + [3, true], + [4, true], + [5, false], + ]; + } + + public function testDownload() { + $response = $this->logSettingsController->download(); + + $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response); + } +} diff --git a/tests/Settings/Controller/MailSettingsControllerTest.php b/tests/Settings/Controller/MailSettingsControllerTest.php new file mode 100644 index 00000000000..1ac6bae69ea --- /dev/null +++ b/tests/Settings/Controller/MailSettingsControllerTest.php @@ -0,0 +1,205 @@ +<?php +/** + * @author Lukas Reschke + * @copyright 2014 Lukas Reschke lukas@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Tests\Settings\Controller; + +use OC\Settings\Application; + +/** + * @package Tests\Settings\Controller + */ +class MailSettingsControllerTest extends \Test\TestCase { + + private $container; + + protected function setUp() { + parent::setUp(); + + $app = new Application(); + $this->container = $app->getContainer(); + $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->container['AppName'] = 'settings'; + $this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') + ->disableOriginalConstructor()->getMock(); + $this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage') + ->disableOriginalConstructor()->getMock(); + $this->container['Mailer'] = $this->getMockBuilder('\OC\Mail\Mailer') + ->setMethods(['send']) + ->disableOriginalConstructor()->getMock(); + $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') + ->disableOriginalConstructor()->getMock(); + $this->container['DefaultMailAddress'] = 'no-reply@owncloud.com'; + } + + public function testSetMailSettings() { + $this->container['L10N'] + ->expects($this->exactly(2)) + ->method('t') + ->will($this->returnValue('Saved')); + + /** + * FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1 + */ + /* + $this->container['Config'] + ->expects($this->exactly(15)) + ->method('setSystemValue') + ->withConsecutive( + array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')), + array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')), + array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')), + array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')), + array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')), + array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')), + array($this->equalTo('mail_smtpauth'), $this->equalTo(1)), + array($this->equalTo('mail_smtpport'), $this->equalTo('25')), + array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')), + array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')), + array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')), + array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')), + array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')), + array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')), + array($this->equalTo('mail_smtpport'), $this->equalTo('25')) + ); + */ + + /** @var \PHPUnit_Framework_MockObject_MockObject $config */ + $config = $this->container['Config']; + $config->expects($this->exactly(2)) + ->method('setSystemValues'); + /** + * FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1 + ->withConsecutive( + [[ + 'mail_domain' => 'owncloud.com', + 'mail_from_address' => 'demo@owncloud.com', + 'mail_smtpmode' => 'smtp', + 'mail_smtpsecure' => 'ssl', + 'mail_smtphost' => 'mx.owncloud.org', + 'mail_smtpauthtype' => 'NTLM', + 'mail_smtpauth' => 1, + 'mail_smtpport' => '25', + ]], + [[ + 'mail_domain' => 'owncloud.com', + 'mail_from_address' => 'demo@owncloud.com', + 'mail_smtpmode' => 'smtp', + 'mail_smtpsecure' => 'ssl', + 'mail_smtphost' => 'mx.owncloud.org', + 'mail_smtpauthtype' => 'NTLM', + 'mail_smtpauth' => null, + 'mail_smtpport' => '25', + 'mail_smtpname' => null, + 'mail_smtppassword' => null, + ]] + ); + */ + + // With authentication + $response = $this->container['MailSettingsController']->setMailSettings( + 'owncloud.com', + 'demo@owncloud.com', + 'smtp', + 'ssl', + 'mx.owncloud.org', + 'NTLM', + 1, + '25' + ); + $expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success'); + $this->assertSame($expectedResponse, $response); + + // Without authentication (testing the deletion of the stored password) + $response = $this->container['MailSettingsController']->setMailSettings( + 'owncloud.com', + 'demo@owncloud.com', + 'smtp', + 'ssl', + 'mx.owncloud.org', + 'NTLM', + 0, + '25' + ); + $expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success'); + $this->assertSame($expectedResponse, $response); + + } + + public function testStoreCredentials() { + $this->container['L10N'] + ->expects($this->once()) + ->method('t') + ->will($this->returnValue('Saved')); + + $this->container['Config'] + ->expects($this->once()) + ->method('setSystemValues') + ->with([ + 'mail_smtpname' => 'UsernameToStore', + 'mail_smtppassword' => 'PasswordToStore', + ]); + + $response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore'); + $expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success'); + + $this->assertSame($expectedResponse, $response); + } + + public function testSendTestMail() { + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor() + ->getMock(); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('Werner')); + $user->expects($this->any()) + ->method('getDisplayName') + ->will($this->returnValue('Werner Brösel')); + + $this->container['L10N'] + ->expects($this->any()) + ->method('t') + ->will( + $this->returnValueMap( + array( + array('You need to set your user email before being able to send test emails.', array(), + 'You need to set your user email before being able to send test emails.'), + array('A problem occurred while sending the e-mail. Please revisit your settings.', array(), + 'A problem occurred while sending the e-mail. Please revisit your settings.'), + array('Email sent', array(), 'Email sent'), + array('test email settings', array(), 'test email settings'), + array('If you received this email, the settings seem to be correct.', array(), + 'If you received this email, the settings seem to be correct.') + ) + )); + $this->container['UserSession'] + ->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($user)); + + // Ensure that it fails when no mail address has been specified + $response = $this->container['MailSettingsController']->sendTestMail(); + $expectedResponse = array('data' => array('message' =>'You need to set your user email before being able to send test emails.'), 'status' => 'error'); + $this->assertSame($expectedResponse, $response); + + // If no exception is thrown it should work + $this->container['Config'] + ->expects($this->any()) + ->method('getUserValue') + ->will($this->returnValue('mail@example.invalid')); + $response = $this->container['MailSettingsController']->sendTestMail(); + $expectedResponse = array('data' => array('message' =>'Email sent'), 'status' => 'success'); + $this->assertSame($expectedResponse, $response); + } + +} diff --git a/tests/Settings/Controller/SecuritySettingsControllerTest.php b/tests/Settings/Controller/SecuritySettingsControllerTest.php new file mode 100644 index 00000000000..11b0edcae23 --- /dev/null +++ b/tests/Settings/Controller/SecuritySettingsControllerTest.php @@ -0,0 +1,68 @@ +<?php +/** + * @author Lukas Reschke + * @copyright 2014 Lukas Reschke lukas@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace Tests\Settings\Controller; + +use \OC\Settings\Application; +use OC\Settings\Controller\SecuritySettingsController; + +/** + * @package Tests\Settings\Controller + */ +class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase { + + /** @var \OCP\AppFramework\IAppContainer */ + private $container; + + /** @var SecuritySettingsController */ + private $securitySettingsController; + + protected function setUp() { + $app = new Application(); + $this->container = $app->getContainer(); + $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->container['AppName'] = 'settings'; + $this->securitySettingsController = $this->container['SecuritySettingsController']; + } + + public function testTrustedDomainsWithExistingValues() { + $this->container['Config'] + ->expects($this->once()) + ->method('setSystemValue') + ->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com')); + $this->container['Config'] + ->expects($this->once()) + ->method('getSystemValue') + ->with('trusted_domains') + ->will($this->returnValue(array('owncloud.org', 'owncloud.com'))); + + $response = $this->securitySettingsController->trustedDomains('newdomain.com'); + $expectedResponse = array('status' => 'success'); + + $this->assertSame($expectedResponse, $response); + } + + public function testTrustedDomainsEmpty() { + $this->container['Config'] + ->expects($this->once()) + ->method('setSystemValue') + ->with('trusted_domains', array('newdomain.com')); + $this->container['Config'] + ->expects($this->once()) + ->method('getSystemValue') + ->with('trusted_domains') + ->will($this->returnValue('')); + + $response = $this->securitySettingsController->trustedDomains('newdomain.com'); + $expectedResponse = array('status' => 'success'); + + $this->assertSame($expectedResponse, $response); + } +} diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php new file mode 100644 index 00000000000..244d1f744d3 --- /dev/null +++ b/tests/Settings/Controller/UsersControllerTest.php @@ -0,0 +1,2032 @@ +<?php +/** + * @author Lukas Reschke + * @copyright 2014-2015 Lukas Reschke lukas@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Tests\Settings\Controller; + +use \OC\Settings\Application; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; + +/** + * @group DB + * + * @package Tests\Settings\Controller + */ +class UsersControllerTest extends \Test\TestCase { + + /** @var \OCP\AppFramework\IAppContainer */ + private $container; + + protected function setUp() { + $app = new Application(); + $this->container = $app->getContainer(); + $this->container['AppName'] = 'settings'; + $this->container['GroupManager'] = $this->getMockBuilder('\OC\Group\Manager') + ->disableOriginalConstructor()->getMock(); + $this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') + ->disableOriginalConstructor()->getMock(); + $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->container['L10N'] + ->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters = array()) { + return vsprintf($text, $parameters); + })); + $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') + ->disableOriginalConstructor()->getMock(); + $this->container['Mailer'] = $this->getMockBuilder('\OCP\Mail\IMailer') + ->disableOriginalConstructor()->getMock(); + $this->container['DefaultMailAddress'] = 'no-reply@owncloud.com'; + $this->container['Logger'] = $this->getMockBuilder('\OCP\ILogger') + ->disableOriginalConstructor()->getMock(); + $this->container['URLGenerator'] = $this->getMockBuilder('\OCP\IURLGenerator') + ->disableOriginalConstructor()->getMock(); + $this->container['OCP\\App\\IAppManager'] = $this->getMockBuilder('OCP\\App\\IAppManager') + ->disableOriginalConstructor()->getMock(); + + + /* + * Set default avtar behaviour for whole testsuite + */ + $this->container['OCP\\IAvatarManager'] = $this->getMock('OCP\IAvatarManager'); + + $avatarExists = $this->getMock('OCP\IAvatar'); + $avatarExists->method('exists')->willReturn(true); + $avatarNotExists = $this->getMock('OCP\IAvatar'); + $avatarNotExists->method('exists')->willReturn(false); + $this->container['OCP\\IAvatarManager'] + ->method('getAvatar') + ->will($this->returnValueMap([ + ['foo', $avatarExists], + ['bar', $avatarExists], + ['admin', $avatarNotExists], + ])); + + $this->container['Config'] + ->method('getSystemValue') + ->with('enable_avatars', true) + ->willReturn(true); + + } + + public function testIndexAdmin() { + $this->container['IsAdmin'] = true; + + $foo = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $foo + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('foo')); + $foo + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('M. Foo')); + $foo + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('foo@bar.com')); + $foo + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('1024')); + $foo + ->method('getLastLogin') + ->will($this->returnValue(500)); + $foo + ->method('getHome') + ->will($this->returnValue('/home/foo')); + $foo + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('OC_User_Database')); + $admin = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $admin + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('admin')); + $admin + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('S. Admin')); + $admin + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('admin@bar.com')); + $admin + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('404')); + $admin + ->expects($this->once()) + ->method('getLastLogin') + ->will($this->returnValue(12)); + $admin + ->expects($this->once()) + ->method('getHome') + ->will($this->returnValue('/home/admin')); + $admin + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + $bar = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $bar + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('bar')); + $bar + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('B. Ar')); + $bar + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('bar@dummy.com')); + $bar + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('2323')); + $bar + ->method('getLastLogin') + ->will($this->returnValue(3999)); + $bar + ->method('getHome') + ->will($this->returnValue('/home/bar')); + $bar + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + + $this->container['GroupManager'] + ->expects($this->once()) + ->method('displayNamesInGroup') + ->with('gid', 'pattern') + ->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar'))); + $this->container['GroupManager'] + ->expects($this->exactly(3)) + ->method('getUserGroupIds') + ->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); + $this->container['UserManager'] + ->expects($this->at(0)) + ->method('get') + ->with('foo') + ->will($this->returnValue($foo)); + $this->container['UserManager'] + ->expects($this->at(1)) + ->method('get') + ->with('admin') + ->will($this->returnValue($admin)); + $this->container['UserManager'] + ->expects($this->at(2)) + ->method('get') + ->with('bar') + ->will($this->returnValue($bar)); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->any()) + ->method('getSubAdminsGroups') + ->with($foo) + ->will($this->returnValue([])); + $subadmin + ->expects($this->any()) + ->method('getSubAdminsGroups') + ->with($admin) + ->will($this->returnValue([])); + $subadmin + ->expects($this->any()) + ->method('getSubAdminsGroups') + ->with($bar) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 0 => array( + 'name' => 'foo', + 'displayname' => 'M. Foo', + 'groups' => array('Users', 'Support'), + 'subadmin' => array(), + 'quota' => 1024, + 'storageLocation' => '/home/foo', + 'lastLogin' => 500000, + 'backend' => 'OC_User_Database', + 'email' => 'foo@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + 1 => array( + 'name' => 'admin', + 'displayname' => 'S. Admin', + 'groups' => array('admins', 'Support'), + 'subadmin' => array(), + 'quota' => 404, + 'storageLocation' => '/home/admin', + 'lastLogin' => 12000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'admin@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => false, + ), + 2 => array( + 'name' => 'bar', + 'displayname' => 'B. Ar', + 'groups' => array('External Users'), + 'subadmin' => array(), + 'quota' => 2323, + 'storageLocation' => '/home/bar', + 'lastLogin' => 3999000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'bar@dummy.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + ) + ); + $response = $this->container['UsersController']->index(0, 10, 'gid', 'pattern'); + $this->assertEquals($expectedResponse, $response); + } + + public function testIndexSubAdmin() { + $this->container['IsAdmin'] = false; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + + $foo = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $foo + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('foo')); + $foo + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('M. Foo')); + $foo + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('foo@bar.com')); + $foo + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('1024')); + $foo + ->method('getLastLogin') + ->will($this->returnValue(500)); + $foo + ->method('getHome') + ->will($this->returnValue('/home/foo')); + $foo + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('OC_User_Database')); + $admin = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $admin + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('admin')); + $admin + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('S. Admin')); + $admin + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('admin@bar.com')); + $admin + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('404')); + $admin + ->expects($this->once()) + ->method('getLastLogin') + ->will($this->returnValue(12)); + $admin + ->expects($this->once()) + ->method('getHome') + ->will($this->returnValue('/home/admin')); + $admin + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + $bar = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $bar + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('bar')); + $bar + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('B. Ar')); + $bar + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('bar@dummy.com')); + $bar + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('2323')); + $bar + ->method('getLastLogin') + ->will($this->returnValue(3999)); + $bar + ->method('getHome') + ->will($this->returnValue('/home/bar')); + $bar + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + + $this->container['GroupManager'] + ->expects($this->at(2)) + ->method('displayNamesInGroup') + ->with('SubGroup2', 'pattern') + ->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin'])); + $this->container['GroupManager'] + ->expects($this->at(1)) + ->method('displayNamesInGroup') + ->with('SubGroup1', 'pattern') + ->will($this->returnValue(['bar' => 'B. Ar'])); + $this->container['GroupManager'] + ->expects($this->exactly(3)) + ->method('getUserGroupIds') + ->will($this->onConsecutiveCalls( + ['admin', 'SubGroup1', 'testGroup'], + ['SubGroup2', 'SubGroup1'], + ['SubGroup2', 'Foo'] + )); + $this->container['UserManager'] + ->expects($this->at(0)) + ->method('get') + ->with('bar') + ->will($this->returnValue($bar)); + $this->container['UserManager'] + ->expects($this->at(1)) + ->method('get') + ->with('foo') + ->will($this->returnValue($foo)); + $this->container['UserManager'] + ->expects($this->at(2)) + ->method('get') + ->with('admin') + ->will($this->returnValue($admin)); + + $subgroup1 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor() + ->getMock(); + $subgroup1->expects($this->any()) + ->method('getGID') + ->will($this->returnValue('SubGroup1')); + $subgroup2 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor() + ->getMock(); + $subgroup2->expects($this->any()) + ->method('getGID') + ->will($this->returnValue('SubGroup2')); + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->at(0)) + ->method('getSubAdminsGroups') + ->will($this->returnValue([$subgroup1, $subgroup2])); + $subadmin + ->expects($this->any()) + ->method('getSubAdminsGroups') + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 0 => [ + 'name' => 'bar', + 'displayname' => 'B. Ar', + 'groups' => ['SubGroup1'], + 'subadmin' => [], + 'quota' => 2323, + 'storageLocation' => '/home/bar', + 'lastLogin' => 3999000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'bar@dummy.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ], + 1=> [ + 'name' => 'foo', + 'displayname' => 'M. Foo', + 'groups' => ['SubGroup2', 'SubGroup1'], + 'subadmin' => [], + 'quota' => 1024, + 'storageLocation' => '/home/foo', + 'lastLogin' => 500000, + 'backend' => 'OC_User_Database', + 'email' => 'foo@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ], + 2 => [ + 'name' => 'admin', + 'displayname' => 'S. Admin', + 'groups' => ['SubGroup2'], + 'subadmin' => [], + 'quota' => 404, + 'storageLocation' => '/home/admin', + 'lastLogin' => 12000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'admin@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => false, + ], + ] + ); + + $response = $this->container['UsersController']->index(0, 10, '', 'pattern'); + $this->assertEquals($expectedResponse, $response); + } + + /** + * TODO: Since the function uses the static OC_Subadmin class it can't be mocked + * to test for subadmins. Thus the test always assumes you have admin permissions... + */ + public function testIndexWithSearch() { + $this->container['IsAdmin'] = true; + + $foo = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $foo + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('foo')); + $foo + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('M. Foo')); + $foo + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('foo@bar.com')); + $foo + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('1024')); + $foo + ->method('getLastLogin') + ->will($this->returnValue(500)); + $foo + ->method('getHome') + ->will($this->returnValue('/home/foo')); + $foo + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('OC_User_Database')); + $admin = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $admin + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('admin')); + $admin + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('S. Admin')); + $admin + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('admin@bar.com')); + $admin + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('404')); + $admin + ->expects($this->once()) + ->method('getLastLogin') + ->will($this->returnValue(12)); + $admin + ->expects($this->once()) + ->method('getHome') + ->will($this->returnValue('/home/admin')); + $admin + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + $bar = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $bar + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('bar')); + $bar + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('B. Ar')); + $bar + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue('bar@dummy.com')); + $bar + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('2323')); + $bar + ->method('getLastLogin') + ->will($this->returnValue(3999)); + $bar + ->method('getHome') + ->will($this->returnValue('/home/bar')); + $bar + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('\Test\Util\User\Dummy')); + + $this->container['UserManager'] + ->expects($this->once()) + ->method('search') + ->with('pattern', 10, 0) + ->will($this->returnValue([$foo, $admin, $bar])); + $this->container['GroupManager'] + ->expects($this->exactly(3)) + ->method('getUserGroupIds') + ->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->any()) + ->method('getSubAdminsGroups') + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 0 => array( + 'name' => 'foo', + 'displayname' => 'M. Foo', + 'groups' => array('Users', 'Support'), + 'subadmin' => array(), + 'quota' => 1024, + 'storageLocation' => '/home/foo', + 'lastLogin' => 500000, + 'backend' => 'OC_User_Database', + 'email' => 'foo@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + 1 => array( + 'name' => 'admin', + 'displayname' => 'S. Admin', + 'groups' => array('admins', 'Support'), + 'subadmin' => array(), + 'quota' => 404, + 'storageLocation' => '/home/admin', + 'lastLogin' => 12000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'admin@bar.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => false, + ), + 2 => array( + 'name' => 'bar', + 'displayname' => 'B. Ar', + 'groups' => array('External Users'), + 'subadmin' => array(), + 'quota' => 2323, + 'storageLocation' => '/home/bar', + 'lastLogin' => 3999000, + 'backend' => '\Test\Util\User\Dummy', + 'email' => 'bar@dummy.com', + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + ) + ); + $response = $this->container['UsersController']->index(0, 10, '', 'pattern'); + $this->assertEquals($expectedResponse, $response); + } + + public function testIndexWithBackend() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->exactly(2)) + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('M. Foo')); + $user + ->expects($this->once()) + ->method('getEMailAddress') + ->will($this->returnValue(null)); + $user + ->expects($this->once()) + ->method('getQuota') + ->will($this->returnValue('none')); + $user + ->method('getLastLogin') + ->will($this->returnValue(500)); + $user + ->method('getHome') + ->will($this->returnValue('/home/foo')); + $user + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('OC_User_Database')); + $this->container['UserManager'] + ->expects($this->once()) + ->method('getBackends') + ->will($this->returnValue([new \Test\Util\User\Dummy(), new \OC\User\Database()])); + $this->container['UserManager'] + ->expects($this->once()) + ->method('clearBackends'); + $this->container['UserManager'] + ->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue([$user])); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 0 => array( + 'name' => 'foo', + 'displayname' => 'M. Foo', + 'groups' => null, + 'subadmin' => array(), + 'quota' => 'none', + 'storageLocation' => '/home/foo', + 'lastLogin' => 500000, + 'backend' => 'OC_User_Database', + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ) + ) + ); + $response = $this->container['UsersController']->index(0, 10, '','', '\Test\Util\User\Dummy'); + $this->assertEquals($expectedResponse, $response); + } + + public function testIndexWithBackendNoUser() { + $this->container['IsAdmin'] = true; + + $this->container['UserManager'] + ->expects($this->once()) + ->method('getBackends') + ->will($this->returnValue([new \Test\Util\User\Dummy(), new \OC\User\Database()])); + $this->container['UserManager'] + ->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue([])); + + $expectedResponse = new DataResponse([]); + $response = $this->container['UsersController']->index(0, 10, '','', '\Test\Util\User\Dummy'); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateSuccessfulWithoutGroupAdmin() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + + $this->container['UserManager'] + ->expects($this->once()) + ->method('createUser') + ->will($this->onConsecutiveCalls($user)); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->any()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 'name' => 'foo', + 'groups' => null, + 'storageLocation' => '/home/user', + 'backend' => 'bar', + 'lastLogin' => null, + 'displayname' => null, + 'quota' => null, + 'subadmin' => array(), + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + Http::STATUS_CREATED + ); + $response = $this->container['UsersController']->create('foo', 'password', array()); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateSuccessfulWithoutGroupSubAdmin() { + $this->container['IsAdmin'] = false; + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + + $newUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $newUser + ->method('getUID') + ->will($this->returnValue('foo')); + $newUser + ->method('getHome') + ->will($this->returnValue('/home/user')); + $newUser + ->method('getHome') + ->will($this->returnValue('/home/user')); + $newUser + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $subGroup1 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $subGroup1 + ->expects($this->once()) + ->method('addUser') + ->with($newUser); + $subGroup2 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $subGroup2 + ->expects($this->once()) + ->method('addUser') + ->with($newUser); + + $this->container['UserManager'] + ->expects($this->once()) + ->method('createUser') + ->will($this->returnValue($newUser)); + $this->container['GroupManager'] + ->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls($subGroup1, $subGroup2)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->onConsecutiveCalls(['SubGroup1', 'SubGroup2'])); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->at(0)) + ->method('getSubAdminsGroups') + ->will($this->returnValue([$subGroup1, $subGroup2])); + $subadmin + ->expects($this->at(1)) + ->method('getSubAdminsGroups') + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 'name' => 'foo', + 'groups' => ['SubGroup1', 'SubGroup2'], + 'storageLocation' => '/home/user', + 'backend' => 'bar', + 'lastLogin' => 0, + 'displayname' => null, + 'quota' => null, + 'subadmin' => [], + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + Http::STATUS_CREATED + ); + $response = $this->container['UsersController']->create('foo', 'password'); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateSuccessfulWithGroupAdmin() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + $existingGroup = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $existingGroup + ->expects($this->once()) + ->method('addUser') + ->with($user); + $newGroup = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $newGroup + ->expects($this->once()) + ->method('addUser') + ->with($user); + + $this->container['UserManager'] + ->expects($this->once()) + ->method('createUser') + ->will($this->onConsecutiveCalls($user)); + $this->container['GroupManager'] + ->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls(null, $existingGroup)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('createGroup') + ->with('NewGroup') + ->will($this->onConsecutiveCalls($newGroup)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup'))); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 'name' => 'foo', + 'groups' => array('NewGroup', 'ExistingGroup'), + 'storageLocation' => '/home/user', + 'backend' => 'bar', + 'lastLogin' => null, + 'displayname' => null, + 'quota' => null, + 'subadmin' => array(), + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + Http::STATUS_CREATED + ); + $response = $this->container['UsersController']->create('foo', 'password', array('NewGroup', 'ExistingGroup')); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateSuccessfulWithGroupSubAdmin() { + $this->container['IsAdmin'] = false; + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $newUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $newUser + ->method('getHome') + ->will($this->returnValue('/home/user')); + $newUser + ->method('getHome') + ->will($this->returnValue('/home/user')); + $newUser + ->method('getUID') + ->will($this->returnValue('foo')); + $newUser + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + $subGroup1 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $subGroup1 + ->expects($this->any()) + ->method('getGID') + ->will($this->returnValue('SubGroup1')); + $subGroup1 + ->expects($this->once()) + ->method('addUser') + ->with($user); + $this->container['UserManager'] + ->expects($this->once()) + ->method('createUser') + ->will($this->returnValue($newUser)); + $this->container['GroupManager'] + ->expects($this->at(0)) + ->method('get') + ->with('SubGroup1') + ->will($this->returnValue($subGroup1)); + $this->container['GroupManager'] + ->expects($this->at(4)) + ->method('get') + ->with('SubGroup1') + ->will($this->returnValue($subGroup1)); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->onConsecutiveCalls(['SubGroup1'])); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('getUserGroupIds') + ->with($newUser) + ->will($this->onConsecutiveCalls(['SubGroup1'])); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->at(1)) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([$subGroup1])); + $subadmin->expects($this->at(2)) + ->method('getSubAdminsGroups') + ->with($newUser) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + array( + 'name' => 'foo', + 'groups' => ['SubGroup1'], + 'storageLocation' => '/home/user', + 'backend' => 'bar', + 'lastLogin' => 0, + 'displayname' => null, + 'quota' => null, + 'subadmin' => [], + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ), + Http::STATUS_CREATED + ); + $response = $this->container['UsersController']->create('foo', 'password', ['SubGroup1', 'ExistingGroup']); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateUnsuccessfulAdmin() { + $this->container['IsAdmin'] = true; + + $this->container['UserManager'] + ->method('createUser') + ->will($this->throwException(new \Exception())); + + $expectedResponse = new DataResponse( + array( + 'message' => 'Unable to create user.' + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->create('foo', 'password', array()); + $this->assertEquals($expectedResponse, $response); + } + + public function testCreateUnsuccessfulSubAdmin() { + $this->container['IsAdmin'] = false; + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('username')); + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + + $this->container['UserManager'] + ->method('createUser') + ->will($this->throwException(new \Exception())); + + $subgroup1 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor() + ->getMock(); + $subgroup1->expects($this->once()) + ->method('getGID') + ->will($this->returnValue('SubGroup1')); + $subgroup2 = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor() + ->getMock(); + $subgroup2->expects($this->once()) + ->method('getGID') + ->will($this->returnValue('SubGroup2')); + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([$subgroup1, $subgroup2])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 'message' => 'Unable to create user.' + ], + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->create('foo', 'password', array()); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroySelfAdmin() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('myself')); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'error', + 'data' => array( + 'message' => 'Unable to delete user.' + ) + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->destroy('myself'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroySelfSubadmin() { + $this->container['IsAdmin'] = false; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('myself')); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'error', + 'data' => array( + 'message' => 'Unable to delete user.' + ) + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->destroy('myself'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroyAdmin() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('Admin')); + $toDeleteUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $toDeleteUser + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue(true)); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['UserManager'] + ->method('get') + ->with('UserToDelete') + ->will($this->returnValue($toDeleteUser)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'success', + 'data' => array( + 'username' => 'UserToDelete' + ) + ), + Http::STATUS_NO_CONTENT + ); + $response = $this->container['UsersController']->destroy('UserToDelete'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroySubAdmin() { + $this->container['IsAdmin'] = false; + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('myself')); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $toDeleteUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $toDeleteUser + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue(true)); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['UserManager'] + ->method('get') + ->with('UserToDelete') + ->will($this->returnValue($toDeleteUser)); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('isUserAccessible') + ->with($user, $toDeleteUser) + ->will($this->returnValue(true)); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 'status' => 'success', + 'data' => [ + 'username' => 'UserToDelete' + ] + ], + Http::STATUS_NO_CONTENT + ); + $response = $this->container['UsersController']->destroy('UserToDelete'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroyUnsuccessfulAdmin() { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('Admin')); + $toDeleteUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $toDeleteUser + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue(false)); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['UserManager'] + ->method('get') + ->with('UserToDelete') + ->will($this->returnValue($toDeleteUser)); + + $expectedResponse = new DataResponse( + array( + 'status' => 'error', + 'data' => array( + 'message' => 'Unable to delete user.' + ) + ), + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->destroy('UserToDelete'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroyUnsuccessfulSubAdmin() { + $this->container['IsAdmin'] = false; + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('myself')); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + + $toDeleteUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $toDeleteUser + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue(false)); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['UserManager'] + ->method('get') + ->with('UserToDelete') + ->will($this->returnValue($toDeleteUser)); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('isUserAccessible') + ->with($user, $toDeleteUser) + ->will($this->returnValue(true)); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 'status' => 'error', + 'data' => [ + 'message' => 'Unable to delete user.' + ] + ], + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->destroy('UserToDelete'); + $this->assertEquals($expectedResponse, $response); + } + + public function testDestroyNotAccessibleToSubAdmin() { + $this->container['IsAdmin'] = false; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('myself')); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + + $toDeleteUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $this->container['UserSession'] + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['UserManager'] + ->method('get') + ->with('UserToDelete') + ->will($this->returnValue($toDeleteUser)); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('isUserAccessible') + ->with($user, $toDeleteUser) + ->will($this->returnValue(false)); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 'status' => 'error', + 'data' => [ + 'message' => 'Authentication error' + ] + ], + Http::STATUS_FORBIDDEN + ); + $response = $this->container['UsersController']->destroy('UserToDelete'); + $this->assertEquals($expectedResponse, $response); + } + + /** + * test if an invalid mail result in a failure response + */ + public function testCreateUnsuccessfulWithInvalidEmailAdmin() { + $this->container['IsAdmin'] = true; + + $expectedResponse = new DataResponse([ + 'message' => 'Invalid mail address', + ], + Http::STATUS_UNPROCESSABLE_ENTITY + ); + $response = $this->container['UsersController']->create('foo', 'password', [], 'invalidMailAdress'); + $this->assertEquals($expectedResponse, $response); + } + + /** + * test if a valid mail result in a successful mail send + */ + public function testCreateSuccessfulWithValidEmailAdmin() { + $this->container['IsAdmin'] = true; + $message = $this->getMockBuilder('\OC\Mail\Message') + ->disableOriginalConstructor()->getMock(); + $message + ->expects($this->at(0)) + ->method('setTo') + ->with(['validMail@Adre.ss' => 'foo']); + $message + ->expects($this->at(1)) + ->method('setSubject') + ->with('Your account was created'); + $htmlBody = new Http\TemplateResponse( + 'settings', + 'email.new_user', + [ + 'username' => 'foo', + 'url' => '', + ], + 'blank' + ); + $message + ->expects($this->at(2)) + ->method('setHtmlBody') + ->with($htmlBody->render()); + $plainBody = new Http\TemplateResponse( + 'settings', + 'email.new_user_plain_text', + [ + 'username' => 'foo', + 'url' => '', + ], + 'blank' + ); + $message + ->expects($this->at(3)) + ->method('setPlainBody') + ->with($plainBody->render()); + $message + ->expects($this->at(4)) + ->method('setFrom') + ->with(['no-reply@owncloud.com' => null]); + + $this->container['Mailer'] + ->expects($this->at(0)) + ->method('validateMailAddress') + ->with('validMail@Adre.ss') + ->will($this->returnValue(true)); + $this->container['Mailer'] + ->expects($this->at(1)) + ->method('createMessage') + ->will($this->returnValue($message)); + $this->container['Mailer'] + ->expects($this->at(2)) + ->method('send') + ->with($message); + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + + $this->container['UserManager'] + ->expects($this->once()) + ->method('createUser') + ->will($this->onConsecutiveCalls($user)); + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $response = $this->container['UsersController']->create('foo', 'password', [], 'validMail@Adre.ss'); + $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); + } + + private function mockUser($userId = 'foo', $displayName = 'M. Foo', + $lastLogin = 500, $home = '/home/foo', $backend = 'OC_User_Database') { + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue($userId)); + $user + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue($displayName)); + $user + ->method('getLastLogin') + ->will($this->returnValue($lastLogin)); + $user + ->method('getHome') + ->will($this->returnValue($home)); + $user + ->expects($this->once()) + ->method('getBackendClassName') + ->will($this->returnValue($backend)); + + $result = [ + 'name' => $userId, + 'displayname' => $displayName, + 'groups' => null, + 'subadmin' => array(), + 'quota' => null, + 'storageLocation' => $home, + 'lastLogin' => $lastLogin * 1000, + 'backend' => $backend, + 'email' => null, + 'isRestoreDisabled' => false, + 'isAvatarAvailable' => true, + ]; + + return [$user, $result]; + } + + public function testRestorePossibleWithoutEncryption() { + $this->container['IsAdmin'] = true; + + list($user, $expectedResult) = $this->mockUser(); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); + $this->assertEquals($expectedResult, $result); + } + + public function testRestorePossibleWithAdminAndUserRestore() { + $this->container['IsAdmin'] = true; + + list($user, $expectedResult) = $this->mockUser(); + + $this->container['OCP\\App\\IAppManager'] + ->expects($this->once()) + ->method('isEnabledForUser') + ->with( + $this->equalTo('encryption') + ) + ->will($this->returnValue(true)); + $this->container['Config'] + ->expects($this->once()) + ->method('getAppValue') + ->with( + $this->equalTo('encryption'), + $this->equalTo('recoveryAdminEnabled'), + $this->anything() + ) + ->will($this->returnValue('1')); + + $this->container['Config'] + ->expects($this->at(1)) + ->method('getUserValue') + ->with( + $this->anything(), + $this->equalTo('encryption'), + $this->equalTo('recoveryEnabled'), + $this->anything() + ) + ->will($this->returnValue('1')); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); + $this->assertEquals($expectedResult, $result); + } + + public function testRestoreNotPossibleWithoutAdminRestore() { + $this->container['IsAdmin'] = true; + + list($user, $expectedResult) = $this->mockUser(); + + $this->container['OCP\\App\\IAppManager'] + ->method('isEnabledForUser') + ->with( + $this->equalTo('encryption') + ) + ->will($this->returnValue(true)); + + $expectedResult['isRestoreDisabled'] = true; + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); + $this->assertEquals($expectedResult, $result); + } + + public function testRestoreNotPossibleWithoutUserRestore() { + $this->container['IsAdmin'] = true; + + list($user, $expectedResult) = $this->mockUser(); + + $this->container['OCP\\App\\IAppManager'] + ->expects($this->once()) + ->method('isEnabledForUser') + ->with( + $this->equalTo('encryption') + ) + ->will($this->returnValue(true)); + $this->container['Config'] + ->expects($this->once()) + ->method('getAppValue') + ->with( + $this->equalTo('encryption'), + $this->equalTo('recoveryAdminEnabled'), + $this->anything() + ) + ->will($this->returnValue('1')); + + $this->container['Config'] + ->expects($this->at(1)) + ->method('getUserValue') + ->with( + $this->anything(), + $this->equalTo('encryption'), + $this->equalTo('recoveryEnabled'), + $this->anything() + ) + ->will($this->returnValue('0')); + + $expectedResult['isRestoreDisabled'] = true; + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); + $this->assertEquals($expectedResult, $result); + } + + public function testNoAvatar() { + $this->container['IsAdmin'] = true; + + list($user, $expectedResult) = $this->mockUser(); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin->expects($this->once()) + ->method('getSubAdminsGroups') + ->with($user) + ->will($this->returnValue([])); + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $this->container['OCP\\IAvatarManager'] + ->method('getAvatar') + ->will($this->throwException(new \OCP\Files\NotFoundException())); + $expectedResult['isAvatarAvailable'] = false; + + $result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); + $this->assertEquals($expectedResult, $result); + } + + /** + * @return array + */ + public function setEmailAddressData() { + return [ + /* mailAddress, isValid, expectsUpdate, canChangeDisplayName, responseCode */ + [ '', true, true, true, Http::STATUS_OK ], + [ 'foo@local', true, true, true, Http::STATUS_OK], + [ 'foo@bar@local', false, false, true, Http::STATUS_UNPROCESSABLE_ENTITY], + [ 'foo@local', true, false, false, Http::STATUS_FORBIDDEN], + ]; + } + + /** + * @dataProvider setEmailAddressData + * + * @param string $mailAddress + * @param bool $isValid + * @param bool $expectsUpdate + * @param bool $expectsDelete + */ + public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->any()) + ->method('canChangeDisplayName') + ->will($this->returnValue($canChangeDisplayName)); + $user + ->expects($expectsUpdate ? $this->once() : $this->never()) + ->method('setEMailAddress') + ->with( + $this->equalTo($mailAddress) + ); + + $this->container['UserSession'] + ->expects($this->atLeastOnce()) + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['Mailer'] + ->expects($this->any()) + ->method('validateMailAddress') + ->with($mailAddress) + ->willReturn($isValid); + + if ($isValid) { + $user->expects($this->atLeastOnce()) + ->method('canChangeDisplayName') + ->willReturn(true); + + $this->container['UserManager'] + ->expects($this->atLeastOnce()) + ->method('get') + ->with('foo') + ->will($this->returnValue($user)); + } + + $response = $this->container['UsersController']->setMailAddress($user->getUID(), $mailAddress); + + $this->assertSame($responseCode, $response->getStatus()); + } + + public function testStatsAdmin() { + $this->container['IsAdmin'] = true; + + $this->container['UserManager'] + ->expects($this->at(0)) + ->method('countUsers') + ->will($this->returnValue([128, 44])); + + $expectedResponse = new DataResponse( + [ + 'totalUsers' => 172 + ] + ); + $response = $this->container['UsersController']->stats(); + $this->assertEquals($expectedResponse, $response); + } + + /** + * Tests that the subadmin stats return unique users, even + * when a user appears in several groups. + */ + public function testStatsSubAdmin() { + $this->container['IsAdmin'] = false; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + + $group1 = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $group1 + ->expects($this->once()) + ->method('getUsers') + ->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin'])); + + $group2 = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $group2 + ->expects($this->once()) + ->method('getUsers') + ->will($this->returnValue(['bar' => 'B. Ar'])); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->expects($this->at(0)) + ->method('getSubAdminsGroups') + ->will($this->returnValue([$group1, $group2])); + + $this->container['GroupManager'] + ->expects($this->any()) + ->method('getSubAdmin') + ->will($this->returnValue($subadmin)); + + $expectedResponse = new DataResponse( + [ + 'totalUsers' => 3 + ] + ); + + $response = $this->container['UsersController']->stats(); + $this->assertEquals($expectedResponse, $response); + } + + public function testSetDisplayNameNull() { + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('userName'); + + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + + $expectedResponse = new DataResponse( + [ + 'status' => 'error', + 'data' => [ + 'message' => 'Authentication error', + ], + ] + ); + $response = $this->container['UsersController']->setDisplayName(null, 'displayName'); + + $this->assertEquals($expectedResponse, $response); + } + + public function dataSetDisplayName() { + $data = []; + + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + $user1->method('canChangeDisplayName')->willReturn(true); + $data[] = [$user1, $user1, false, false, true]; + + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + $user1->method('canChangeDisplayName')->willReturn(false); + $data[] = [$user1, $user1, false, false, false]; + + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + $user2 = $this->getMock('\OCP\IUser'); + $user2->method('getUID')->willReturn('user2'); + $user2->method('canChangeDisplayName')->willReturn(true); + $data[] = [$user1, $user2, false, false, false]; + + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + $user2 = $this->getMock('\OCP\IUser'); + $user2->method('getUID')->willReturn('user2'); + $user2->method('canChangeDisplayName')->willReturn(true); + $data[] = [$user1, $user2, true, false, true]; + + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + $user2 = $this->getMock('\OCP\IUser'); + $user2->method('getUID')->willReturn('user2'); + $user2->method('canChangeDisplayName')->willReturn(true); + $data[] = [$user1, $user2, false, true, true]; + + return $data; + } + + /** + * @dataProvider dataSetDisplayName + */ + public function testSetDisplayName($currentUser, $editUser, $isAdmin, $isSubAdmin, $valid) { + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->willReturn($currentUser); + $this->container['UserManager'] + ->expects($this->once()) + ->method('get') + ->with($editUser->getUID()) + ->willReturn($editUser); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->method('isUserAccessible') + ->with($currentUser, $editUser) + ->willReturn($isSubAdmin); + + $this->container['GroupManager'] + ->method('getSubAdmin') + ->willReturn($subadmin); + $this->container['GroupManager'] + ->method('isAdmin') + ->with($currentUser->getUID()) + ->willReturn($isAdmin); + + if ($valid === true) { + $editUser->expects($this->once()) + ->method('setDisplayName') + ->with('newDisplayName') + ->willReturn(true); + $expectedResponse = new DataResponse( + [ + 'status' => 'success', + 'data' => [ + 'message' => 'Your full name has been changed.', + 'username' => $editUser->getUID(), + 'displayName' => 'newDisplayName', + ], + ] + ); + } else { + $editUser->expects($this->never())->method('setDisplayName'); + $expectedResponse = new DataResponse( + [ + 'status' => 'error', + 'data' => [ + 'message' => 'Authentication error', + ], + ] + ); + } + + $response = $this->container['UsersController']->setDisplayName($editUser->getUID(), 'newDisplayName'); + $this->assertEquals($expectedResponse, $response); + } + + public function testSetDisplayNameFails() { + $user = $this->getMock('\OCP\IUser'); + $user->method('canChangeDisplayname')->willReturn(true); + $user->method('getUID')->willReturn('user'); + $user->expects($this->once()) + ->method('setDisplayName') + ->with('newDisplayName') + ->willReturn(false); + $user->method('getDisplayName')->willReturn('oldDisplayName'); + + $this->container['UserSession'] + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + $this->container['UserManager'] + ->expects($this->once()) + ->method('get') + ->with($user->getUID()) + ->willReturn($user); + + $subadmin = $this->getMockBuilder('\OC\SubAdmin') + ->disableOriginalConstructor() + ->getMock(); + $subadmin + ->method('isUserAccessible') + ->with($user, $user) + ->willReturn(false); + + $this->container['GroupManager'] + ->method('getSubAdmin') + ->willReturn($subadmin); + $this->container['GroupManager'] + ->expects($this->once()) + ->method('isAdmin') + ->with($user->getUID()) + ->willReturn(false); + + $expectedResponse = new DataResponse( + [ + 'status' => 'error', + 'data' => [ + 'message' => 'Unable to change full name', + 'displayName' => 'oldDisplayName', + ], + ] + ); + $response = $this->container['UsersController']->setDisplayName($user->getUID(), 'newDisplayName'); + $this->assertEquals($expectedResponse, $response); + } +} diff --git a/tests/Settings/Middleware/SubadminMiddlewareTest.php b/tests/Settings/Middleware/SubadminMiddlewareTest.php new file mode 100644 index 00000000000..652f8b2d151 --- /dev/null +++ b/tests/Settings/Middleware/SubadminMiddlewareTest.php @@ -0,0 +1,99 @@ +<?php +/** + * @author Lukas Reschke + * @copyright 2014 Lukas Reschke lukas@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Tests\Settings\Middleware; + +use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException; +use OC\AppFramework\Utility\ControllerMethodReflector; +use OC\Settings\Middleware\SubadminMiddleware; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\TemplateResponse; + +/** + * Verifies whether an user has at least subadmin rights. + * To bypass use the `@NoSubadminRequired` annotation + * + * @package Tests\Settings\Middleware + */ +class SubadminMiddlewareTest extends \Test\TestCase { + /** @var SubadminMiddleware */ + private $subadminMiddlewareAsSubAdmin; + /** @var SubadminMiddleware */ + private $subadminMiddleware; + /** @var ControllerMethodReflector */ + private $reflector; + /** @var Controller */ + private $controller; + + protected function setUp() { + $this->reflector = $this->getMockBuilder('\OC\AppFramework\Utility\ControllerMethodReflector') + ->disableOriginalConstructor()->getMock(); + $this->controller = $this->getMockBuilder('\OCP\AppFramework\Controller') + ->disableOriginalConstructor()->getMock(); + + $this->subadminMiddlewareAsSubAdmin = new SubadminMiddleware($this->reflector, true); + $this->subadminMiddleware = new SubadminMiddleware($this->reflector, false); + } + + /** + * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\NotAdminException + */ + public function testBeforeControllerAsUserWithExemption() { + $this->reflector + ->expects($this->once()) + ->method('hasAnnotation') + ->with('NoSubadminRequired') + ->will($this->returnValue(false)); + $this->subadminMiddleware->beforeController($this->controller, 'foo'); + } + + + public function testBeforeControllerAsUserWithoutExemption() { + $this->reflector + ->expects($this->once()) + ->method('hasAnnotation') + ->with('NoSubadminRequired') + ->will($this->returnValue(true)); + $this->subadminMiddleware->beforeController($this->controller, 'foo'); + } + + public function testBeforeControllerAsSubAdminWithoutExemption() { + $this->reflector + ->expects($this->once()) + ->method('hasAnnotation') + ->with('NoSubadminRequired') + ->will($this->returnValue(false)); + $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo'); + } + + public function testBeforeControllerAsSubAdminWithExemption() { + $this->reflector + ->expects($this->once()) + ->method('hasAnnotation') + ->with('NoSubadminRequired') + ->will($this->returnValue(true)); + $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo'); + } + + public function testAfterNotAdminException() { + $expectedResponse = new TemplateResponse('core', '403', array(), 'guest'); + $expectedResponse->setStatus(403); + $this->assertEquals($expectedResponse, $this->subadminMiddleware->afterException($this->controller, 'foo', new NotAdminException())); + } + + /** + * @expectedException \Exception + */ + public function testAfterRegularException() { + $expectedResponse = new TemplateResponse('core', '403', array(), 'guest'); + $expectedResponse->setStatus(403); + $this->subadminMiddleware->afterException($this->controller, 'foo', new \Exception()); + } +} |