示例#1
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // disable file proxy by default
     \OC_FileProxy::$enabled = false;
     // setup filesystem
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     \OC\Files\Filesystem::tearDown();
     \OC_Util::setupFS('admin');
     \OC_User::setUserId('admin');
     // login admin
     $params['uid'] = 'admin';
     $params['password'] = '******';
     OCA\Encryption\Hooks::login($params);
 }
示例#2
0
文件: crypt.php 项目: hjimmy/owncloud
 /**
  * @medium
  */
 function testChangePassphrase()
 {
     $filename = 'tmp-' . uniqid();
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
     // Test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // Get file decrypted contents
     $decrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
     $this->assertEquals($this->dataLong, $decrypt);
     // change password
     \OC_User::setPassword($this->userId, 'test', null);
     // relogin
     $params['uid'] = $this->userId;
     $params['password'] = '******';
     OCA\Encryption\Hooks::login($params);
     // Get file decrypted contents
     $newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
     $this->assertEquals($this->dataLong, $newDecrypt);
     // tear down
     // change password back
     \OC_User::setPassword($this->userId, $this->pass);
     $view = new \OC\Files\View('/' . $this->userId . '/files');
     $view->unlink($filename);
 }
示例#3
0
文件: util.php 项目: hjimmy/owncloud
 /**
  * @param string $user
  * @param bool $create
  * @param bool $password
  */
 public static function loginHelper($user, $create = false, $password = false)
 {
     if ($create) {
         \OC_User::createUser($user, $user);
     }
     if ($password === false) {
         $password = $user;
     }
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     \OC\Files\Filesystem::tearDown();
     \OC_Util::setupFS($user);
     \OC_User::setUserId($user);
     $params['uid'] = $user;
     $params['password'] = $password;
     OCA\Encryption\Hooks::login($params);
 }
示例#4
0
 /**
  * @param string $user
  * @param bool $create
  * @param bool $password
  */
 public static function loginHelper($user, $create = false, $password = false, $loadEncryption = true)
 {
     if ($create) {
         try {
             \OC_User::createUser($user, $user);
         } catch (\Exception $e) {
             // catch username is already being used from previous aborted runs
         }
     }
     if ($password === false) {
         $password = $user;
     }
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     \OC\Files\Filesystem::tearDown();
     \OC_User::setUserId($user);
     \OC_Util::setupFS($user);
     if ($loadEncryption) {
         $params['uid'] = $user;
         $params['password'] = $password;
         OCA\Encryption\Hooks::login($params);
     }
 }