/**
  * @expectedException \Exception
  * @expectedExceptionMessage $filePath is not under the \OC::$SERVERROOT
  */
 public function testInvalidConvertToRelativePath()
 {
     $invalidFile = '/this/file/is/invalid';
     $_SERVER['REQUEST_URI'] = $invalidFile;
     $_SERVER['SCRIPT_NAME'] = '/';
     \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($invalidFile));
 }
 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('*PREFIX*vcategory_to_object', 4, 'Assert tag entries count before repair step');
     $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count before repair step');
     \Test_Helper::invokePrivate($this->repair, 'deleteOrphanFileEntries');
     $this->assertEntryCount('*PREFIX*vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
     $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning file entries');
     \Test_Helper::invokePrivate($this->repair, 'deleteOrphanTagEntries');
     $this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
     $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning tag entries');
     \Test_Helper::invokePrivate($this->repair, 'deleteOrphanCategoryEntries');
     $this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
     $this->assertEntryCount('*PREFIX*vcategory', 2, 'Assert tag categories count after cleaning category entries');
 }
 public function testGetFilenameForDownload()
 {
     $timestamp = 42;
     $this->container['Config']->expects($this->once())->method('getSystemValue')->with('instanceid')->will($this->returnValue('0xF'));
     $filename = \Test_Helper::invokePrivate($this->logSettingsController, 'getFilenameForDownload', [$timestamp]);
     $this->assertSame('ownCloud-0xF-42.log', $filename);
 }
 /**
  *
  */
 public function testRegisterHooksWithInstance()
 {
     $mock = $this->getMockBuilder('OCA\\Encryption\\Hooks\\Contracts\\IHook')->disableOriginalConstructor()->getMock();
     self::$instance->registerHook($mock);
     $hookInstances = \Test_Helper::invokePrivate(self::$instance, 'hookInstances');
     $this->assertCount(3, $hookInstances);
 }
 public function testRunStep()
 {
     $mailQueueHandler = $this->getMockBuilder('OCA\\Activity\\MailQueueHandler')->disableOriginalConstructor()->getMock();
     $config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $backgroundJob = new EmailNotification($mailQueueHandler, $config, $this->getMock('OCP\\ILogger'), true);
     $mailQueueHandler->expects($this->any())->method('getAffectedUsers')->with(2, 200)->willReturn(['test1', 'test2']);
     $mailQueueHandler->expects($this->any())->method('getItemsForUsers')->willReturn(['test1' => [], 'test2' => []]);
     $mailQueueHandler->expects($this->once())->method('sendEmailToUser')->with('test1', 'test1@localhost', 'de', date_default_timezone_get(), $this->anything());
     $config->expects($this->any())->method('getUserValueForUsers')->willReturnMap([['settings', 'email', ['test1', 'test2'], ['test1' => 'test1@localhost', 'test2' => '']], ['core', 'lang', ['test1', 'test2'], ['test1' => 'de', 'test2' => 'en']]]);
     $this->assertEquals(2, \Test_Helper::invokePrivate($backgroundJob, 'runStep', [2, 200]));
 }
Beispiel #6
0
 /**
  * @dataProvider mailAddressProvider
  */
 public function testConvertAddresses($unconverted, $expected)
 {
     $this->assertSame($expected, \Test_Helper::invokePrivate($this->message, 'convertAddresses', array($unconverted)));
 }
Beispiel #7
0
 /**
  * @dataProvider urls
  */
 function testRemoveProtocolFromUrl($url, $expectedResult)
 {
     $share = new \OC\Share\Share();
     $result = \Test_Helper::invokePrivate($share, 'removeProtocolFromUrl', array($url));
     $this->assertSame($expectedResult, $result);
 }
