Exemplo n.º 1
0
 /**
  * test if all keys get moved to the backup folder correctly
  */
 function testBackupAllKeys()
 {
     self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1);
     // create some dummy key files
     $encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption';
     $this->view->file_put_contents($encPath . '/keyfiles/foo.key', 'key');
     $this->view->file_put_contents($encPath . '/share-keys/foo.user1.shareKey', 'share key');
     $util = new \OCA\Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
     $util->backupAllKeys('testing');
     $encFolderContent = $this->view->getDirectoryContent($encPath);
     $backupPath = '';
     foreach ($encFolderContent as $c) {
         $name = $c['name'];
         if (substr($name, 0, strlen('backup')) === 'backup') {
             $backupPath = $encPath . '/' . $c['name'];
             break;
         }
     }
     $this->assertTrue($backupPath !== '');
     // check backupDir Content
     $this->assertTrue($this->view->is_dir($backupPath . '/keyfiles'));
     $this->assertTrue($this->view->is_dir($backupPath . '/share-keys'));
     $this->assertTrue($this->view->file_exists($backupPath . '/keyfiles/foo.key'));
     $this->assertTrue($this->view->file_exists($backupPath . '/share-keys/foo.user1.shareKey'));
     $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.private.key'));
     $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.public.key'));
     //cleanup
     $this->view->deleteAll($backupPath);
     $this->view->unlink($encPath . '/keyfiles/foo.key', 'key');
     $this->view->unlink($encPath . '/share-keys/foo.user1.shareKey', 'share key');
 }
Exemplo n.º 2
0
 /**
  * test deletion of a folder which contains share mount points. Share mount
  * points should be unshared before the folder gets deleted so
  * that the mount point doesn't end up at the trash bin
  */
 function testDeleteParentFolder()
 {
     $status = \OC_App::isEnabled('files_trashbin');
     \OC_App::enable('files_trashbin');
     \OCA\Files_Trashbin\Trashbin::registerHooks();
     OC_FileProxy::register(new OCA\Files\Share\Proxy());
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
     \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // check if user2 can see the shared folder
     $this->assertTrue($view->file_exists($this->folder));
     $foldersShared = \OCP\Share::getItemsSharedWith('folder');
     $this->assertSame(1, count($foldersShared));
     $view->mkdir("localFolder");
     $view->file_put_contents("localFolder/localFile.txt", "local file");
     $view->rename($this->folder, 'localFolder/' . $this->folder);
     // share mount point should now be moved to the subfolder
     $this->assertFalse($view->file_exists($this->folder));
     $this->assertTrue($view->file_exists('localFolder/' . $this->folder));
     $view->unlink('localFolder');
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // shared folder should be unshared
     $foldersShared = \OCP\Share::getItemsSharedWith('folder');
     $this->assertTrue(empty($foldersShared));
     // trashbin should contain the local file but not the mount point
     $rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     $dirContent = $rootView->getDirectoryContent('files_trashbin/files');
     $this->assertSame(1, count($dirContent));
     $firstElement = reset($dirContent);
     $ext = pathinfo($firstElement['path'], PATHINFO_EXTENSION);
     $this->assertTrue($rootView->file_exists('files_trashbin/files/localFolder.' . $ext . '/localFile.txt'));
     $this->assertFalse($rootView->file_exists('files_trashbin/files/localFolder.' . $ext . '/' . $this->folder));
     //cleanup
     $rootView->deleteAll('files_trashin');
     if ($status === false) {
         \OC_App::disable('files_trashbin');
     }
 }
Exemplo n.º 3
0
 public function testUTF8Names()
 {
     $names = array('虚', '和知しゃ和で', 'regular ascii', 'sɨˈrɪlɪk', 'ѨѬ', 'أنا أحب القراءة كثيرا');
     $storage = new \OC\Files\Storage\Temporary(array());
     \OC\Files\Filesystem::mount($storage, array(), '/');
     $rootView = new \OC\Files\View('');
     foreach ($names as $name) {
         $rootView->file_put_contents('/' . $name, 'dummy content');
     }
     $list = $rootView->getDirectoryContent('/');
     $this->assertCount(count($names), $list);
     foreach ($list as $item) {
         $this->assertContains($item['name'], $names);
     }
     $cache = $storage->getCache();
     $scanner = $storage->getScanner();
     $scanner->scan('');
     $list = $cache->getFolderContents('');
     $this->assertCount(count($names), $list);
     foreach ($list as $item) {
         $this->assertContains($item['name'], $names);
     }
 }
