예제 #1
0
 public function testGetAvatarValidUser()
 {
     $this->userManager->expects($this->once())->method('get')->with('validUser')->willReturn(true);
     $folder = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->once())->method('getUserFolder')->with('validUser')->willReturn($folder);
     $folder->expects($this->once())->method('getParent')->will($this->returnSelf());
     $this->avatarManager->getAvatar('validUser');
 }
예제 #2
0
 /**
  * @dataProvider usersProvider
  * @param $query
  * @param $uid
  */
 public function testImpersonate($query, $uid)
 {
     $user = $this->getMock('\\OCP\\IUser');
     $user->expects($this->once())->method('getUID')->will($this->returnValue($uid));
     $this->userManager->expects($this->once())->method('search')->with($query, 1, 0)->will($this->returnValue([$user]));
     $this->userSession->expects($this->once())->method('setUser')->with($user);
     $this->assertEquals(new JSONResponse(), $this->controller->impersonate($query));
 }
예제 #3
0
 public function testRunWithUsersAndOffsetAtEndOfUserList()
 {
     $this->config->expects($this->at(0))->method('getAppValue')->with('files', 'cronjob_scan_files', 0)->will($this->returnValue(50));
     $this->userManager->expects($this->at(0))->method('search')->with('', 500, 50)->will($this->returnValue([]));
     $this->userManager->expects($this->at(1))->method('search')->with('', 500)->will($this->returnValue([]));
     $this->config->expects($this->at(1))->method('setAppValue')->with('files', 'cronjob_scan_files', 500);
     $this->scanFiles->expects($this->never())->method('runScanner');
     $this->invokePrivate($this->scanFiles, 'run', [[]]);
 }
예제 #4
0
 public function testStartMigrationSuccessful()
 {
     $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());
 }
예제 #5
0
 /**
  * @dataProvider dataGetUsers
  *
  * @param string $searchTerm
  * @param bool $shareWithGroupOnly
  * @param bool $shareeEnumeration
  * @param array $groupResponse
  * @param array $userResponse
  * @param array $exactExpected
  * @param array $expected
  * @param bool $reachedEnd
  * @param mixed $singleUser
  */
 public function testGetUsers($searchTerm, $shareWithGroupOnly, $shareeEnumeration, $groupResponse, $userResponse, $exactExpected, $expected, $reachedEnd, $singleUser)
 {
     $this->invokePrivate($this->sharees, 'limit', [2]);
     $this->invokePrivate($this->sharees, 'offset', [0]);
     $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]);
     $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
     $user = $this->getUserMock('admin', 'Administrator');
     $this->session->expects($this->any())->method('getUser')->willReturn($user);
     if (!$shareWithGroupOnly) {
         $this->userManager->expects($this->once())->method('searchDisplayName')->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))->willReturn($userResponse);
     } else {
         if ($singleUser !== false) {
             $this->groupManager->expects($this->exactly(2))->method('getUserGroupIds')->withConsecutive($user, $singleUser)->willReturn($groupResponse);
         } else {
             $this->groupManager->expects($this->once())->method('getUserGroupIds')->with($user)->willReturn($groupResponse);
         }
         $this->groupManager->expects($this->exactly(sizeof($groupResponse)))->method('displayNamesInGroup')->with($this->anything(), $searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))->willReturnMap($userResponse);
     }
     if ($singleUser !== false) {
         $this->userManager->expects($this->once())->method('get')->with($searchTerm)->willReturn($singleUser);
     }
     $this->invokePrivate($this->sharees, 'getUsers', [$searchTerm]);
     $result = $this->invokePrivate($this->sharees, 'result');
     $this->assertEquals($exactExpected, $result['exact']['users']);
     $this->assertEquals($expected, $result['users']);
     $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
 }
 public function testCreatePublicity()
 {
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setType')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setAuthor')->with('author')->willReturnSelf();
     $event->expects($this->once())->method('setTimestamp')->with(1337)->willReturnSelf();
     $event->expects($this->once())->method('setSubject')->with('announcementsubject#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setMessage')->with('announcementmessage#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $event->expects($this->exactly(5))->method('setAffectedUser')->willReturnSelf();
     $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock();
     $notification->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $dateTime = new \DateTime();
     $dateTime->setTimestamp(1337);
     $notification->expects($this->once())->method('setDateTime')->with($dateTime)->willReturnSelf();
     $notification->expects($this->once())->method('setSubject')->with('announced', ['author'])->willReturnSelf();
     $notification->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $notification->expects($this->once())->method('setLink')->willReturnSelf();
     $notification->expects($this->exactly(4))->method('setUser')->willReturnSelf();
     $controller = $this->getController();
     $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event);
     $this->notificationManager->expects($this->once())->method('createNotification')->willReturn($notification);
     $this->userManager->expects($this->once())->method('search')->with('')->willReturn([$this->getUserMock('author', 'User One'), $this->getUserMock('u2', 'User Two'), $this->getUserMock('u3', 'User Three'), $this->getUserMock('u4', 'User Four'), $this->getUserMock('u5', 'User Five')]);
     $this->activityManager->expects($this->exactly(5))->method('publish');
     $this->notificationManager->expects($this->exactly(4))->method('notify');
     $this->invokePrivate($controller, 'createPublicity', [10, 'author', 1337]);
 }
