function prepareSettings($dataDir, $userId)
 {
     // hard-coded string as we want a predictable fixed length
     // no data will be written there
     $this->dataDir = $dataDir;
     \OCP\Config::setSystemValue('datadirectory', $this->dataDir);
     $this->user = $userId;
     $this->legacyStorageId = 'local::' . $this->dataDir . $this->user . '/';
     $this->newStorageId = 'home::' . $this->user;
     \OC_User::createUser($this->user, $this->user);
 }
Example #2
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 #3
0
 /**
  * Test default apps
  *
  * @dataProvider defaultAppsProvider
  */
 function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps)
 {
     $oldDefaultApps = \OCP\Config::getSystemValue('core', 'defaultapp', '');
     // CLI is doing messy stuff with the webroot, so need to work it around
     $oldWebRoot = \OC::$WEBROOT;
     \OC::$WEBROOT = '';
     Dummy_OC_App::setEnabledApps($enabledApps);
     \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
     $this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl());
     // restore old state
     \OC::$WEBROOT = $oldWebRoot;
     Dummy_OC_App::restore();
     \OCP\Config::setSystemValue('defaultapp', $oldDefaultApps);
 }
	/**
	 * Sets a new system wide value
	 *
	 * @param string $key the key of the value, under which will be saved
	 * @param mixed $value the value that should be stored
	 */
 	public function setSystemValue($key, $value) {
 		\OCP\Config::setSystemValue($key, $value);
	}
Example #5
0
 /**
  * Test default apps
  *
  * @dataProvider defaultAppsProvider
  */
 function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps)
 {
     $oldDefaultApps = \OCP\Config::getSystemValue('defaultapp', '');
     // CLI is doing messy stuff with the webroot, so need to work it around
     $oldWebRoot = \OC::$WEBROOT;
     \OC::$WEBROOT = '';
     $appManager = $this->getMock('\\OCP\\App\\IAppManager');
     $appManager->expects($this->any())->method('isEnabledForUser')->will($this->returnCallback(function ($appId) use($enabledApps) {
         return in_array($appId, $enabledApps);
     }));
     Dummy_OC_Util::$appManager = $appManager;
     // need to set a user id to make sure enabled apps are read from cache
     \OC_User::setUserId($this->getUniqueID());
     \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
     $this->assertEquals('http://localhost/' . $expectedPath, Dummy_OC_Util::getDefaultPageUrl());
     // restore old state
     \OC::$WEBROOT = $oldWebRoot;
     \OCP\Config::setSystemValue('defaultapp', $oldDefaultApps);
     \OC_User::setUserId(null);
 }
<?php

$state = \OCP\Config::getSystemValue('markup_configuration_history', 'doSet');
if ($state === 'doSet') {
    \OCP\Config::setSystemValue('markup_configuration_history', true);
}
Example #7
0
 /**
  * set default share folder
  *
  * @param string $shareFolder
  */
 public static function setShareFolder($shareFolder)
 {
     \OCP\Config::setSystemValue('share_folder', $shareFolder);
 }
Example #8
0
 /**
  * @brief enable/disable preview for selected format
  *
  * @param string format
  * @param bool enable (true = enable, false = disable, default = false)
  * @return bool
  */
 public static function setPreview($format, $enable = 'false')
 {
     $enablePreviewProviders = \OCP\Config::getSystemValue('enabledPreviewProviders', null);
     if ($enable == 'true') {
         if ($enablePreviewProviders === null) {
             // set up default providers
             $enablePreviewProviders = array();
             array_push($enablePreviewProviders, 'OC\\Preview\\Image', 'OC\\Preview\\MP3', 'OC\\Preview\\TXT', 'OC\\Preview\\MarkDown');
         }
         if (!in_array($format, $enablePreviewProviders)) {
             array_push($enablePreviewProviders, $format);
         }
     } else {
         if (!($enablePreviewProviders == null)) {
             $enablePreviewProviders = array_diff($enablePreviewProviders, array($format));
         }
     }
     if (!\OCP\Config::setSystemValue('enabledPreviewProviders', $enablePreviewProviders)) {
         logWarn("Failed to enable " . $format . " preview provider (config.php readonly?)");
         return true;
     }
 }