Beispiel #8
0
 public function testGetProxyUriProxyHostWithPassword()
 {
     $this->config->expects($this->at(0))->method('getSystemValue')->with('proxy', null)->willReturn('foo');
     $this->config->expects($this->at(1))->method('getSystemValue')->with('proxyuserpwd', null)->willReturn('username:password');
     $this->assertSame('username:password@foo', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
 }
Beispiel #9
0
 /**
  * This is actual more an integration test whether the version parameter in the .htaccess
  * was updated as well when the version has been incremented.
  * If it hasn't this test will fail.
  */
 public function testHtaccessIsCurrent()
 {
     $result = Test_Helper::invokePrivate($this->setupClass, 'isCurrentHtaccess');
     $this->assertTrue($result);
 }
 public function testDeletePrivateKey()
 {
     $this->keyStorageMock->expects($this->once())->method('deleteUserKey')->with('user1', 'privateKey')->willReturn(true);
     $this->assertTrue(\Test_Helper::invokePrivate($this->instance, 'deletePrivateKey', [$this->userId]));
 }
Beispiel #11
0
 public function testGeneratePathTraversal()
 {
     $logger = $this->getMock('\\Test\\NullLogger');
     $tmpManager = \Test_Helper::invokePrivate($this->getManager($logger), 'generatePath', ['../Traversal\\../FileName']);
     $this->assertStringEndsNotWith('./Traversal\\../FileName', $tmpManager);
     $this->assertStringEndsWith('.Traversal..FileName', $tmpManager);
 }
 public function testGetAppStoreUrl()
 {
     $this->config->expects($this->once())->method('getSystemValue')->with('appstoreurl', 'https://api.owncloud.com/v1')->will($this->returnValue('https://api.owncloud.com/v1'));
     $this->assertSame('https://api.owncloud.com/v1', Test_Helper::invokePrivate($this->ocsClient, 'getAppStoreUrl'));
 }
Beispiel #13
0
 /**
  * @dataProvider isExcludedPathProvider
  */
 function testIsExcludedPath($path, $expected)
 {
     $this->view->mkdir(dirname($path));
     $this->view->file_put_contents($path, "test");
     $result = \Test_Helper::invokePrivate(new \OCA\Files_Encryption\Proxy(), 'isExcludedPath', array($path));
     $this->assertSame($expected, $result);
     $this->view->deleteAll(dirname($path));
 }
Beispiel #14
0
 public function testReleaseAll()
 {
     $this->assertTrue(\Test_Helper::invokePrivate($this->fileLock, 'releaseAll'));
 }
Beispiel #15
0
 public function testRecoverFile()
 {
     $this->keyManagerMock->expects($this->once())->method('getEncryptedFileKey')->willReturn(true);
     $this->keyManagerMock->expects($this->once())->method('getShareKey')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->willReturn(true);
     $this->fileMock->expects($this->once())->method('getAccessList')->willReturn(['users' => ['admin']]);
     $this->keyManagerMock->expects($this->once())->method('getPublicKey')->willReturn('publicKey');
     $this->keyManagerMock->expects($this->once())->method('addSystemKeys')->willReturn(['admin' => 'publicKey']);
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt');
     $this->keyManagerMock->expects($this->once())->method('setAllFileKeys');
     $this->assertNull(\Test_Helper::invokePrivate($this->instance, 'recoverFile', ['/', 'testkey']));
 }
Beispiel #16
0
 public function testKeySetPreparation()
 {
     $this->view->expects($this->any())->method('file_exists')->willReturn(false);
     $this->view->expects($this->any())->method('is_dir')->willReturn(false);
     $this->view->expects($this->any())->method('mkdir')->will($this->returnCallback(array($this, 'mkdirCallback')));
     $this->mkdirStack = array('/user1/files_encryption/keys/foo', '/user1/files_encryption/keys', '/user1/files_encryption', '/user1');
     \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
 }
 /**
  * @expectedException \UnexpectedValueException
  * @dataProvider getUserFromTokenThrowInvalidTokenData
  *
  * @param string $token
  * @param array $users
  */
 public function testGetUserFromTokenThrowInvalidToken($token, $users)
 {
     $this->mockRSSToken($token, $token, $users);
     \Test_Helper::invokePrivate($this->activityManager, 'getUserFromToken');
 }
Beispiel #18
0
 /**
  * @dataProvider hookPathProvider
  * @param $root
  * @param $path
  * @param $shouldEmit
  */
 public function testHookPaths($root, $path, $shouldEmit)
 {
     $filesystemReflection = new \ReflectionClass('\\OC\\Files\\Filesystem');
     $defaultRootValue = $filesystemReflection->getProperty('defaultInstance');
     $defaultRootValue->setAccessible(true);
     $oldRoot = $defaultRootValue->getValue();
     $defaultView = new \OC\Files\View('/foo/files');
     $defaultRootValue->setValue($defaultView);
     $view = new \OC\Files\View($root);
     $result = \Test_Helper::invokePrivate($view, 'shouldEmitHooks', [$path]);
     $defaultRootValue->setValue($oldRoot);
     $this->assertEquals($shouldEmit, $result);
 }
 public function testGetOverwriteHostWithOverwrite()
 {
     $this->config->expects($this->at(0))->method('getSystemValue')->with('overwritehost')->will($this->returnValue('www.owncloud.org'));
     $this->config->expects($this->at(1))->method('getSystemValue')->with('overwritecondaddr')->will($this->returnValue(''));
     $this->config->expects($this->at(2))->method('getSystemValue')->with('overwritehost')->will($this->returnValue('www.owncloud.org'));
     $request = new Request([], $this->secureRandom, $this->config, $this->stream);
     $this->assertSame('www.owncloud.org', \Test_Helper::invokePrivate($request, 'getOverwriteHost'));
 }
 /**
  * @dataProvider postParameters
  */
 public function testassemblePostParameters($parameterList, $expectedResult)
 {
     $helper = \OC::$server->getHTTPHelper();
     $result = \Test_Helper::invokePrivate($helper, 'assemblePostParameters', array($parameterList));
     $this->assertSame($expectedResult, $result);
 }
 public function testIsSharingEnabledWithSharingDisabled()
 {
     $this->appManager->expects($this->once())->method('isEnabledForUser')->with('files_sharing')->will($this->returnValue(true));
     $this->config->expects($this->once())->method('getAppValue')->with('core', 'shareapi_allow_links', 'yes')->will($this->returnValue('no'));
     $this->assertFalse(\Test_Helper::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
 }
Beispiel #22
0
 public function testAddShare()
 {
     $shareData1 = ['remote' => 'http://localhost', 'token' => 'token1', 'password' => '', 'name' => '/SharedFolder', 'owner' => 'foobar', 'accepted' => false, 'user' => $this->uid];
     $shareData2 = $shareData1;
     $shareData2['token'] = 'token2';
     $shareData3 = $shareData1;
     $shareData3['token'] = 'token3';
     // Add a share for "user"
     $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData1));
     $openShares = $this->manager->getOpenShares();
     $this->assertCount(1, $openShares);
     $this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertNotMount('SharedFolder');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     // Add a second share for "user" with the same name
     $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData2));
     $openShares = $this->manager->getOpenShares();
     $this->assertCount(2, $openShares);
     $this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     // New share falls back to "-1" appendix, because the name is already taken
     $this->assertExternalShareEntry($shareData2, $openShares[1], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertNotMount('SharedFolder');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
     // Accept the first share
     $this->manager->acceptShare($openShares[0]['id']);
     // Check remaining shares - Accepted
     $acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]);
     $this->assertCount(1, $acceptedShares);
     $shareData1['accepted'] = true;
     $this->assertExternalShareEntry($shareData1, $acceptedShares[0], 1, $shareData1['name']);
     // Check remaining shares - Open
     $openShares = $this->manager->getOpenShares();
     $this->assertCount(1, $openShares);
     $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertMount($shareData1['name']);
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
     // Add another share for "user" with the same name
     $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData3));
     $openShares = $this->manager->getOpenShares();
     $this->assertCount(2, $openShares);
     $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
     // New share falls back to the original name (no "-\d", because the name is not taken)
     $this->assertExternalShareEntry($shareData3, $openShares[1], 3, '{{TemporaryMountPointName#' . $shareData3['name'] . '}}');
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertMount($shareData1['name']);
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
     // Decline the third share
     $this->manager->declineShare($openShares[1]['id']);
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertMount($shareData1['name']);
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
     // Check remaining shares - Accepted
     $acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]);
     $this->assertCount(1, $acceptedShares);
     $shareData1['accepted'] = true;
     $this->assertExternalShareEntry($shareData1, $acceptedShares[0], 1, $shareData1['name']);
     // Check remaining shares - Open
     $openShares = $this->manager->getOpenShares();
     $this->assertCount(1, $openShares);
     $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertMount($shareData1['name']);
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
     $this->manager->removeUserShares($this->uid);
     $this->assertEmpty(\Test_Helper::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');
     $this->mountManager->clear();
     \Test_Helper::invokePrivate($this->manager, 'setupMounts');
     $this->assertNotMount($shareData1['name']);
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
     $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
 }