Exemplo n.º 4
0
 /**
  * @param string $filter
  * @param string[] $expected
  * @dataProvider mimeFilterProvider
  */
 public function testGetDirectoryContentMimeFilter($filter, $expected)
 {
     $storage1 = new Temporary();
     $root = $this->getUniqueID('/');
     \OC\Files\Filesystem::mount($storage1, array(), $root . '/');
     $view = new \OC\Files\View($root);
     $view->file_put_contents('test1.txt', 'asd');
     $view->file_put_contents('test2.txt', 'asd');
     $view->file_put_contents('test3.md', 'asd');
     $view->file_put_contents('test4.png', '');
     $content = $view->getDirectoryContent('', $filter);
     $files = array_map(function (FileInfo $info) {
         return $info->getName();
     }, $content);
     sort($files);
     $this->assertEquals($expected, $files);
 }
Exemplo n.º 5
0
 function testGetFolderContentsWhenSubSubdirShared()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $fileinfo = $this->view->getFileInfo('container/shareddir/subdir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $thirdView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $results = $thirdView->getDirectoryContent('/subdir');
     $this->verifyFiles(array(array('name' => 'another too.txt', 'path' => 'another too.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'another.txt', 'path' => 'another.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'not a text file.xml', 'path' => 'not a text file.xml', 'mimetype' => 'application/xml', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One')), $results);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3);
 }
Exemplo n.º 6
0
 /**
  * check if a backup from the encryption keys exists
  *
  * @return boolean
  */
 public static function backupKeysExists()
 {
     //check if encryption was enabled in the past
     $backupExists = false;
     if (OC_App::isEnabled('files_encryption') === false) {
         $view = new OC\Files\View('/' . OCP\User::getUser());
         $backupPath = '/files_encryption/keyfiles.backup';
         if ($view->is_dir($backupPath)) {
             $dircontent = $view->getDirectoryContent($backupPath);
             if (!empty($dircontent)) {
                 $backupExists = true;
             }
         }
     }
     return $backupExists;
 }
Exemplo n.º 7
0
 /**
  * get share from all files in a given folder (non-recursive)
  * @param array $params contains 'path' to the folder
  * @return \OC_OCS_Result
  */
 private static function getSharesFromFolder($params)
 {
     $path = $params['path'];
     $view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files');
     if (!$view->is_dir($path)) {
         return new \OC_OCS_Result(null, 400, "not a directory");
     }
     $content = $view->getDirectoryContent($path);
     $result = array();
     foreach ($content as $file) {
         // workaround because folders are named 'dir' in this context
         $itemType = $file['type'] === 'file' ? 'file' : 'folder';
         $share = \OCP\Share::getItemShared($itemType, $file['fileid']);
         if ($share) {
             $receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']);
             reset($share);
             $key = key($share);
             if ($receivedFrom) {
                 $share[$key]['received_from'] = $receivedFrom['uid_owner'];
                 $share[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
             }
             $result = array_merge($result, $share);
         }
     }
     return new \OC_OCS_Result($result);
 }
Exemplo n.º 8
0
 /**
  * @brief check if trash bin is empty for a given user
  * @param string $user
  */
 public static function isEmpty($user)
 {
     $view = new \OC\Files\View('/' . $user . '/files_trashbin');
     $content = $view->getDirectoryContent('/files');
     if ($content) {
         return false;
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * returns all stored file versions from a given user
  * @param string $uid id of the user
  * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename
  */
 private static function getAllVersions($uid)
 {
     $view = new \OC\Files\View('/' . $uid . '/');
     $dirs = array(self::VERSIONS_ROOT);
     $versions = array();
     while (!empty($dirs)) {
         $dir = array_pop($dirs);
         $files = $view->getDirectoryContent($dir);
         foreach ($files as $file) {
             if ($file['type'] === 'dir') {
                 array_push($dirs, $file['path']);
             } else {
                 $versionsBegin = strrpos($file['path'], '.v');
                 $relPathStart = strlen(self::VERSIONS_ROOT);
                 $version = substr($file['path'], $versionsBegin + 2);
                 $relpath = substr($file['path'], $relPathStart, $versionsBegin - $relPathStart);
                 $key = $version . '#' . $relpath;
                 $versions[$key] = array('path' => $relpath, 'timestamp' => $version);
             }
         }
     }
     // newest version first
     krsort($versions);
     $result = array();
     foreach ($versions as $key => $value) {
         $size = $view->filesize(self::VERSIONS_ROOT . '/' . $value['path'] . '.v' . $value['timestamp']);
         $filename = $value['path'];
         $result['all'][$key]['version'] = $value['timestamp'];
         $result['all'][$key]['path'] = $filename;
         $result['all'][$key]['size'] = $size;
         $result['by_file'][$filename][$key]['version'] = $value['timestamp'];
         $result['by_file'][$filename][$key]['path'] = $filename;
         $result['by_file'][$filename][$key]['size'] = $size;
     }
     return $result;
 }
Exemplo n.º 10
0
 function testGetFolderContentsWhenSubSubdirShared()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
     $node = $rootFolder->get('container/shareddir/subdir');
     $share = $this->shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER3)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $share = $this->shareManager->createShare($share);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $thirdView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $results = $thirdView->getDirectoryContent('/subdir');
     $this->verifyFiles(array(array('name' => 'another too.txt', 'path' => 'another too.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'another.txt', 'path' => 'another.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'not a text file.xml', 'path' => 'not a text file.xml', 'mimetype' => 'application/xml', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One')), $results);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->shareManager->deleteShare($share);
 }
Exemplo n.º 11
0
Arquivo: view.php Projeto: evanjt/core
 /**
  * Test rename operation: unlock first path when second path was locked
  */
 public function testGetOwner()
 {
     $this->loginAsUser('test');
     $view = new \OC\Files\View('/test/files/');
     $path = 'foo.txt';
     $view->file_put_contents($path, 'meh');
     $this->assertEquals('test', $view->getFileInfo($path)->getOwner()->getUID());
     $folderInfo = $view->getDirectoryContent('');
     $folderInfo = array_values(array_filter($folderInfo, function (FileInfo $info) {
         return $info->getName() === 'foo.txt';
     }));
     $this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
     $subStorage = new Temporary();
     \OC\Files\Filesystem::mount($subStorage, [], '/test/files/asd');
     $folderInfo = $view->getDirectoryContent('');
     $folderInfo = array_values(array_filter($folderInfo, function (FileInfo $info) {
         return $info->getName() === 'asd';
     }));
     $this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
 }
Exemplo n.º 12
0
 private function countUserDirectories()
 {
     $dataview = new \OC\Files\View('/');
     $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory');
     return count($userDirectories);
 }
Exemplo n.º 13
0
 private static function getOC7FileList($user, $path, $onlyID, $indexed)
 {
     $result = array();
     $dirView = new \OC\Files\View('/' . $user);
     $dirContent = $dirView->getDirectoryContent($path);
     foreach ($dirContent as $item) {
         $fileID = $item->getId();
         $fileMime = $item->getMimetype();
         $fileName = $item->getName();
         $filePath = substr($item->getPath(), strlen($user) + 2);
         $itemRes = array();
         if (strpos($fileMime, 'directory') === FALSE) {
             $fileData = array('fileid' => $fileID, 'name' => $fileName, 'mimetype' => $fileMime, 'path' => $filePath);
             $itemRes[] = $onlyID ? $fileID : $fileData;
         } else {
             $itemRes = \OCA\OCLife\utilities::getOC7FileList($user, $filePath, $onlyID, $indexed);
         }
         foreach ($itemRes as $item) {
             if ($onlyID) {
                 $result[] = intval($item);
             } else {
                 if ($indexed) {
                     $result[intval($item['fileid'])] = $item;
                 } else {
                     $result[] = $item;
                 }
             }
         }
     }
     return $result;
 }