/** * run multiple async jobs parallel */ public static function triggerAsyncEvents($numOfParallels = 5) { $cmd = realpath(__DIR__ . "/../../../tine20/tine20.php") . ' --method Tinebase.triggerAsyncEvents'; $cmd = TestServer::assembleCliCommand($cmd); // start multiple cronruns at the same time // NOTE: we don't use pnctl as we don't need it here and it's not always available for ($i = 0; $i < 5; $i++) { $tempNames[] = $fileName = tempnam(Tinebase_Core::getTempDir(), 'asynctest'); Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Starting async job: ' . $cmd); $result = exec("{$cmd} > {$fileName} 2> /dev/null &"); } // wait for processes to complete for ($i = 0; $i < count($tempNames) * 5; $i++) { sleep(1); $allJobsDone = TRUE; foreach ($tempNames as $fileName) { $output = file_get_contents($fileName); $allJobsDone &= (bool) preg_match('/complete.$/m', $output); } if ($allJobsDone) { break; } } // cleanup foreach ($tempNames as $fileName) { //echo 'removing ' . $fileName . "\n"; unlink($fileName); } if (!$allJobsDone) { throw new Exception('jobs did not complete'); } }
/** * the singleton pattern * * @return TestServer */ public static function getInstance() { if (self::$instance === NULL) { self::$instance = new TestServer(); } return self::$instance; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_backend = Tinebase_User::getInstance(); if (!array_key_exists('Tinebase_EmailUser_Smtp_Postfix', $this->_backend->getPlugins())) { $this->markTestSkipped('Postfix SQL plugin not enabled'); } $this->objects['users'] = array(); $this->_mailDomain = TestServer::getPrimaryMailDomain(); }
public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Tinebase All Group Tests'); $suite->addTestSuite('Tinebase_Group_SqlTest'); if (TestServer::getInstance()->isPhpunitVersionGreaterOrEquals("3.5.0")) { // getMockBuilder() is only supported in phpunit 3.5 and higher $suite->addTestSuite('Tinebase_Group_ActiveDirectoryTest'); } return $suite; }
/** * lazy init of uit * * @return Calendar_Import_CalDAV_ClientMock */ protected function _getUit() { $testCredentials = TestServer::getInstance()->getTestCredentials(); if ($this->_uit === null) { $caldavClientOptions = array('baseUri' => 'localhost', 'userName' => Tinebase_Core::getUser()->accountLoginName, 'password' => $testCredentials['password']); $this->_uit = new Calendar_Import_CalDAV_ClientMock($caldavClientOptions, 'MacOSX'); $this->_uit->setVerifyPeer(false); } return $this->_uit; }
/** * test get smtp config */ public function testGetSmtpConfig() { $smtpConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::SMTP); $account = new Felamimail_Model_Account(array('type' => Felamimail_Model_Account::TYPE_SYSTEM)); $accountSmtpConfig = $account->getSmtpConfig(); if (array_key_exists('primarydomain', $smtpConfig)) { $this->assertContains($smtpConfig['primarydomain'], $accountSmtpConfig['username']); } if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $accountSmtpConfig['hostname']); } }
/** * test get smtp config */ public function testGetSmtpConfig() { $this->markTestSkipped('this test has to be refactored'); $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray(); $account = new Felamimail_Model_Account(array('type' => Felamimail_Model_Account::TYPE_SYSTEM)); $accountSmtpConfig = $account->getSmtpConfig(); if (isset($smtpConfig['primarydomain']) || array_key_exists('primarydomain', $smtpConfig)) { $this->assertContains($smtpConfig['primarydomain'], $accountSmtpConfig['username']); } if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $accountSmtpConfig['hostname']); } }
/** * testMaintenanceModeLoginFail */ public function testMaintenanceModeLoginFail() { if (Tinebase_User::getConfiguredBackend() === Tinebase_User::LDAP || Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) { $this->markTestSkipped('FIXME: Does not work with LDAP/AD backend (full test suite run)'); } Tinebase_Config::getInstance()->maintenanceMode = 1; try { $this->_instance->login('sclever', Tinebase_Helper::array_value('password', TestServer::getInstance()->getTestCredentials()), new \Zend\Http\PhpEnvironment\Request()); $this->fail('expecting exception: Tinebase_Exception_MaintenanceMode'); } catch (Tinebase_Exception_MaintenanceMode $temm) { $this->assertEquals('Installation is in maintenance mode. Please try again later', $temm->getMessage()); } }
public static function get() { self::$counter--; if (!self::$cache || !self::$counter) { self::$counter = self::getCount(); self::$cache = self::getCache(); if (!isset(self::$sum[self::$cache])) { self::$sum[self::$cache] = 0; } } self::$sum[self::$cache]++; return self::$cache; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_backend = Tinebase_User::getInstance(); if (!array_key_exists('Tinebase_EmailUser_Smtp_Postfix', $this->_backend->getPlugins())) { $this->markTestSkipped('Postfix SQL plugin not enabled'); } if (Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) { // error: Zend_Ldap_Exception: 0x44 (Already exists; 00002071: samldb: Account name (sAMAccountName) // 'tine20phpunituser' already in use!): adding: cn=PHPUnit User Tine 2.0,cn=Users,dc=example,dc=org $this->markTestSkipped('skipped for ad backends as it does not allow duplicate CNs'); } $this->objects['users'] = array(); $this->_mailDomain = TestServer::getPrimaryMailDomain(); }
public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Tinebase All User Tests'); $suite->addTestSuite('Tinebase_User_SqlTest'); $suite->addTestSuite('Tinebase_User_LdapTest'); if (TestServer::getInstance()->isPhpunitVersionGreaterOrEquals("3.5.0")) { // getMockBuilder() is only supported in phpunit 3.5 and higher $suite->addTestSuite('Tinebase_User_ActiveDirectoryTest'); } $suite->addTestSuite('Tinebase_User_Plugin_SambaTest'); $suite->addTestSuite('Tinebase_User_ModelTest'); $suite->addTestSuite('Tinebase_User_AbstractTest'); $suite->addTestSuite('Tinebase_User_EmailUser_AllTests'); // disabled user registration tests -> this is not used atm and not functional //$suite->addTestSuite('Tinebase_User_RegistrationTest'); return $suite; }
public function setUp() { $this->_defaultConfig = Tinebase_Redis_Worker_Daemon::getDefaultConfig(); // config actionqueue $this->_actionQueueConfigBackup = Tinebase_Core::getConfig()->actionqueue; Tinebase_Core::getConfig()->actionqueue = array('adapter' => 'Redis'); $this->_redis = new Redis(); $this->_redis->connect($this->_defaultConfig['host'], $this->_defaultConfig['port'], $this->_defaultConfig['timeout']); // start daemon $this->_daemonLog = tempnam("/tmp", "tine20daemonttestdaemonlog_"); $this->_daemonPid = tempnam("/tmp", "tine20daemonttestdaemonpid_"); $this->_configIni = tempnam("/tmp", "tine20daemontestconfigini_"); file_put_contents($this->_configIni, <<<EOT loglevel = 7 EOT ); $cmd = realpath(__DIR__ . '/../../../../../tine20/Tinebase/Redis/Worker/Daemon.php') . " -v -d -p {$this->_daemonPid} --config {$this->_configIni} > {$this->_daemonLog} 2>&1 &"; $cmd = TestServer::assembleCliCommand($cmd); exec($cmd); sleep(1); }
<?php require __DIR__ . '/TestServer.php'; $client = new swoole_client(SWOOLE_SOCK_TCP); if (!$client->connect('127.0.0.1', 9501)) { exit("connect failed\n"); } for ($i = 0; $i < TestServer::PKG_NUM; $i++) { $len = TestServer::random(); $sid = TestServer::random(); $array['index'] = $i; $array['sid'] = $sid; $array['len'] = $len; $array['data'] = str_repeat('A', $len); $_send = serialize($array) . "\r\n\r\n"; if ($i % 1000 == 0) { echo "#{$i} send package. sid={$sid}, length=" . strlen($_send) . "\n"; //usleep(100); } if (!$client->send($_send)) { break; } } sleep(1);
/** * import file * * @param string $_filename * @param Tinebase_Model_ImportExportDefinition $_definition * @param boolean $_useJsonImportFn * @param boolean $removeGroupList * @return array course data */ protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE, $removeGroupList = FALSE) { $definition = $_definition !== NULL ? $_definition : $this->_getCourseImportDefinition(); $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); if ($removeGroupList) { $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']); Addressbook_Controller_List::getInstance()->delete($group->list_id); } if ($_useJsonImportFn) { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile($_filename); Courses_Config::getInstance()->set(Courses_Config::STUDENTS_IMPORT_DEFINITION, $definition->name); $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']); $this->assertGreaterThan(0, $result['results']); } else { $maildomain = TestServer::getPrimaryMailDomain(); $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array('group_id' => $courseData['group_id'], 'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/', 'accountEmailDomain' => $maildomain, 'password' => $courseData['name'], 'samba' => array('homePath' => '//basehome/', 'homeDrive' => 'H:', 'logonScript' => 'logon.bat', 'profilePath' => '\\\\profile\\'))); $tempFilename = TestServer::replaceEmailDomainInFile($_filename); $importer->importFile($tempFilename); } $courseData = $this->_json->getCourse($courseData['id']); return $courseData; }
/** * @return Tinebase_Model_FullUser */ public static function getTestRecord() { $emailDomain = TestServer::getPrimaryMailDomain(); $user = new Tinebase_Model_FullUser(array('accountLoginName' => 'tine20phpunituser', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getDefaultGroup()->id, 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit User', 'accountEmailAddress' => 'phpunit@' . $emailDomain)); return $user; }
/** * testDuplicateUserId * * @see 0007218: Duplicate userid in dovecot_users */ public function testDuplicateUserId() { $emailDomain = TestServer::getPrimaryMailDomain(); $user = $this->_addUser('testuser@' . $emailDomain); // update user loginname $user->accountLoginName = 'testuser'; $user = Tinebase_User::getInstance()->updateUser($user); $queryResult = $this->_fetchUserFromDovecotUsersTable($user->getId()); $this->assertEquals('testuser@' . $emailDomain, $queryResult[0]['username'], 'username has not been updated in dovecot user table'); }
{ return new TestServer(); } public function ServerSetup() { $this->ServiceCreate('GTCX', array(&$this, 'GTCX')); } public function GTCX() { $this->SendSTART(); $this->SendI($this->LinkGetCtxId()); $this->SendC("+"); if ($this->LinkIsParent()) { $this->SendI(-1); } else { $this->SendI($this->LinkGetParent()->LinkGetCtxId()); } $this->SendC("+"); $this->SendC($this->ConfigGetName()); $this->SendC(":"); $this->SendRETURN(); } } $srv = new TestServer(); try { $srv->LinkCreate($argv); $srv->ProcessEvent(MqS::WAIT_FOREVER); } catch (Exception $ex) { $srv->ErrorSet($ex); } $srv->Exit();
$_SESSION['sleep'] = 5; } sleep($_SESSION['sleep']--); } // extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on class TestServer extends HTML_AJAX_Server { // this flag must be set to on init methods var $initMethods = true; // init method for the test class, includes needed files an registers it for ajax function initTest() { include 'support/test.class.php'; $this->registerClass(new test()); } // init method for the livesearch class, includes needed files an registers it for ajax function initLivesearch() { include 'support/livesearch.class.php'; $this->registerClass(new livesearch()); } // init method for the testHaa class, includes needed files an registers it for ajax, directly passes in methods to register to specify case in php4 function initTestHaa() { include 'support/testHaa.class.php'; $this->registerClass(new testHaa(), 'testHaa', array('updateClassName')); } } $server = new TestServer(); // handle requests as needed $server->handleRequest();
} // init method for the livesearch class, includes needed files an registers it for ajax function initLivesearch() { include 'support/livesearch.class.php'; $this->registerClass(new livesearch()); } // init method for the testHaa class, includes needed files an registers it for ajax, directly passes in methods to register to specify case in php4 function initTestHaa() { include 'support/testHaa.class.php'; $this->registerClass(new testHaa(), 'testHaa', array('updateClassName', 'greenText', 'highlight', 'duplicate')); } } // create an instance of our test server $server = new TestServer(); // init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods class initObject { // init method for the test class, includes needed files an registers it for ajax function initTest2() { include 'support/test2.class.php'; $this->server->registerClass(new test2()); } } $init = new initObject(); $server->registerInitObject($init); // you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can // use just one javascript include for all your library files // example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib
/** * testImportTwice (forceUpdateExisting) * * @see 0008652: Import von .ics-Dateien in Kalender schlägt fehl */ public function testImportTwice() { $this->_testNeedsTransaction(); $cmd = realpath(__DIR__ . "/../../../../tine20/tine20.php") . ' --method Calendar.import ' . 'plugin=Calendar_Import_Ical forceUpdateExisting=1 container_id=' . $this->_getTestCalendar()->getId() . ' ' . dirname(__FILE__) . '/files/termine.ics'; $cmd = TestServer::assembleCliCommand($cmd, TRUE); exec($cmd, $output); $failMessage = print_r($output, TRUE); $this->_checkImport($failMessage); // second time exec($cmd, $output); $failMessage = print_r($output, TRUE); $this->_checkImport($failMessage); }
/** * test line end encoding of Zend_Mime_Part / Smtp Protocol */ public function testSendWithWrongLineEnd() { $config = TestServer::getInstance()->getConfig(); $mailDomain = $config->maildomain ? $config->maildomain : 'tine20.org'; // build message with wrong line end rfc822 part $mail = new Tinebase_Mail('utf-8'); $mail->setBodyText('testmail' . "\r\n" . "\r\n"); $mail->setFrom('unittest@' . $mailDomain, 'unittest'); $mail->setSubject('line end test'); $mail->addTo('unittest@' . $mailDomain); $mail->addHeader('X-Tine20TestMessage', 'lineend'); // replace EOLs $content = file_get_contents(dirname(dirname(__FILE__)) . '/files/text_plain.eml'); $content = preg_replace("/\\x0a/", "\r\n", $content); $stream = fopen("php://temp", 'r+'); fputs($stream, $content); rewind($stream); $attachment = new Zend_Mime_Part($stream); $attachment->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822; $attachment->encoding = null; $attachment->charset = 'ISO-8859-1'; $attachment->filename = 'attach.eml'; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $mail->addAttachment($attachment); $smtpConfig = $this->_account->getSmtpConfig(); $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig); $mail->send($transport); $smtpLog = $transport->getConnection()->getLog(); $badLineEndCount = preg_match_all("/\\x0d\\x0d\\x0a/", $smtpLog, $matches); $this->assertEquals(0, $badLineEndCount); $badLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches); $this->assertTrue(preg_match_all("/\\x0d/", $smtpLog, $matches) > 70, 'unix line ends are missing'); }
/** * test change / delete of account */ public function testChangeDeleteAccount() { $system = $this->_getSystemAccount(); unset($system['id']); $system['type'] = Felamimail_Model_Account::TYPE_USER; $account = $this->_json->saveAccount($system); $accountRecord = new Felamimail_Model_Account($account, TRUE); $accountRecord->resolveCredentials(FALSE); if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $account['host']); } $this->_json->changeCredentials($account['id'], $accountRecord->user, 'neuespasswort'); $account = $this->_json->getAccount($account['id']); $accountRecord = new Felamimail_Model_Account($account, TRUE); $accountRecord->resolveCredentials(FALSE); $this->assertEquals('neuespasswort', $accountRecord->password); $this->_json->deleteAccounts($account['id']); }
public function RCall($code, $include_ini_code = false, $close = false, $debug_syntax = false) { $command = ""; if (!$debug_syntax) { if ($include_ini_code) { $command = $this->get_ini_RCode(); } else { $command .= $this->get_next_ini_RCode(); } } $command .= $code; if (!$debug_syntax) { $command .= $this->get_post_RCode(); } $output = array(); $return = -999; $command_obj = json_encode(array("session_id" => $this->id, "code" => $command, "close" => 0)); if (TestServer::$debug) { TestServer::log_debug("TestSession->RCall --- checking for server"); } if (!TestServer::is_running()) { TestServer::start_process(); } if (TestServer::$debug) { TestServer::log_debug("TestSession->RCall --- server found, trying to send"); } $response = TestServer::send($command_obj); $result = json_decode(trim($response)); if (TestServer::$debug) { TestServer::log_debug("TestSession->RCall --- sent and recieved response"); } $output = explode("\n", $result->output); $return = $result->return; $thisSession = null; $status = TestSession::TEST_SESSION_STATUS_ERROR; $removed = false; $release = 0; $html = ""; $head = ""; $Template_id = 0; $debug = 0; $hash = ""; $time_limit = 0; $Test_id = 0; $finished = 0; $loader_HTML = ""; $loader_head = ""; $loader_effect_show = "none"; $loader_effect_hide = "none"; $loader_effect_show_options = ""; $loader_effect_hide_options = ""; $effect_show = "none"; $effect_hide = "none"; $effect_show_options = ""; $effect_hide_options = ""; if (!$debug_syntax) { $thisSession = TestSession::from_mysql_id($this->id); if ($thisSession != null) { $status = $thisSession->status; $release = $thisSession->release; $html = $thisSession->HTML; $Template_id = $thisSession->Template_id; $debug = $thisSession->debug; $hash = $thisSession->hash; $time_limit = $thisSession->time_limit; $Test_id = $thisSession->Test_id; $loader_HTML = $thisSession->loader_HTML; $loader_head = $thisSession->loader_head; $loader_effect_hide = $thisSession->loader_effect_hide; $loader_effect_hide_options = $thisSession->loader_effect_hide_options; $loader_effect_show = $thisSession->loader_effect_show; $loader_effect_show_options = $thisSession->loader_effect_show_options; $effect_hide = $thisSession->effect_hide; $effect_hide_options = $thisSession->effect_hide_options; $effect_show = $thisSession->effect_show; $effect_show_options = $thisSession->effect_show_options; if ($return != 0) { $status = TestSession::TEST_SESSION_STATUS_ERROR; } if ($status == TestSession::TEST_SESSION_STATUS_WORKING && $release == 1 || $close) { $status = TestSession::TEST_SESSION_STATUS_COMPLETED; } $thisSession->status = $status; $thisSession->mysql_save(); switch ($status) { case TestSession::TEST_SESSION_STATUS_COMPLETED: if ($debug) { TestSession::unregister($thisSession->id); $removed = true; } else { $thisSession->serialize(); } break; case TestSession::TEST_SESSION_STATUS_ERROR: case TestSession::TEST_SESSION_STATUS_TAMPERED: if ($debug) { TestSession::unregister($thisSession->id); $removed = true; } else { $thisSession->close(); } break; case TestSession::TEST_SESSION_STATUS_TEMPLATE: if ($debug) { $html = Template::strip_html($html); if ($release) { TestSession::unregister($thisSession->id); } } else { $head = Template::from_mysql_id($Template_id)->head; if ($release) { $thisSession->serialize(); } } break; } } else { $removed = true; } } $test = Test::from_mysql_id($this->Test_id); $debug_data = false; $logged_user = User::get_logged_user(); if ($logged_user != null) { $debug_data = $logged_user->is_object_readable($test); } if ($release == 1 || $status == TestSession::TEST_SESSION_STATUS_COMPLETED || $status == TestSession::TEST_SESSION_STATUS_ERROR || $status == TestSession::TEST_SESSION_STATUS_TAMPERED) { $finished = 1; } if (!$debug_syntax) { $response = array("data" => array("HEAD" => $head, "HASH" => $hash, "TIME_LIMIT" => $time_limit, "HTML" => $html, "TEST_ID" => $Test_id, "TEST_SESSION_ID" => $this->id, "STATUS" => $status, "TEMPLATE_ID" => $Template_id, "FINISHED" => $finished, "LOADER_HTML" => $loader_HTML, "LOADER_HEAD" => $loader_head, "LOADER_EFFECT_SHOW" => $loader_effect_show, "LOADER_EFFECT_SHOW_OPTIONS" => $loader_effect_show_options, "LOADER_EFFECT_HIDE" => $loader_effect_hide, "LOADER_EFFECT_HIDE_OPTIONS" => $loader_effect_hide_options, "EFFECT_SHOW" => $effect_show, "EFFECT_HIDE" => $effect_hide, "EFFECT_SHOW_OPTIONS" => $effect_show_options, "EFFECT_HIDE_OPTIONS" => $effect_hide_options)); } if ($debug_data) { for ($i = 0; $i < count($output); $i++) { if (strpos($output[$i], "CONCERTO_DB_PASSWORD <-") !== false) { $output[$i] = "[hidden]"; } $output[$i] = htmlspecialchars($output[$i], ENT_QUOTES); } $command_lines = explode("\n", $command); for ($i = 0; $i < count($command_lines); $i++) { if (strpos($command_lines[$i], "CONCERTO_DB_PASSWORD <-") !== false) { $command_lines[$i] = "[hidden]"; } } $command = implode("\n", $command_lines); $command = htmlspecialchars($command, ENT_QUOTES); if (!is_array($response)) { $response = array(); } $response["debug"] = array("code" => $command, "return" => $return, "output" => $output); } if (Ini::$timer_tamper_prevention && !$debug_syntax && !$removed) { $sql = sprintf("UPDATE `%s` SET `time_tamper_prevention`=%d WHERE `id`=%d", TestSession::get_mysql_table(), time(), $this->id); mysql_query($sql); } return $response; }
/** * replace maildomain in input file * * @param string $filename * @return string filename */ public static function replaceEmailDomainInFile($filename) { $config = TestServer::getInstance()->getConfig(); $maildomain = $config->maildomain ? $config->maildomain : 'tine20.org'; $tempPath = Tinebase_TempFile::getTempPath(); $contents = file_get_contents($filename); $contents = preg_replace('/tine20.org/', $maildomain, $contents); file_put_contents($tempPath, $contents); return $tempPath; }
public function RCall($values = null, $code = null, $resume_from_last_template = false) { if (Ini::$log_server_events) { TestServer::log_debug("TestSession->RCall --- R call initiated #" . session_id()); } //resume from last template if ($resume_from_last_template) { $response = array("data" => array("HEAD" => $this->head, "HASH" => $this->hash, "TIME_LIMIT" => $this->time_limit, "HTML" => $this->HTML, "TEST_ID" => $this->Test_id, "TEST_SESSION_ID" => $this->id, "STATUS" => TestSession::TEST_SESSION_STATUS_TEMPLATE, "TEMPLATE_ID" => $this->Template_id, "LOADER_TEMPLATE_ID" => $this->loader_Template_id, "FINISHED" => 0, "EFFECT_SHOW" => $this->effect_show, "EFFECT_HIDE" => $this->effect_hide, "EFFECT_SHOW_OPTIONS" => $this->effect_show_options, "EFFECT_HIDE_OPTIONS" => $this->effect_hide_options, "LOADER_HTML" => $this->loader_HTML, "LOADER_HEAD" => $this->loader_head, "LOADER_EFFECT_SHOW" => $this->loader_effect_show, "LOADER_EFFECT_SHOW_OPTIONS" => $this->loader_effect_show_options, "LOADER_EFFECT_HIDE" => $this->loader_effect_hide, "LOADER_EFFECT_HIDE_OPTIONS" => $this->loader_effect_hide_options, "LOADER_HTML" => $this->loader_HTML, "LOADER_HEAD" => $this->loader_head, "LOADER_EFFECT_SHOW" => $this->loader_effect_show, "LOADER_EFFECT_SHOW_OPTIONS" => $this->loader_effect_show_options, "LOADER_EFFECT_HIDE" => $this->loader_effect_hide, "LOADER_EFFECT_HIDE_OPTIONS" => $this->loader_effect_hide_options)); return $response; } //R server connection $command_obj = json_encode(array("workspace_id" => $this->UserWorkspace_id, "session_id" => $this->id, "hash" => $this->hash, "values" => $values, "code" => $code, "type" => 0, "IP" => $_SERVER["REMOTE_ADDR"])); if (Ini::$log_server_events) { TestServer::log_debug("TestSession->RCall --- checking for server"); } if (TestServer::get_server_status() == TestServer::SERVER_STATUS_STOPPED) { TestServer::start_process(); TestServer::wait_until_started(); } else { if (TestServer::get_server_status() == TestServer::SERVER_STATUS_STARTING) { TestServer::wait_until_started(); } } if (Ini::$log_server_events) { TestServer::log_debug("TestSession->RCall --- server found, trying to send"); } $response = TestServer::send($command_obj); $result = json_decode(trim($response)); if (Ini::$log_server_events) { TestServer::log_debug("TestSession->RCall --- sent and recieved response"); } $status = TestSession::TEST_SESSION_STATUS_ERROR; $removed = false; $release = 0; $html = ""; $head = ""; $Template_id = 0; $debug = 0; $hash = ""; $time_limit = 0; $Test_id = 0; $finished = 0; $loader_Template_id = 0; $loader_HTML = ""; $loader_head = ""; $loader_effect_show = "none"; $loader_effect_hide = "none"; $loader_effect_show_options = ""; $loader_effect_hide_options = ""; $effect_show = "none"; $effect_hide = "none"; $effect_show_options = ""; $effect_hide_options = ""; $state = "[]"; $output = ""; $thisSession = TestSession::from_mysql_id($this->id); $return = $result->return; if ($thisSession != null) { $output = $thisSession->output; $error_output = $thisSession->error_output; $state = $thisSession->state; $status = $thisSession->status; $release = $thisSession->release; $html = $thisSession->HTML; $head = $thisSession->head; $Template_id = $thisSession->Template_id; $debug = $thisSession->debug; $hash = $thisSession->hash; $time_limit = $thisSession->time_limit; $Test_id = $thisSession->Test_id; $loader_Template_id = $thisSession->loader_Template_id; $loader_HTML = $thisSession->loader_HTML; $loader_head = $thisSession->loader_head; $loader_effect_hide = $thisSession->loader_effect_hide; $loader_effect_hide_options = $thisSession->loader_effect_hide_options; $loader_effect_show = $thisSession->loader_effect_show; $loader_effect_show_options = $thisSession->loader_effect_show_options; $effect_hide = $thisSession->effect_hide; $effect_hide_options = $thisSession->effect_hide_options; $effect_show = $thisSession->effect_show; $effect_show_options = $thisSession->effect_show_options; if ($return != 0) { $status = TestSession::TEST_SESSION_STATUS_ERROR; } if ($status == TestSession::TEST_SESSION_STATUS_WORKING && $release == 1) { $status = TestSession::TEST_SESSION_STATUS_COMPLETED; } $thisSession->status = $status; $thisSession->mysql_save(); switch ($status) { case TestSession::TEST_SESSION_STATUS_COMPLETED: if ($debug) { TestSession::unregister($thisSession->UserWorkspace_id . "-" . $thisSession->id, $thisSession->UserWorkspace_id); $removed = true; } else { $thisSession->close(); } break; case TestSession::TEST_SESSION_STATUS_ERROR: if ($debug) { TestSession::unregister($thisSession->UserWorkspace_id . "-" . $thisSession->id, $thisSession->UserWorkspace_id); $removed = true; } else { $thisSession->close(); if (Ini::$log_r_errors) { $thisSession->log_error(nl2br(htmlspecialchars($error_output, ENT_QUOTES))); } } break; case TestSession::TEST_SESSION_STATUS_TAMPERED: if ($debug) { TestSession::unregister($thisSession->UserWorkspace_id . "-" . $thisSession->id, $thisSession->UserWorkspace_id); $removed = true; } else { $thisSession->close(); } break; case TestSession::TEST_SESSION_STATUS_TEMPLATE: if ($release) { if ($debug) { TestSession::unregister($thisSession->UserWorkspace_id . "-" . $thisSession->id, $thisSession->UserWorkspace_id); $removed = true; } else { $thisSession->close(); } } break; } } else { $removed = true; } $debug_data = false; $logged_user = User::get_logged_user(); if ($logged_user != null) { $debug_data = true; } if ($release == 1 || $status == TestSession::TEST_SESSION_STATUS_COMPLETED || $status == TestSession::TEST_SESSION_STATUS_ERROR || $status == TestSession::TEST_SESSION_STATUS_TAMPERED) { $finished = 1; } $response = array("data" => array("HEAD" => $head, "HASH" => $hash, "TIME_LIMIT" => $time_limit, "HTML" => $html, "TEST_ID" => $Test_id, "TEST_SESSION_ID" => $this->id, "STATUS" => $status, "TEMPLATE_ID" => $Template_id, "FINISHED" => $finished, "LOADER_TEMPLATE_ID" => $loader_Template_id, "LOADER_HTML" => $loader_HTML, "LOADER_HEAD" => $loader_head, "LOADER_EFFECT_SHOW" => $loader_effect_show, "LOADER_EFFECT_SHOW_OPTIONS" => $loader_effect_show_options, "LOADER_EFFECT_HIDE" => $loader_effect_hide, "LOADER_EFFECT_HIDE_OPTIONS" => $loader_effect_hide_options, "EFFECT_SHOW" => $effect_show, "EFFECT_HIDE" => $effect_hide, "EFFECT_SHOW_OPTIONS" => $effect_show_options, "EFFECT_HIDE_OPTIONS" => $effect_hide_options)); if ($debug_data) { if (!is_array($response)) { $response = array(); } if ($output != null) { if (strpos(trim($output), ">") !== 0 && strpos(trim($output), "[") !== 0) { $output = "> " . trim($output); } } if ($debug) { $state = json_decode($state, true); if ($state != null) { foreach ($state as $k => $v) { $state[$k] = htmlspecialchars($v, ENT_QUOTES); } $state = json_encode($state); } else { $state = "[]"; } $response["debug"] = array("return" => $return, "output" => nl2br(htmlspecialchars($output, ENT_QUOTES)), "error_output" => nl2br(htmlspecialchars($error_output, ENT_QUOTES)), "state" => nl2br($state)); } } if (Ini::$timer_tamper_prevention && !$removed) { $sql = sprintf("UPDATE `%s` SET `time_tamper_prevention`=%d WHERE `id`=%d", TestSession::get_mysql_table(), time(), $this->id); mysql_query($sql); } return $response; }
/** * test change pw + credential cache */ public function testChangePasswordAndUpdateCredentialCache() { $this->markTestSkipped('FIXME 0009250: fix test testChangePasswordAndUpdateCredentialCache'); $testCredentials = TestServer::getInstance()->getTestCredentials(); $account = clone $this->_account; unset($account->id); $account->type = Felamimail_Model_Account::TYPE_USER; $account->user = $testCredentials['username']; $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (isset($imapConfig['domain']) && !empty($imapConfig['domain'])) { $account->user .= '@' . $imapConfig['domain']; } $account->password = $testCredentials['password']; $account = $this->_controller->create($account); $testPw = 'testpwd'; // change pw & update credential cache $this->_setCredentials($testCredentials['username'], $testPw); $account = $this->_controller->get($account->getId()); // try to connect to imap $loginSuccessful = TRUE; try { $imap = Felamimail_Backend_ImapFactory::factory($account); } catch (Felamimail_Exception_IMAPInvalidCredentials $e) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' config: ' . print_r($imapAccountConfig, true) . ' / exception:' . $e); } $loginSuccessful = FALSE; } $this->assertTrue($loginSuccessful, 'wrong credentials'); }
/** * get test mail domain * * @return string */ protected function _getMailDomain() { return TestServer::getPrimaryMailDomain(); }
/** * testMaintenanceModeLoginFail */ public function testMaintenanceModeLoginFail() { Tinebase_Config::getInstance()->maintenanceMode = 1; $this->setExpectedException('Tinebase_Exception_MaintenanceMode'); $this->_instance->login('sclever', Tinebase_Helper::array_value('password', TestServer::getInstance()->getTestCredentials()), new \Zend\Http\PhpEnvironment\Request()); }
/** * test imap authentication */ public function testImapAuth() { // use imap config for the auth config $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (empty($imapConfig)) { $this->markTestSkipped('No IMAP config found.'); } $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']); Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP); Tinebase_Auth::setBackendConfiguration($authConfig); Tinebase_Auth::saveBackendConfiguration(); Tinebase_Auth::getInstance()->setBackend(); $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend()); $testCredentials = TestServer::getInstance()->getTestCredentials(); // valid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], $testCredentials['password']); $this->assertTrue($authResult->isValid()); // invalid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], 'some pw'); $this->assertFalse($authResult->isValid()); $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode()); $this->assertEquals(array('Invalid credentials for user ' . $this->_getEmailAddress(), ''), $authResult->getMessages()); }
/** * testImportUsersWithEmailUser */ public function testImportUsersWithEmailUser() { $userBackend = Tinebase_User::getInstance(); $config = TestServer::getInstance()->getConfig(); $maildomain = $config->maildomain ? $config->maildomain : 'tine20.org'; $readFile = fopen(dirname(__FILE__) . '/files/tine_user5.csv', 'r'); $writeFile = fopen('test.csv', 'w'); $delimiter = ','; $enclosure = '"'; while (($row = fgetcsv($readFile)) !== false) { foreach ($row as $colIndex => &$field) { $field = str_replace('DOMAIN', $maildomain, $field); } fputcsv($writeFile, $row, $delimiter, $enclosure); } fclose($readFile); fclose($writeFile); if (!array_key_exists('Tinebase_EmailUser_Smtp_Postfix', $userBackend->getPlugins())) { $this->markTestSkipped('Postfix SQL plugin not enabled'); } $this->_importUsers($this->objects['configEmailuser'], 'test.csv', 'admin_user_import_csv_test_emailuser'); $newUser = $userBackend->getFullUserByLoginName('testuser'); $this->assertEquals(array('contact@' . $maildomain, 'kontakt@' . $maildomain), $newUser->smtpUser->emailAliases); $this->assertEquals(array('test@' . $maildomain), $newUser->smtpUser->emailForwards); $this->assertTrue($newUser->smtpUser->emailForwardOnly); unlink("test.csv"); }