Example #1
0
 /**
  * test set and get share folder
  */
 function testSetGetShareFolder()
 {
     $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder());
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared');
     $this->assertSame('/Shared', \OCA\Files_Sharing\Helper::getShareFolder());
     // cleanup
     \OCP\Config::deleteSystemValue('share_folder');
 }
Example #2
0
 /**
  * test set and get share folder
  */
 function testSetGetShareFolder()
 {
     $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder());
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared/Folder');
     $sharedFolder = \OCA\Files_Sharing\Helper::getShareFolder();
     $this->assertSame('/Shared/Folder', \OCA\Files_Sharing\Helper::getShareFolder());
     $this->assertTrue(\OC\Files\Filesystem::is_dir($sharedFolder));
     // cleanup
     \OCP\Config::deleteSystemValue('share_folder');
 }
Example #3
0
 /**
  * @medium
  * Test that data that is written by the crypto stream wrapper with AES 128
  * @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
  * @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
  * reassembly of its data
  */
 public function testStreamDecryptLongFileContentWithoutHeader()
 {
     // Generate a a random filename
     $filename = 'tmp-' . $this->getUniqueID() . '.test';
     \OCP\Config::setSystemValue('cipher', 'AES-128-CFB');
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
     \OCP\Config::deleteSystemValue('cipher');
     // 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 file contents without using any wrapper to get it's actual contents on disk
     $retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
     // Check that the file was encrypted before being written to disk
     $this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
     // remove the header to check if we can also decrypt old files without a header,
     //  this files should fall back to AES-128
     $cryptedWithoutHeader = substr($retreivedCryptedFile, Encryption\Crypt::BLOCKSIZE);
     $this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader);
     // Re-enable proxy - our work is done
     \OC_FileProxy::$enabled = $proxyStatus;
     $decrypted = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
     $this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
     // Teardown
     $this->view->unlink($this->userId . '/files/' . $filename);
     Encryption\Keymanager::deleteFileKey($this->view, $filename);
 }
Example #4
0
 /**
  * test update for the removal of the logical "Shared" folder. It should update
  * the file_target for every share and create a physical "Shared" folder for each user
  */
 function testRemoveSharedFolder()
 {
     self::prepareDB();
     // run the update routine to remove the shared folder and replace it with a real folder
     removeSharedFolder(false, 2);
     // verify results
     $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
     $result = $query->execute(array());
     $newDBContent = $result->fetchAll();
     foreach ($newDBContent as $row) {
         if ((int) $row['share_type'] === \OCP\Share::SHARE_TYPE_USER) {
             $this->assertSame('/Shared', substr($row['file_target'], 0, strlen('/Shared')));
         } else {
             $this->assertSame('/ShouldNotChange', $row['file_target']);
         }
     }
     $shareFolder = \OCP\Config::getSystemValue('share_folder', '/');
     $this->assertSame('/Shared', $shareFolder);
     // cleanup
     $this->cleanupSharedTable();
     \OCP\Config::deleteSystemValue('share_folder');
 }
Example #5
0
 /**
  * Delete a system wide defined value
  *
  * @param string $key the key of the value, under which it was saved
  */
 public function deleteSystemValue($key)
 {
     \OCP\Config::deleteSystemValue($key);
 }
Example #6
0
 function testShareWithDifferentShareFolder()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $folderinfo = $this->view->getFileInfo($this->folder);
     $fileShare = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($fileShare);
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder');
     $folderShare = \OCP\Share::shareItem('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($folderShare);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     \OCP\Share::unshare('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     \OCP\Config::deleteSystemValue('share_folder');
 }