/** * @group ServerTests * * @see 0011760: create smd from model definition */ public function testHandleRequestForDynamicAPI() { // handle jsonkey check $jsonkey = 'myawsomejsonkey'; $_SERVER['HTTP_X_TINE20_JSONKEY'] = $jsonkey; $coreSession = Tinebase_Session::getSessionNamespace(); $coreSession->jsonKey = $jsonkey; $server = new Tinebase_Server_Json(); $request = \Zend\Http\PhpEnvironment\Request::fromString('POST /index.php?requestType=JSON HTTP/1.1' . "\r\n" . 'Host: localhost' . "\r\n" . 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7' . "\r\n" . 'Content-Type: application/json' . "\r\n" . 'X-Tine20-Transactionid: 18da265bc0eb66a36081bfd42689c1675ed68bab' . "\r\n" . 'X-Requested-With: XMLHttpRequest' . "\r\n" . 'Accept: */*' . "\r\n" . 'Referer: http://tine20.vagrant/' . "\r\n" . 'Accept-Encoding: gzip, deflate' . "\r\n" . 'Accept-Language: en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4' . "\r\n" . "\r\n" . '{"jsonrpc":"2.0","method":"Inventory.searchInventoryItems","params":{"filter":[], "paging":{}},"id":6}' . "\r\n"); ob_start(); $server->handle($request); $out = ob_get_clean(); //echo $out; $this->assertTrue(!empty($out), 'request should not be empty'); $this->assertNotContains('Not Authorised', $out); $this->assertNotContains('Method not found', $out); $this->assertNotContains('No Application Controller found', $out); $this->assertNotContains('"error"', $out); $this->assertNotContains('PHP Fatal error', $out); $this->assertContains('"result"', $out); }
/** * returns true if user account has been changed * * @return boolean */ public function userAccountChanged() { try { $session = Tinebase_Session::getSessionNamespace(); } catch (Zend_Session_Exception $zse) { $session = null; } return $session instanceof Zend_Session_Namespace && isset($session->userAccountChanged) ? $session->userAccountChanged : false; }
/** * * @return array */ protected function _getLoginFailedResponse() { $response = array('success' => false, 'errorMessage' => "Wrong username or password!"); Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter()->resetCache(); if ($this->_hasCaptcha()) { $config_count = Tinebase_Core::getConfig()->captcha->count; if (!isset(Tinebase_Session::getSessionNamespace()->captcha['count'])) { Tinebase_Session::getSessionNamespace()->captcha['count'] = 1; } else { Tinebase_Session::getSessionNamespace()->captcha['count'] = Tinebase_Session::getSessionNamespace()->captcha['count'] + 1; } if (Tinebase_Session::getSessionNamespace()->captcha['count'] >= $config_count) { $rets = Tinebase_Controller::getInstance()->makeCaptcha(); $response = array('success' => false, 'errorMessage' => "Wrong username or password!", 'c1' => $rets['1']); } } else { Tinebase_Session::destroyAndMantainCookie(); } return $response; }
/** * returns TRUE if filesystem is available * * - value is stored in session and registry for caching * * @return boolean */ public static function isFilesystemAvailable() { $isFileSystemAvailable = self::get('FILESYSTEM'); if ($isFileSystemAvailable === null) { try { $session = Tinebase_Session::getSessionNamespace(); if (isset($session->filesystemAvailable)) { $isFileSystemAvailable = $session->filesystemAvailable; self::set('FILESYSTEM', $isFileSystemAvailable); return $isFileSystemAvailable; } } catch (Zend_Session_Exception $zse) { $session = null; } $isFileSystemAvailable = !empty(Tinebase_Core::getConfig()->filesdir) && is_writeable(Tinebase_Core::getConfig()->filesdir); if ($session instanceof Zend_Session_Namespace) { if (Tinebase_Session::isWritable()) { $session->filesystemAvailable = $isFileSystemAvailable; } } if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Filesystem available: ' . ($isFileSystemAvailable ? 'yes' : 'no')); } self::set('FILESYSTEM', $isFileSystemAvailable); } return $isFileSystemAvailable; }
/** * Even if the database backend is PostgreSQL, we have to verify * if the extension Unaccent is installed and loaded. * This is done in Tinebase_Core::checkUnaccentExtension. * * @return boolean */ protected function _hasUnaccentExtension() { try { $session = Tinebase_Session::getSessionNamespace(); if (isset($session->dbcapabilities) && (isset($session->dbcapabilities['unaccent']) || array_key_exists('unaccent', $session->dbcapabilities))) { $result = $session->dbcapabilities['unaccent']; } else { $result = $this->_adapter->hasUnaccentExtension(); $capabilities['unaccent'] = $result; $session->dbcapabilities = $capabilities; } } catch (Zend_Session_Exception $zse) { $result = $this->_adapter->hasUnaccentExtension(); } return $result; }
/** * testChangeUserAccount * * @see 0009984: allow to change user role */ public function testChangeUserAccount() { // allow test user to sign in as sclever Tinebase_Config::getInstance()->set(Tinebase_Config::ROLE_CHANGE_ALLOWED, new Tinebase_Config_Struct(array(Tinebase_Core::getUser()->accountLoginName => array('sclever')))); $sclever = $this->_personas['sclever']; $result = $this->_instance->changeUserAccount('sclever'); $this->assertEquals(array('success' => true), $result); // make sure, we are sclever $this->assertEquals('sclever', Tinebase_Core::getUser()->accountLoginName); $this->assertEquals('sclever', Tinebase_Session::getSessionNamespace()->currentAccount->accountLoginName); // reset to original user Tinebase_Controller::getInstance()->initUser($this->_originalTestUser, false); Tinebase_Session::getSessionNamespace()->userAccountChanged = false; }
/** * get cache record (try to find in session first, then DB) * * @param string $id * @return Tinebase_Model_CredentialCache */ protected function _getCache($id) { try { $session = Tinebase_Session::getSessionNamespace(); $credentialSessionCache = $session->{self::SESSION_NAMESPACE}; if (isset($credentialSessionCache) && isset($credentialSessionCache[$id])) { return new Tinebase_Model_CredentialCache($credentialSessionCache[$id]); } } catch (Zend_Session_Exception $zse) { // nothing to do } /** @var Tinebase_Model_CredentialCache $result */ $result = $this->get($id); $this->_saveInSession($result); return $result; }