예제 #7
0
	/**
	 * @expectedException \Sabre\DAV\Exception
	 * @expectedExceptionMessage Principal not found
	 */
	public function testGetGroupMembershipEmpty() {
		$this->userManager
			->expects($this->once())
			->method('get')
			->with('foo')
			->will($this->returnValue(null));

		$this->connector->getGroupMembership('principals/foo');
	}
예제 #8
0
 /**
  * @dataProvider dataFormat
  *
  * @param string $parameter
  * @param null|\OCP\IUser $user
  * @param bool $avatarsEnabled
  * @param bool $allowHtml
  * @param bool $verbose
  * @param string $expected
  */
 public function testFormat($parameter, $user, $avatarsEnabled, $allowHtml, $verbose, $expected)
 {
     /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $this->l->expects($this->never())->method('t');
     $this->userManager->expects($this->once())->method('get')->with($parameter)->willReturn($user);
     $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($avatarsEnabled);
     $formatter = $this->getFormatter();
     $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose));
 }
예제 #9
0
 public function testGetUserSubAdminGroupsWithoutGroups()
 {
     $targetUser = $this->getMock('\\OCP\\IUser');
     $this->userManager->expects($this->once())->method('get')->with('RequestedUser')->will($this->returnValue($targetUser));
     $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock();
     $subAdminManager->expects($this->once())->method('getSubAdminsGroups')->with($targetUser)->will($this->returnValue([]));
     $this->groupManager->expects($this->once())->method('getSubAdmin')->will($this->returnValue($subAdminManager));
     $expected = new \OC_OCS_Result(null, 102, 'Unknown error occurred');
     $this->assertEquals($expected, $this->api->getUserSubAdminGroups(['userid' => 'RequestedUser']));
 }
예제 #10
0
 public function testShowLoginFormForUserNamedNull()
 {
     $this->userSession->expects($this->once())->method('isLoggedIn')->willReturn(false);
     $this->config->expects($this->once())->method('getSystemValue')->with('lost_password_link')->willReturn(false);
     $user = $this->getMock('\\OCP\\IUser');
     $user->expects($this->once())->method('canChangePassword')->willReturn(false);
     $this->userManager->expects($this->once())->method('get')->with('0')->willReturn($user);
     $expectedResponse = new TemplateResponse('core', 'login', ['messages' => [], 'loginName' => '0', 'user_autofocus' => false, 'canResetPassword' => false, 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0], 'guest');
     $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('0', '', ''));
 }
