diff options
Diffstat (limited to 'tests')
22 files changed, 560 insertions, 175 deletions
diff --git a/tests/Core/Command/Apps/AppsDisableTest.php b/tests/Core/Command/Apps/AppsDisableTest.php index cbe6a816cd6..fea368f4b03 100644 --- a/tests/Core/Command/Apps/AppsDisableTest.php +++ b/tests/Core/Command/Apps/AppsDisableTest.php @@ -61,7 +61,7 @@ class AppsDisableTest extends TestCase { $this->commandTester->execute($input); - $this->assertContains($output, $this->commandTester->getDisplay()); + $this->assertStringContainsString($output, $this->commandTester->getDisplay()); $this->assertSame($statusCode, $this->commandTester->getStatusCode()); } diff --git a/tests/Core/Command/Apps/AppsEnableTest.php b/tests/Core/Command/Apps/AppsEnableTest.php index 6c137dca44b..ecbed649d36 100644 --- a/tests/Core/Command/Apps/AppsEnableTest.php +++ b/tests/Core/Command/Apps/AppsEnableTest.php @@ -66,12 +66,12 @@ class AppsEnableTest extends TestCase { $this->commandTester->execute($input); - $this->assertContains($output, $this->commandTester->getDisplay()); + $this->assertStringContainsString($output, $this->commandTester->getDisplay()); $this->assertSame($statusCode, $this->commandTester->getStatusCode()); } public function dataCommandInput(): array { - return [ + $data = [ [['admin_audit'], null, 0, 'admin_audit enabled'], [['comments'], null, 0, 'comments enabled'], [['invalid_app'], null, 1, 'Could not download app invalid_app'], @@ -83,16 +83,20 @@ class AppsEnableTest extends TestCase { [['comments'], ['admin'], 1, "comments can't be enabled for groups"], [['updatenotification'], ['admin'], 0, 'updatenotification enabled for groups: admin'], -# TODO: not reliable due to dependency to appstore -# [['updatenotification', 'contacts'], ['admin'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"], [['updatenotification', 'accessibility'], ['admin'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"], [['updatenotification'], ['admin', 'invalid_group'], 0, 'updatenotification enabled for groups: admin'], -# TODO: not reliable due to dependency to appstore -# [['updatenotification', 'contacts'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"], -# [['updatenotification', 'contacts', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin\nCould not download app invalid_app"], [['updatenotification', 'accessibility'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"], [['updatenotification', 'accessibility', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin\nCould not download app invalid_app"], ]; + + if (getenv('CI') === false) { + /** Tests disabled on drone/ci due to appstore dependency */ + $data[] = [['updatenotification', 'contacts'], ['admin'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"]; + $data[] = [['updatenotification', 'contacts'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"]; + $data[] = [['updatenotification', 'contacts', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin\nCould not download app invalid_app"]; + } + + return $data; } } diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 9135a6bc92f..284c82310a1 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -33,6 +33,9 @@ namespace Tests\Core\Controller; use OC\AppFramework\Utility\TimeFactory; use OC\Core\Controller\AvatarController; +use OCP\Accounts\IAccount; +use OCP\Accounts\IAccountManager; +use OCP\Accounts\IAccountProperty; use OCP\AppFramework\Http; use OCP\Files\File; use OCP\Files\IRootFolder; @@ -46,6 +49,7 @@ use OCP\ILogger; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; +use PHPUnit\Framework\MockObject\MockObject; /** * Class AvatarControllerTest @@ -78,6 +82,8 @@ class AvatarControllerTest extends \Test\TestCase { private $request; /** @var TimeFactory|\PHPUnit_Framework_MockObject_MockObject */ private $timeFactory; + /** @var IAccountManager|MockObject */ + private $accountManager; protected function setUp(): void { parent::setUp(); @@ -92,6 +98,7 @@ class AvatarControllerTest extends \Test\TestCase { $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); $this->timeFactory = $this->getMockBuilder('OC\AppFramework\Utility\TimeFactory')->getMock(); + $this->accountManager = $this->createMock(IAccountManager::class); $this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock(); $this->userMock = $this->getMockBuilder(IUser::class)->getMock(); @@ -106,7 +113,8 @@ class AvatarControllerTest extends \Test\TestCase { $this->rootFolder, $this->logger, 'userid', - $this->timeFactory + $this->timeFactory, + $this->accountManager ); // Configure userMock @@ -137,6 +145,39 @@ class AvatarControllerTest extends \Test\TestCase { $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); } + public function testAvatarNotPublic() { + $account = $this->createMock(IAccount::class); + $this->accountManager->method('getAccount') + ->with($this->userMock) + ->willReturn($account); + + $property = $this->createMock(IAccountProperty::class); + $account->method('getProperty') + ->with(IAccountManager::PROPERTY_AVATAR) + ->willReturn($property); + + $property->method('getScope') + ->willReturn(IAccountManager::VISIBILITY_PRIVATE); + + $controller = new AvatarController( + 'core', + $this->request, + $this->avatarManager, + $this->cache, + $this->l, + $this->userManager, + $this->rootFolder, + $this->logger, + null, + $this->timeFactory, + $this->accountManager + ); + + $result = $controller->getAvatar('userId', 128); + + $this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus()); + } + /** * Fetch the user's avatar */ diff --git a/tests/acceptance/features/bootstrap/UsersSettingsContext.php b/tests/acceptance/features/bootstrap/UsersSettingsContext.php index 56dce822359..d42b49cbf2d 100644 --- a/tests/acceptance/features/bootstrap/UsersSettingsContext.php +++ b/tests/acceptance/features/bootstrap/UsersSettingsContext.php @@ -1,9 +1,10 @@ <?php /** - * + * * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * @copyright Copyright (c) 2019, Greta Doci <gretadoci@gmail.com> * * @license GNU AGPL version 3 or any later version * @@ -33,7 +34,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function newUserForm() { return Locator::forThe()->id("new-user")-> - describedAs("New user form in Users Settings"); + describedAs("New user form in Users Settings"); } /** @@ -41,7 +42,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function userNameFieldForNewUser() { return Locator::forThe()->field("newusername")-> - describedAs("User name field for new user in Users Settings"); + describedAs("User name field for new user in Users Settings"); } /** @@ -49,7 +50,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function displayNameFieldForNewUser() { return Locator::forThe()->field("newdisplayname")-> - describedAs("Display name field for new user in Users Settings"); + describedAs("Display name field for new user in Users Settings"); } /** @@ -57,7 +58,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function passwordFieldForNewUser() { return Locator::forThe()->field("newuserpassword")-> - describedAs("Password field for new user in Users Settings"); + describedAs("Password field for new user in Users Settings"); } /** @@ -65,7 +66,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function newUserButton() { return Locator::forThe()->id("new-user-button")-> - describedAs("New user button in Users Settings"); + describedAs("New user button in Users Settings"); } /** @@ -73,26 +74,26 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function createNewUserButton() { return Locator::forThe()->xpath("//form[@id = 'new-user']//input[@type = 'submit']")-> - describedAs("Create user button in Users Settings"); + describedAs("Create user button in Users Settings"); } /** * @return Locator */ public static function rowForUser($user) { - return Locator::forThe()->xpath("//div[@id='app-content']/div/div[normalize-space() = '$user']/..")-> - describedAs("Row for user $user in Users Settings"); + return Locator::forThe()->css("div.user-list-grid div.row[data-id=$user]")-> + describedAs("Row for user $user in Users Settings"); } /** * Warning: you need to watch out for the proper classes order - * + * * @return Locator */ public static function classCellForUser($class, $user) { return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]")-> - descendantOf(self::rowForUser($user))-> - describedAs("$class cell for user $user in Users Settings"); + descendantOf(self::rowForUser($user))-> + describedAs("$class cell for user $user in Users Settings"); } /** @@ -100,8 +101,8 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function inputForUserInCell($cell, $user) { return Locator::forThe()->css("input")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("$cell input for user $user in Users Settings"); + descendantOf(self::classCellForUser($cell, $user))-> + describedAs("$cell input for user $user in Users Settings"); } /** @@ -116,8 +117,8 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function optionInInputForUser($cell, $user) { return Locator::forThe()->css(".multiselect__option--highlight")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("Selected $cell option in $cell input for user $user in Users Settings"); + descendantOf(self::classCellForUser($cell, $user))-> + describedAs("Selected $cell option in $cell input for user $user in Users Settings"); } /** @@ -125,8 +126,8 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function actionsMenuOf($user) { return Locator::forThe()->css(".icon-more")-> - descendantOf(self::rowForUser($user))-> - describedAs("Actions menu for user $user in Users Settings"); + descendantOf(self::rowForUser($user))-> + describedAs("Actions menu for user $user in Users Settings"); } /** @@ -134,8 +135,8 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function theAction($action, $user) { return Locator::forThe()->xpath("//button[normalize-space() = '$action']")-> - descendantOf(self::rowForUser($user))-> - describedAs("$action action for the user $user row in Users Settings"); + descendantOf(self::rowForUser($user))-> + describedAs("$action action for the user $user row in Users Settings"); } /** @@ -143,7 +144,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function theColumn($column) { return Locator::forThe()->xpath("//div[@class='user-list-grid']//div[normalize-space() = '$column']")-> - describedAs("The $column column in Users Settings"); + describedAs("The $column column in Users Settings"); } /** @@ -151,8 +152,25 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public static function selectedSelectOption($cell, $user) { return Locator::forThe()->css(".multiselect__single")-> - descendantOf(self::classCellForUser($cell, $user))-> - describedAs("The selected option of the $cell select for the user $user in Users Settings"); + descendantOf(self::classCellForUser($cell, $user))-> + describedAs("The selected option of the $cell select for the user $user in Users Settings"); + } + + /** + * @return Locator + */ + public static function editModeToggle($user) { + return Locator::forThe()->css(".toggleUserActions button.icon-rename")-> + descendantOf(self::rowForUser($user))-> + describedAs("The edit toggle button for the user $user in Users Settings"); + } + + /** + * @return Locator + */ + public static function editModeOn($user) { + return Locator::forThe()->css("div.user-list-grid div.row.row--editable[data-id=$user]")-> + describedAs("I see the edit mode is on for the user $user in Users Settings"); } /** @@ -205,6 +223,13 @@ class UsersSettingsContext implements Context, ActorAwareInterface { } /** + * @When I toggle the edit mode for the user :user + */ + public function iToggleTheEditModeForUser($user) { + $this->actor->find(self::editModeToggle($user), 10)->click(); + } + + /** * @When I create user :user with password :password */ public function iCreateUserWithPassword($user, $password) { @@ -258,7 +283,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public function iSeeThatTheNewUserFormIsShown() { PHPUnit_Framework_Assert::assertTrue( - $this->actor->find(self::newUserForm(), 10)->isVisible()); + $this->actor->find(self::newUserForm(), 10)->isVisible()); } /** @@ -266,7 +291,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public function iSeeTheAction($action, $user) { PHPUnit_Framework_Assert::assertTrue( - $this->actor->find(self::theAction($action, $user), 10)->isVisible()); + $this->actor->find(self::theAction($action, $user), 10)->isVisible()); } /** @@ -274,7 +299,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { */ public function iSeeThatTheColumnIsShown($column) { PHPUnit_Framework_Assert::assertTrue( - $this->actor->find(self::theColumn($column), 10)->isVisible()); + $this->actor->find(self::theColumn($column), 10)->isVisible()); } /** @@ -289,15 +314,16 @@ class UsersSettingsContext implements Context, ActorAwareInterface { * @Then I see that the display name for the user :user is :displayName */ public function iSeeThatTheDisplayNameForTheUserIs($user, $displayName) { - PHPUnit_Framework_Assert::assertEquals($displayName, $this->actor->find(self::displayNameCellForUser($user), 10)->getValue()); + PHPUnit_Framework_Assert::assertEquals( + $displayName, $this->actor->find(self::displayNameCellForUser($user), 10)->getValue()); } /** * @Then I see that the :cell cell for user :user is done loading */ public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) { - WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user)); - WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user)); + WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user)); + WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user)); } /** @@ -307,6 +333,11 @@ class UsersSettingsContext implements Context, ActorAwareInterface { PHPUnit_Framework_Assert::assertEquals( $this->actor->find(self::selectedSelectOption('quota', $user), 2)->getText(), $quota); } - + /** + * @Then I see that the edit mode is on for user :user + */ + public function iSeeThatTheEditModeIsOn($user) { + WaitFor::elementToBeEventuallyShown($this->actor, self::editModeOn($user)); + } } diff --git a/tests/acceptance/features/users.feature b/tests/acceptance/features/users.feature index 263e9fddfc0..c4cfa3b69bf 100644 --- a/tests/acceptance/features/users.feature +++ b/tests/acceptance/features/users.feature @@ -63,18 +63,20 @@ Feature: users And I am logged in as the admin And I open the User settings And I see that the list of users contains the user user0 - # disabled because we need the TAB patch: + When I toggle the edit mode for the user user0 + Then I see that the edit mode is on for user user0 + # disabled because we need the TAB patch: # https://github.com/minkphp/MinkSelenium2Driver/pull/244 # When I assign the user user0 to the group admin # Then I see that the section Admins is shown # And I see that the section Admins has a count of 2 - + Scenario: create and delete a group Given I act as Jane And I am logged in as the admin And I open the User settings And I see that the list of users contains the user user0 - # disabled because we need the TAB patch: + # disabled because we need the TAB patch: # https://github.com/minkphp/MinkSelenium2Driver/pull/244 # And I assign the user user0 to the group Group1 # And I see that the section Group1 is shown @@ -112,7 +114,7 @@ Feature: users Then I see that the "Storage location" column is shown When I toggle the showUserBackend checkbox in the settings Then I see that the "User backend" column is shown - + # Scenario: change display name # Given I act as Jane # And I am logged in as the admin @@ -128,6 +130,8 @@ Feature: users And I am logged in as the admin And I open the User settings And I see that the list of users contains the user user0 + When I toggle the edit mode for the user user0 + Then I see that the edit mode is on for user user0 And I see that the password of user0 is "" When I set the password for user0 to 123456 And I see that the password cell for user user0 is done loading @@ -149,8 +153,10 @@ Feature: users And I am logged in as the admin And I open the User settings And I see that the list of users contains the user user0 + When I toggle the edit mode for the user user0 + Then I see that the edit mode is on for user user0 And I see that the user quota of user0 is Unlimited - # disabled because we need the TAB patch: + # disabled because we need the TAB patch: # https://github.com/minkphp/MinkSelenium2Driver/pull/244 # When I set the user user0 quota to 1GB # And I see that the quota cell for user user0 is done loading @@ -163,4 +169,4 @@ Feature: users # Then I see that the user quota of user0 is "0 B" # When I set the user user0 quota to Default # And I see that the quota cell for user user0 is done loading - # Then I see that the user quota of user0 is "Default quota"
\ No newline at end of file + # Then I see that the user quota of user0 is "Default quota" diff --git a/tests/karma.config.js b/tests/karma.config.js index fb460ad850d..06503bf9bf8 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -53,10 +53,14 @@ module.exports = function(config) { // only test these files, others are not ready and mess // up with the global namespace/classes/state 'apps/files_sharing/js/app.js', - 'apps/files_sharing/js/sharedfilelist.js', 'apps/files_sharing/js/dist/additionalScripts.js', - 'apps/files_sharing/js/public.js', + 'apps/files_sharing/js/dist/files_sharing_tab.js', + 'apps/files_sharing/js/dist/files_sharing.js', + 'apps/files_sharing/js/dist/main.js', + 'apps/files_sharing/js/dist/sidebar.js', 'apps/files_sharing/js/files_drop.js', + 'apps/files_sharing/js/public.js', + 'apps/files_sharing/js/sharedfilelist.js', 'apps/files_sharing/js/templates.js', ], testFiles: ['apps/files_sharing/tests/js/*.js'] diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index b3437ad290c..11450667fcc 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -390,6 +390,7 @@ class AppManagerTest extends TestCase { 'test1', 'test3', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ]; $this->assertEquals($apps, $this->manager->getInstalledApps()); @@ -418,6 +419,7 @@ class AppManagerTest extends TestCase { 'test1', 'test3', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ]; $this->assertEquals($enabled, $this->manager->getEnabledAppsForUser($user)); @@ -444,6 +446,7 @@ class AppManagerTest extends TestCase { 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], 'settings' => ['id' => 'settings'], 'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'], + 'viewer' => ['id' => 'viewer'], 'workflowengine' => ['id' => 'workflowengine'], 'oauth2' => ['id' => 'oauth2'], ]; @@ -494,6 +497,7 @@ class AppManagerTest extends TestCase { 'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'], 'workflowengine' => ['id' => 'workflowengine'], 'oauth2' => ['id' => 'oauth2'], + 'viewer' => ['id' => 'viewer'], ]; $manager->expects($this->any()) @@ -537,6 +541,7 @@ class AppManagerTest extends TestCase { 'test1', 'test3', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ]; $this->assertEquals($enabled, $this->manager->getEnabledAppsForGroup($group)); diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index a1f340075b8..4aac0d68318 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -346,6 +346,7 @@ class AppTest extends \Test\TestCase { 'provisioning_api', 'settings', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ), false @@ -367,6 +368,7 @@ class AppTest extends \Test\TestCase { 'provisioning_api', 'settings', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ), false @@ -389,6 +391,7 @@ class AppTest extends \Test\TestCase { 'provisioning_api', 'settings', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ), false @@ -411,6 +414,7 @@ class AppTest extends \Test\TestCase { 'provisioning_api', 'settings', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ), false, @@ -433,6 +437,7 @@ class AppTest extends \Test\TestCase { 'provisioning_api', 'settings', 'twofactor_backupcodes', + 'viewer', 'workflowengine', ), true, @@ -511,11 +516,11 @@ class AppTest extends \Test\TestCase { ); $apps = \OC_App::getEnabledApps(); - $this->assertEquals(array('files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'twofactor_backupcodes', 'workflowengine'), $apps); + $this->assertEquals(array('files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'twofactor_backupcodes', 'viewer', 'workflowengine'), $apps); // mock should not be called again here $apps = \OC_App::getEnabledApps(); - $this->assertEquals(array('files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'twofactor_backupcodes', 'workflowengine'), $apps); + $this->assertEquals(array('files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'twofactor_backupcodes', 'viewer', 'workflowengine'), $apps); $this->restoreAppConfig(); \OC_User::setUserId(null); diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php index 26306458d83..450bdf607b3 100644 --- a/tests/lib/Cache/FileCacheTest.php +++ b/tests/lib/Cache/FileCacheTest.php @@ -95,6 +95,15 @@ class FileCacheTest extends TestCache { \OC_User::setUserId($this->user); \OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir); + if ($this->instance) { + $this->instance->clear(); + $this->instance = null; + } + + //tear down the users dir aswell + $user = \OC::$server->getUserManager()->get('test'); + $user->delete(); + // Restore the original mount point \OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::mount($this->storage, array(), '/'); diff --git a/tests/lib/Collaboration/Resources/ManagerTest.php b/tests/lib/Collaboration/Resources/ManagerTest.php new file mode 100644 index 00000000000..f59c2913c88 --- /dev/null +++ b/tests/lib/Collaboration/Resources/ManagerTest.php @@ -0,0 +1,62 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Collaboration\Resources; + +use OC\Collaboration\Resources\Manager; +use OCP\Collaboration\Resources\IManager; +use OCP\Collaboration\Resources\IProviderManager; +use OCP\IDBConnection; +use OCP\ILogger; +use Test\TestCase; + +class ManagerTest extends TestCase { + + /** @var ILogger */ + protected $logger; + /** @var IProviderManager */ + protected $providerManager; + /** @var IManager */ + protected $manager; + + protected function setUp(): void { + parent::setUp(); + + $this->logger = $this->createMock(ILogger::class); + $this->providerManager = $this->createMock(IProviderManager::class); + + /** @var IDBConnection $connection */ + $connection = $this->createMock(IDBConnection::class); + $this->manager = new Manager($connection, $this->providerManager, $this->logger); + } + + public function testRegisterResourceProvider(): void { + $this->logger->expects($this->once()) + ->method('debug') + ->with($this->equalTo('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated'), $this->equalTo(['provider' => 'AwesomeResourceProvider'])); + $this->providerManager->expects($this->once()) + ->method('registerResourceProvider') + ->with($this->equalTo('AwesomeResourceProvider')); + + $this->manager->registerResourceProvider('AwesomeResourceProvider'); + } +} diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php new file mode 100644 index 00000000000..d8bebe8fa6c --- /dev/null +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -0,0 +1,111 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Collaboration\Resources; + +use OC\Collaboration\Resources\ProviderManager; +use OCA\Files\Collaboration\Resources\ResourceProvider; +use OCP\AppFramework\QueryException; +use OCP\Collaboration\Resources\IProviderManager; +use OCP\ILogger; +use OCP\IServerContainer; +use Test\TestCase; + +class ProviderManagerTest extends TestCase { + + /** @var IServerContainer */ + protected $serverContainer; + /** @var ILogger */ + protected $logger; + /** @var IProviderManager */ + protected $providerManager; + + protected function setUp(): void { + parent::setUp(); + + $this->serverContainer = $this->createMock(IServerContainer::class); + $this->logger = $this->createMock(ILogger::class); + + $this->providerManager = new class($this->serverContainer, $this->logger) extends ProviderManager { + public function countProviders(): int { + return count($this->providers); + } + }; + } + + public function testRegisterResourceProvider(): void { + $this->providerManager->registerResourceProvider('AwesomeResourceProvider'); + $this->assertSame(1, $this->providerManager->countProviders()); + } + + public function testGetResourceProvidersNoProvider(): void { + $this->assertCount(0, $this->providerManager->getResourceProviders()); + } + + public function testGetResourceProvidersValidProvider(): void { + $this->serverContainer->expects($this->once()) + ->method('query') + ->with($this->equalTo(ResourceProvider::class)) + ->willReturn($this->createMock(ResourceProvider::class)); + + $this->providerManager->registerResourceProvider(ResourceProvider::class); + $resourceProviders = $this->providerManager->getResourceProviders(); + + $this->assertCount(1, $resourceProviders); + $this->assertInstanceOf(ResourceProvider::class, $resourceProviders[0]); + } + + public function testGetResourceProvidersInvalidProvider(): void { + $this->serverContainer->expects($this->once()) + ->method('query') + ->with($this->equalTo('InvalidResourceProvider')) + ->willThrowException(new QueryException('A meaningful error message')); + + $this->logger->expects($this->once()) + ->method('logException'); + + $this->providerManager->registerResourceProvider('InvalidResourceProvider'); + $resourceProviders = $this->providerManager->getResourceProviders(); + + $this->assertCount(0, $resourceProviders); + } + + public function testGetResourceProvidersValidAndInvalidProvider(): void { + $this->serverContainer->expects($this->at(0)) + ->method('query') + ->with($this->equalTo('InvalidResourceProvider')) + ->willThrowException(new QueryException('A meaningful error message')); + $this->serverContainer->expects($this->at(1)) + ->method('query') + ->with($this->equalTo(ResourceProvider::class)) + ->willReturn($this->createMock(ResourceProvider::class)); + + $this->logger->expects($this->once()) + ->method('logException'); + + $this->providerManager->registerResourceProvider('InvalidResourceProvider'); + $this->providerManager->registerResourceProvider(ResourceProvider::class); + $resourceProviders = $this->providerManager->getResourceProviders(); + + $this->assertCount(1, $resourceProviders); + } +} diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 58f775febb0..15415a4061c 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -60,7 +60,7 @@ class MigrationsTest extends \Test\TestCase { $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName()); } - + public function testExecuteUnknownStep() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Version 20170130180000 is unknown.'); @@ -68,7 +68,7 @@ class MigrationsTest extends \Test\TestCase { $this->migrationService->executeStep('20170130180000'); } - + public function testUnknownApp() { $this->expectException(\Exception::class); $this->expectExceptionMessage('App not found'); @@ -76,7 +76,7 @@ class MigrationsTest extends \Test\TestCase { $migrationService = new MigrationService('unknown-bloody-app', $this->db); } - + public function testExecuteStepWithUnknownClass() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Migration step \'X\' is unknown'); @@ -341,7 +341,7 @@ class MigrationsTest extends \Test\TestCase { $table = $this->createMock(Table::class); $table->expects($this->any()) ->method('getName') - ->willReturn(\str_repeat('a', 26)); + ->willReturn(\str_repeat('a', 25)); $table->expects($this->once()) ->method('getColumns') @@ -375,7 +375,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongTableName() { $this->expectException(\InvalidArgumentException::class); @@ -400,7 +400,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault() { $this->expectException(\InvalidArgumentException::class); @@ -453,7 +453,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() { $this->expectException(\InvalidArgumentException::class); @@ -496,7 +496,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() { $this->expectException(\InvalidArgumentException::class); @@ -530,7 +530,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() { $this->expectException(\InvalidArgumentException::class); @@ -567,7 +567,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() { $this->expectException(\InvalidArgumentException::class); @@ -607,7 +607,7 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - + public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index d7617125faa..3d9baf35b1c 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -198,4 +198,24 @@ class FunctionBuilderTest extends TestCase { $this->assertEquals(10, $query->execute()->fetchColumn()); } + + public function testGreatest() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->greatest($query->createNamedParameter(2, IQueryBuilder::PARAM_INT), new Literal(1))); + $query->from('appconfig') + ->setMaxResults(1); + + $this->assertEquals(2, $query->execute()->fetchColumn()); + } + + public function testLeast() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->least($query->createNamedParameter(2, IQueryBuilder::PARAM_INT), new Literal(1))); + $query->from('appconfig') + ->setMaxResults(1); + + $this->assertEquals(1, $query->execute()->fetchColumn()); + } } diff --git a/tests/lib/Files/Cache/PropagatorTest.php b/tests/lib/Files/Cache/PropagatorTest.php index ce6b84ee4d0..c1822c90282 100644 --- a/tests/lib/Files/Cache/PropagatorTest.php +++ b/tests/lib/Files/Cache/PropagatorTest.php @@ -81,6 +81,17 @@ class PropagatorTest extends TestCase { } } + public function testSizePropagationNoNegative() { + $paths = ['', 'foo', 'foo/bar']; + $oldInfos = $this->getFileInfos($paths); + $this->storage->getPropagator()->propagateChange('foo/bar/file.txt', time(), -100); + $newInfos = $this->getFileInfos($paths); + + foreach ($oldInfos as $i => $oldInfo) { + $this->assertEquals(-1, $newInfos[$i]->getSize()); + } + } + public function testBatchedPropagation() { $this->storage->mkdir('foo/baz'); $this->storage->mkdir('asd'); diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index d63693a655b..2f61f634ffb 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\MountPoint; use OC\Files\Storage\Storage; use OC\Log; use OC\User\Manager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\ICachedMountInfo; use OCP\IConfig; use OCP\IDBConnection; @@ -45,7 +46,7 @@ class UserMountCacheTest extends TestCase { protected function setUp(): void { $this->fileIds = []; $this->connection = \OC::$server->getDatabaseConnection(); - $this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class)); + $this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)); $userBackend = new Dummy(); $userBackend->createUser('u1', ''); $userBackend->createUser('u2', ''); diff --git a/tests/lib/Files/EtagTest.php b/tests/lib/Files/EtagTest.php index acda220d01f..554812253f3 100644 --- a/tests/lib/Files/EtagTest.php +++ b/tests/lib/Files/EtagTest.php @@ -10,6 +10,7 @@ namespace Test\Files; use OC\Files\Filesystem; use OCP\Share; +use OCA\Files_Sharing\AppInfo\Application; /** * Class EtagTest @@ -32,8 +33,9 @@ class EtagTest extends \Test\TestCase { parent::setUp(); \OC_Hook::clear('OC_Filesystem', 'setup'); - $application = new \OCA\Files_Sharing\AppInfo\Application(); - $application->registerMountProviders(); + // init files sharing + new Application(); + \OC\Share\Share::registerBackend('file', 'OCA\Files_Sharing\ShareBackend\File'); \OC\Share\Share::registerBackend('folder', 'OCA\Files_Sharing\ShareBackend\Folder', 'file'); diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 95ee0ada24f..a9d678e76e9 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -14,6 +14,7 @@ use OC\User\Manager; use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IFile; use OCP\Encryption\Keys\IStorage; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\Files\Mount\IMountPoint; use OCP\IConfig; @@ -131,7 +132,7 @@ class EncryptionTest extends Storage { $this->util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) - ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $this->util->expects($this->any()) ->method('getUidAndFilename') @@ -568,7 +569,7 @@ class EncryptionTest extends Storage { ->setConstructorArgs( [ new View(), - new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), + new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache @@ -637,7 +638,7 @@ class EncryptionTest extends Storage { ->willReturn($exists); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 3ded6ef91d6..fd5e8c6ca9d 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -5,6 +5,7 @@ namespace Test\Files\Stream; use OC\Files\Cache\CacheEntry; use OC\Files\View; use OC\Memcache\ArrayCache; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\IConfig; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -48,7 +49,7 @@ class EncryptionTest extends \Test\TestCase { $file->expects($this->any())->method('getAccessList')->willReturn([]); $util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename']) - ->setConstructorArgs([new View(), new \OC\User\Manager($config, $this->createMock(EventDispatcherInterface::class)), $groupManager, $config, $arrayCache]) + ->setConstructorArgs([new View(), new \OC\User\Manager($config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $groupManager, $config, $arrayCache]) ->getMock(); $util->expects($this->any()) ->method('getUidAndFilename') diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php index e522239f001..01f11bf39c8 100644 --- a/tests/lib/Files/Type/DetectionTest.php +++ b/tests/lib/Files/Type/DetectionTest.php @@ -22,6 +22,7 @@ namespace Test\Files\Type; use OC\Files\Type\Detection; +use OCP\ILogger; use OCP\IURLGenerator; class DetectionTest extends \Test\TestCase { @@ -32,66 +33,102 @@ class DetectionTest extends \Test\TestCase { parent::setUp(); $this->detection = new Detection( \OC::$server->getURLGenerator(), + \OC::$server->getLogger(), \OC::$SERVERROOT . '/config/', \OC::$SERVERROOT . '/resources/config/' ); } - public function testDetect() { - $dir = \OC::$SERVERROOT.'/tests/data'; + public function dataDetectPath(): array { + return [ + ['foo.txt', 'text/plain'], + ['foo.png', 'image/png'], + ['foo.bar.png', 'image/png'], + ['.hidden.png', 'image/png'], + ['.hidden.foo.png', 'image/png'], + ['.hidden/foo.png', 'image/png'], + ['.hidden/.hidden.png', 'image/png'], + ['test.jpg/foo.png', 'image/png'], + ['.png', 'application/octet-stream'], + ['..hidden', 'application/octet-stream'], + ['foo', 'application/octet-stream'], + ['', 'application/octet-stream'], + ['foo.png.ocTransferId123456789.part', 'image/png'], + ['foo.png.v1234567890', 'image/png'], + ]; + } - $result = $this->detection->detect($dir."/"); - $expected = 'httpd/unix-directory'; - $this->assertEquals($expected, $result); + /** + * @dataProvider dataDetectPath + * + * @param string $path + * @param string $expected + */ + public function testDetectPath(string $path, string $expected): void { + $this->assertEquals($expected, $this->detection->detectPath($path)); + } - $result = $this->detection->detect($dir."/data.tar.gz"); - $expected = 'application/x-gzip'; - $this->assertEquals($expected, $result); + public function dataDetectContent(): array { + return [ + ['/', 'httpd/unix-directory'], +// ['/data.tar.gz', 'application/x-gzip'], TODO: fix as it fails hard on php7.4 now + ['/data.zip', 'application/zip'], + ['/testimage.mp3', 'audio/mpeg'], + ['/testimage.png', 'image/png'], + ]; + } - $result = $this->detection->detect($dir."/data.zip"); - $expected = 'application/zip'; - $this->assertEquals($expected, $result); + /** + * @dataProvider dataDetectContent + * + * @param string $path + * @param string $expected + */ + public function testDetectContent(string $path, string $expected): void { + $this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path)); + } - $result = $this->detection->detect($dir."/testimagelarge.svg"); - $expected = 'image/svg+xml'; - $this->assertEquals($expected, $result); + public function dataDetect(): array { + return [ + ['/', 'httpd/unix-directory'], + ['/data.tar.gz', 'application/x-gzip'], + ['/data.zip', 'application/zip'], + ['/testimagelarge.svg', 'image/svg+xml'], + ['/testimage.png', 'image/png'], + ]; + } - $result = $this->detection->detect($dir."/testimage.png"); - $expected = 'image/png'; - $this->assertEquals($expected, $result); + /** + * @dataProvider dataDetect + * + * @param string $path + * @param string $expected + */ + public function testDetect(string $path, string $expected): void { + $this->assertEquals($expected, $this->detection->detect(\OC::$SERVERROOT . '/tests/data' . $path)); } - public function testGetSecureMimeType() { - $result = $this->detection->getSecureMimeType('image/svg+xml'); + public function testDetectString(): void { + $result = $this->detection->detectString('/data/data.tar.gz'); $expected = 'text/plain'; $this->assertEquals($expected, $result); - - $result = $this->detection->getSecureMimeType('image/png'); - $expected = 'image/png'; - $this->assertEquals($expected, $result); } - public function testDetectPath() { - $this->assertEquals('text/plain', $this->detection->detectPath('foo.txt')); - $this->assertEquals('image/png', $this->detection->detectPath('foo.png')); - $this->assertEquals('image/png', $this->detection->detectPath('foo.bar.png')); - $this->assertEquals('image/png', $this->detection->detectPath('.hidden.png')); - $this->assertEquals('image/png', $this->detection->detectPath('.hidden.foo.png')); - $this->assertEquals('image/png', $this->detection->detectPath('.hidden/foo.png')); - $this->assertEquals('image/png', $this->detection->detectPath('.hidden/.hidden.png')); - $this->assertEquals('image/png', $this->detection->detectPath('test.jpg/foo.png')); - $this->assertEquals('application/octet-stream', $this->detection->detectPath('.png')); - $this->assertEquals('application/octet-stream', $this->detection->detectPath('..hidden')); - $this->assertEquals('application/octet-stream', $this->detection->detectPath('foo')); - $this->assertEquals('application/octet-stream', $this->detection->detectPath('')); - $this->assertEquals('image/png', $this->detection->detectPath('foo.png.ocTransferId123456789.part')); - $this->assertEquals('image/png', $this->detection->detectPath('foo.png.v1234567890')); + public function dataGetSecureMimeType(): array { + return [ + ['image/svg+xml', 'text/plain'], + ['image/png', 'image/png'], + ]; } - public function testDetectString() { - $result = $this->detection->detectString("/data/data.tar.gz"); - $expected = 'text/plain'; - $this->assertEquals($expected, $result); + /** + * @dataProvider dataGetSecureMimeType + * + * @param string $mimeType + * @param string $expected + */ + public function testGetSecureMimeType(string $mimeType, string $expected): void { + $this->assertEquals($expected, $this->detection->getSecureMimeType($mimeType)); } public function testMimeTypeIcon() { @@ -114,13 +151,16 @@ class DetectionTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); + /** @var ILogger $logger */ + $logger = $this->createMock(ILogger::class); + //Only call the url generator once $urlGenerator->expects($this->once()) ->method('imagePath') ->with($this->equalTo('core'), $this->equalTo('filetypes/folder.png')) ->willReturn('folder.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir'); $this->assertEquals('folder.svg', $mimeType); @@ -139,7 +179,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/folder-shared.png')) ->willReturn('folder-shared.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir-shared'); $this->assertEquals('folder-shared.svg', $mimeType); @@ -159,7 +199,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/folder-external.png')) ->willReturn('folder-external.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir-external'); $this->assertEquals('folder-external.svg', $mimeType); @@ -179,7 +219,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/my-type.png')) ->willReturn('my-type.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('my-type'); $this->assertEquals('my-type.svg', $mimeType); @@ -209,7 +249,7 @@ class DetectionTest extends \Test\TestCase { } )); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('my-type'); $this->assertEquals('my.svg', $mimeType); @@ -240,7 +280,7 @@ class DetectionTest extends \Test\TestCase { } )); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo-bar'); $this->assertEquals('file.svg', $mimeType); @@ -259,7 +299,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/foo-bar.png')) ->willReturn('foo-bar.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo-bar'); $this->assertEquals('foo-bar.svg', $mimeType); $mimeType = $detection->mimeTypeIcon('foo-bar'); @@ -285,7 +325,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/foobar-baz.png')) ->willReturn('foobar-baz.svg'); - $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); + $detection = new Detection($urlGenerator, $logger, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo'); $this->assertEquals('foobar-baz.svg', $mimeType); } diff --git a/tests/lib/Security/TrustedDomainHelperTest.php b/tests/lib/Security/TrustedDomainHelperTest.php index 26158401f79..f3ee14dead1 100644 --- a/tests/lib/Security/TrustedDomainHelperTest.php +++ b/tests/lib/Security/TrustedDomainHelperTest.php @@ -31,7 +31,11 @@ class TrustedDomainHelperTest extends \Test\TestCase { * @param bool $result */ public function testIsTrustedDomain($trustedDomains, $testDomain, $result) { - $this->config->expects($this->once()) + $this->config->expects($this->at(0)) + ->method('getSystemValue') + ->with('overwritehost') + ->will($this->returnValue('')); + $this->config->expects($this->at(1)) ->method('getSystemValue') ->with('trusted_domains') ->will($this->returnValue($trustedDomains)); @@ -113,4 +117,15 @@ class TrustedDomainHelperTest extends \Test\TestCase { [$trustedHostTestList, 'LOWERCASE.DOMAIN', true], ]; } + + public function testIsTrustedDomainOverwriteHost() { + $this->config->expects($this->at(0)) + ->method('getSystemValue') + ->with('overwritehost') + ->will($this->returnValue('myproxyhost')); + + $trustedDomainHelper = new TrustedDomainHelper($this->config); + $this->assertTrue($trustedDomainHelper->isTrustedDomain('myproxyhost')); + $this->assertTrue($trustedDomainHelper->isTrustedDomain('myotherhost')); + } } diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index 58a6b550658..40197101fd6 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -11,6 +11,7 @@ namespace Test\User; use OC\AllConfig; use OC\User\Database; use OC\User\Manager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IUser; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -28,18 +29,21 @@ class ManagerTest extends TestCase { /** @var IConfig */ private $config; /** @var EventDispatcherInterface */ - private $dispatcher; + private $oldDispatcher; + /** @var IEventDispatcher */ + private $eventDispatcher; protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->oldDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); } public function testGetBackends() { $userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($userDummyBackend); $this->assertEquals([$userDummyBackend], $manager->getBackends()); $dummyDatabaseBackend = $this->createMock(Database::class); @@ -58,7 +62,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertTrue($manager->userExists('foo')); @@ -74,14 +78,14 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->userExists('foo')); } public function testUserExistsNoBackends() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $this->assertFalse($manager->userExists('foo')); } @@ -105,7 +109,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -129,7 +133,7 @@ class ManagerTest extends TestCase { $backend2->expects($this->never()) ->method('userExists'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -156,7 +160,7 @@ class ManagerTest extends TestCase { } })); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $user = $manager->checkPassword('foo', 'bar'); @@ -175,7 +179,7 @@ class ManagerTest extends TestCase { ->method('implementsActions') ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->checkPassword('foo', 'bar')); @@ -193,7 +197,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals('foo', $manager->get('foo')->getUID()); @@ -209,7 +213,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals(null, $manager->get('foo')); @@ -227,7 +231,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID()); @@ -245,7 +249,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $result = $manager->search('fo'); @@ -279,7 +283,7 @@ class ManagerTest extends TestCase { $backend2->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -333,7 +337,7 @@ class ManagerTest extends TestCase { ->willReturn(true); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->expectException(\InvalidArgumentException::class, $exception); @@ -360,14 +364,14 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $user = $manager->createUser('foo', 'bar'); $this->assertEquals('foo', $user->getUID()); } - + public function testCreateUserSingleBackendExists() { $this->expectException(\Exception::class); @@ -387,7 +391,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $manager->createUser('foo', 'bar'); @@ -408,19 +412,19 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('userExists'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->createUser('foo', 'bar')); } public function testCreateUserNoBackends() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $this->assertFalse($manager->createUser('foo', 'bar')); } - + public function testCreateUserFromBackendWithBackendError() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Could not create user'); @@ -435,11 +439,11 @@ class ManagerTest extends TestCase { ->with('MyUid', 'MyPassword') ->willReturn(false); - $manager = new Manager($config, $this->dispatcher); + $manager = new Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->createUserFromBackend('MyUid', 'MyPassword', $backend); } - + public function testCreateUserTwoBackendExists() { $this->expectException(\Exception::class); @@ -475,7 +479,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -483,7 +487,7 @@ class ManagerTest extends TestCase { } public function testCountUsersNoBackend() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $result = $manager->countUsers(); $this->assertTrue(is_array($result)); @@ -508,7 +512,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $result = $manager->countUsers(); @@ -549,7 +553,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -650,21 +654,7 @@ class ManagerTest extends TestCase { } public function testDeleteUser() { - $config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $config - ->expects($this->at(0)) - ->method('getUserValue') - ->with('foo', 'core', 'enabled') - ->will($this->returnValue(true)); - $config - ->expects($this->at(1)) - ->method('getUserValue') - ->with('foo', 'login', 'lastLogin') - ->will($this->returnValue(0)); - - $manager = new \OC\User\Manager($config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $backend = new \Test\Util\User\Dummy(); $manager->registerBackend($backend); @@ -698,7 +688,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('uid2')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($config, $this->dispatcher); + $manager = new \OC\User\Manager($config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $users = $manager->getByEmail('test@example.com'); diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 3567aa9cf62..e7df7578c7d 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -228,7 +228,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -271,7 +275,7 @@ class SessionTest extends \Test\TestCase { $this->assertEquals($user, $userSession->getUser()); } - + public function testLoginValidPasswordDisabled() { $this->expectException(\OC\User\LoginException::class); @@ -290,11 +294,13 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); - $backend = $this->createMock(\Test\Util\User\Dummy::class); - $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('isEnabled') @@ -321,7 +327,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); @@ -404,7 +414,7 @@ class SessionTest extends \Test\TestCase { $userSession->login('foo', 'bar'); } - + public function testLogClientInNoTokenPasswordWith2fa() { $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); @@ -508,7 +518,7 @@ class SessionTest extends \Test\TestCase { $this->assertTrue($userSession->logClientIn('john', 'I-AM-AN-APP-PASSWORD', $request, $this->throttler)); } - + public function testLogClientInNoTokenPasswordNo2fa() { $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); @@ -560,7 +570,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -645,7 +659,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -705,7 +723,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -753,7 +775,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -973,7 +999,7 @@ class SessionTest extends \Test\TestCase { $this->assertFalse($userSession->createSessionToken($request, $uid, $loginName, $password)); } - + public function testTryTokenLoginWithDisabledUser() { $this->expectException(\OC\User\LoginException::class); |