예제 #1
0
 function testGetUser()
 {
     $path1 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/files/foo/bar.txt";
     $path2 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/cache/foo/bar.txt";
     $path3 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/thumbnails/foo";
     $path4 = "/" . "/" . self::TEST_ENCRYPTION_HELPER_USER1;
     // if we are logged-in every path should return the currently logged-in user
     $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path3));
     // now log out
     \Test_Encryption_Util::logoutHelper();
     // now we should only get the user from /user/files and user/cache paths
     $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path1));
     $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path2));
     $this->assertFalse(Encryption\Helper::getUser($path3));
     $this->assertFalse(Encryption\Helper::getUser($path4));
     // Log-in again
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
 }
예제 #2
0
 function testDeleteHooksForSharedFiles()
 {
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     // remember files_trashbin state
     $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
     // we want to tests with app files_trashbin disabled
     \OC_App::disable('files_trashbin');
     // make sure that the trash bin is disabled
     $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
     $this->user1View->file_put_contents($this->filename, $this->data);
     // check if all keys are generated
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // get the file info from previous created file
     $fileInfo = $this->user1View->getFileInfo($this->filename);
     // check if we have a valid file info
     $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
     // share the file with user2
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
     // check if new share key exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
     \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
     // user2 update the shared file
     $this->user2View->file_put_contents($this->filename, $this->data);
     // keys should be stored at user1s dir, not in user2s
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // delete the Shared file from user1 in data/user2/files/Shared
     $result = $this->user2View->unlink($this->filename);
     $this->assertTrue($result);
     // share key for user2 from user1s home should be gone, all other keys should still exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // cleanup
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     if ($stateFilesTrashbin) {
         OC_App::enable('files_trashbin');
     } else {
         OC_App::disable('files_trashbin');
     }
 }
예제 #3
0
파일: share.php 프로젝트: Combustible/core
 function testPublicShareFile()
 {
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // check if we have a valid file info
     $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
     // check if the unencrypted file size is stored
     $this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
     // re-enable the file proxy
     \OC_FileProxy::$enabled = $proxyStatus;
     // share the file
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, false, OCP\PERMISSION_ALL);
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     $publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');
     // check if share key for public exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
     // some hacking to simulate public link
     //$GLOBALS['app'] = 'files_sharing';
     //$GLOBALS['fileOwner'] = \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1;
     \Test_Encryption_Util::logoutHelper();
     // get file contents
     $retrievedCryptedFile = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // check if data is the same as we previously written
     $this->assertEquals($this->dataShort, $retrievedCryptedFile);
     // tear down
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     // unshare the file
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
     // check if share key not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
     // cleanup
     $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
     $this->view->unlink($this->filename);
     $this->view->chroot('/');
     // check if share key not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
 }
예제 #4
0
파일: helper.php 프로젝트: hjimmy/owncloud
 /**
  * Tests whether share keys can be found
  *
  * @dataProvider userNamesProvider
  */
 function testFindShareKeys($userName)
 {
     // note: not using dataProvider as we want to make
     // sure that the correct keys are match and not any
     // other ones that might happen to have similar names
     \Test_Encryption_Util::setupHooks();
     \Test_Encryption_Util::loginHelper($userName, true);
     $testDir = 'testFindShareKeys' . uniqid() . '/';
     $baseDir = $userName . '/files/' . $testDir;
     $fileList = array('t est.txt', 't est_.txt', 't est.doc.txt', 't est(.*).txt', 'multiple.dots.can.happen.too.txt', 't est.' . $userName . '.txt', 't est_.' . $userName . '.shareKey.txt', 'who would upload their.shareKey', 'user ones file.txt', 'user ones file.txt.backup', '.t est.txt');
     $rootView = new \OC\Files\View('/');
     $rootView->mkdir($baseDir);
     foreach ($fileList as $fileName) {
         $rootView->file_put_contents($baseDir . $fileName, 'dummy');
     }
     $shareKeysDir = $userName . '/files_encryption/share-keys/' . $testDir;
     foreach ($fileList as $fileName) {
         // make sure that every file only gets its correct respective keys
         $result = Encryption\Helper::findShareKeys($baseDir . $fileName, $shareKeysDir . $fileName, $rootView);
         $this->assertEquals(array($shareKeysDir . $fileName . '.' . $userName . '.shareKey'), $result);
     }
     // clean up
     $rootView->unlink($baseDir);
     \Test_Encryption_Util::logoutHelper();
     \OC_User::deleteUser($userName);
 }