예제 #11
0
 public function testRun()
 {
     $cat1 = $this->addTagCategory('TestRepairCleanTags', 'files');
     // Retained
     $cat2 = $this->addTagCategory('TestRepairCleanTags2', 'files');
     // Deleted: Category will be empty
     $this->addTagCategory('TestRepairCleanTags3', 'files');
     // Deleted: Category is empty
     $cat3 = $this->addTagCategory('TestRepairCleanTags', 'contacts');
     // Retained
     $this->addTagEntry($this->getFileID(), $cat2, 'files');
     // Retained
     $this->addTagEntry($this->getFileID() + 1, $cat1, 'files');
     // Deleted: File is NULL
     $this->addTagEntry(9999999, $cat3, 'contacts');
     // Retained
     $this->addTagEntry($this->getFileID(), $cat3 + 1, 'files');
     // Deleted: Category is NULL
     $this->assertEntryCount('vcategory_to_object', 4, 'Assert tag entries count before repair step');
     $this->assertEntryCount('vcategory', 4, 'Assert tag categories count before repair step');
     self::invokePrivate($this->repair, 'deleteOrphanFileEntries', [$this->outputMock]);
     $this->assertEntryCount('vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
     $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning file entries');
     self::invokePrivate($this->repair, 'deleteOrphanTagEntries', [$this->outputMock]);
     $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
     $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning tag entries');
     self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries', [$this->outputMock]);
     $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
     $this->assertEntryCount('vcategory', 2, 'Assert tag categories count after cleaning category entries');
     $this->addTagCategory('TestRepairCleanTags', 'contacts', 'userExists');
     // Retained
     $this->assertEntryCount('vcategory', 3, 'Assert tag categories count before cleaning categories by users');
     $this->userManager->expects($this->exactly(2))->method('userExists')->willReturnMap([['userExists', true], ['TestRepairCleanTags', false]]);
     self::invokePrivate($this->repair, 'deleteOrphanTags', [$this->outputMock]);
     $this->assertEntryCount('vcategory', 1, 'Assert tag categories count after cleaning categories by users');
 }
 /**
  * test updatePrivateKeyPassword() with the correct old and new password
  */
 public function testUpdatePrivateKeyPassword()
 {
     $oldPassword = '******';
     $newPassword = '******';
     $this->ocSessionMock->expects($this->once())->method('get')->with('loginname')->willReturn('testUser');
     $this->userManagerMock->expects($this->at(0))->method('checkPassword')->with('testUserUid', 'new')->willReturn(false);
     $this->userManagerMock->expects($this->at(1))->method('checkPassword')->with('testUser', 'new')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('decryptPrivateKey')->willReturn('decryptedKey');
     $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->willReturn('encryptedKey');
     $this->cryptMock->expects($this->once())->method('generateHeader')->willReturn('header.');
     // methods which must be called after successful changing the key password
     $this->keyManagerMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('testUserUid'), $this->equalTo('header.encryptedKey'));
     $this->sessionMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('decryptedKey'));
     $this->sessionMock->expects($this->once())->method('setStatus')->with($this->equalTo(Session::INIT_SUCCESSFUL));
     $result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword);
     $data = $result->getData();
     $this->assertSame(Http::STATUS_OK, $result->getStatus());
     $this->assertSame('Private key password successfully updated.', $data['message']);
 }
 public function testSendEmailToUser()
 {
     $maxTime = 200;
     $user = '******';
     $userDisplayName = 'user two';
     $email = $user . '@localhost';
     $this->mailer->expects($this->once())->method('send')->with($this->message);
     $this->message->expects($this->once())->method('setTo')->with([$email => $userDisplayName]);
     $this->message->expects($this->once())->method('setSubject');
     $this->message->expects($this->once())->method('setPlainBody');
     $this->message->expects($this->once())->method('setFrom');
     $userObject = $this->getMock('OCP\\IUser');
     $userObject->expects($this->any())->method('getDisplayName')->willReturn($userDisplayName);
     $this->userManager->expects($this->any())->method('get')->willReturnMap([[$user, $userObject], [$user . $user, null]]);
     $users = $this->mailQueueHandler->getAffectedUsers(1, $maxTime);
     $this->assertEquals([$user], $users);
     $this->mailQueueHandler->sendEmailToUser($user, $email, 'en', 'UTC', $maxTime);
     // Invalid user, no object no email
     $this->mailQueueHandler->sendEmailToUser($user . $user, $email, 'en', 'UTC', $maxTime);
 }
예제 #14
0
 public function testUpdateShareUser()
 {
     $this->userManager->expects($this->any())->method('userExists')->willReturn(true);
     $manager = $this->createManagerMock()->setMethods(['canShare', 'getShareById', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])->getMock();
     $originalShare = $this->manager->newShare();
     $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith('origUser')->setPermissions(1);
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->method('getId')->willReturn(100);
     $node->method('getPath')->willReturn('/newUser/files/myPath');
     $manager->expects($this->once())->method('canShare')->willReturn(true);
     $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
     $share = $this->manager->newShare();
     $share->setProviderId('foo')->setId('42')->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith('origUser')->setShareOwner('newUser')->setSharedBy('sharer')->setPermissions(31)->setNode($node);
     $this->defaultProvider->expects($this->once())->method('update')->with($share)->willReturn($share);
     $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
     \OCP\Util::connectHook('OCP\\Share', 'post_set_expiration_date', $hookListner, 'post');
     $hookListner->expects($this->never())->method('post');
     $this->rootFolder->method('getUserFolder')->with('newUser')->will($this->returnSelf());
     $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath');
     $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
     \OCP\Util::connectHook('OCP\\Share', 'post_update_permissions', $hookListner2, 'post');
     $hookListner2->expects($this->once())->method('post')->with(['itemType' => 'file', 'itemSource' => 100, 'shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'origUser', 'uidOwner' => 'sharer', 'permissions' => 31, 'path' => '/myPath']);
     $manager->updateShare($share);
 }