Beispiel #23
0
 /**
  * @dataProvider getLangForApproximatedTimeFrameData
  * @param int $time
  * @param int $expected
  */
 public function testGetLangForApproximatedTimeFrame($time, $expected)
 {
     $this->assertEquals($expected, \Test_Helper::invokePrivate($this->mailQueueHandler, 'getLangForApproximatedTimeFrame', [$time]), 'Failed asserting to receive the right timeframe');
 }
 /**
  * @dataProvider dataProviderForTestGetPathToRealFile
  */
 public function testGetPathToRealFile($path, $expected)
 {
     $this->assertSame($expected, \Test_Helper::invokePrivate($this->instance, 'getPathToRealFile', array($path)));
 }
Beispiel #25
0
 /**
  * @dataProvider versionHashProvider
  */
 function testSplitHash($hash, $expected)
 {
     $relativePath = \Test_Helper::invokePrivate($this->hasher, 'splitHash', array($hash));
     $this->assertSame($expected, $relativePath);
 }
Beispiel #26
0
 public function testGetInstanceSendmail()
 {
     $this->config->expects($this->any())->method('getSystemValue')->will($this->returnValue('sendmail'));
     $this->assertInstanceOf('\\Swift_SendmailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
 }
Beispiel #27
0
 /**
  * test decrypt()
  *
  * @depends testEncrypt
  */
 public function testDecrypt($data)
 {
     $result = \Test_Helper::invokePrivate($this->crypt, 'decrypt', array($data['encrypted'], $data['iv'], $data['password']));
     $this->assertSame($data['decrypted'], $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('files_encryption'))->will($this->returnValue(true));
     $this->container['Config']->expects($this->once())->method('getAppValue')->with($this->equalTo('files_encryption'), $this->equalTo('recoveryAdminEnabled'), $this->anything())->will($this->returnValue('1'));
     $this->container['Config']->expects($this->at(1))->method('getUserValue')->with($this->anything(), $this->equalTo('files_encryption'), $this->equalTo('recovery_enabled'), $this->anything())->will($this->returnValue('0'));
     $expectedResult['isRestoreDisabled'] = true;
     $result = \Test_Helper::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
     $this->assertEquals($expectedResult, $result);
 }
 /**
  * @dataProvider providesValidPosixPaths
  */
 public function testPathVerificationValidPaths($fileName)
 {
     $storage = new Local(['datadir' => '']);
     \Test_Helper::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
     \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
     // nothing thrown
     $this->assertTrue(true);
 }
 public function testIsMemcacheConfiguredTrue()
 {
     $this->config->expects($this->once())->method('getSystemValue')->with('memcache.local', null)->will($this->returnValue('SomeProvider'));
     $this->assertTrue(\Test_Helper::invokePrivate($this->checkSetupController, 'isMemcacheConfigured'));
 }