/** * @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::$server->getUserSession()->setUser(new \OC\User\User($user, new \OC_User_Database())); \OC_Util::setupFS($user); if ($loadEncryption) { $params['uid'] = $user; $params['password'] = $password; \OCA\Files_Encryption\Hooks::login($params); } }
/** * @medium */ public function testChangePassphrase() { $filename = 'tmp-' . $this->getUniqueID(); // 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\Files_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); }