/** * Check administrator login during the upgrade steps * * @return boolean True if login succeded */ function checkLogin() { if (empty($_COOKIE['oat']) || $_COOKIE['oat'] != OA_UPGRADE_UPGRADE) { return true; } // Clean up session $GLOBALS['session'] = array(); // Detection needs to happen every time to make sure that database parameters are $oUpgrader = new OA_Upgrade(); $openadsDetected = $oUpgrader->detectOpenads(true) || $oUpgrader->existing_installation_status == OA_STATUS_CURRENT_VERSION; // Sequentially check, to avoid useless work if (!$openadsDetected) { if (!($panDetected = $oUpgrader->detectPAN(true))) { if (!($maxDetected = $oUpgrader->detectMAX(true))) { if (!($max01Detected = $oUpgrader->detectMAX01(true))) { // No upgrade-able version detected, return return false; } } } } phpAds_SessionStart(); OA_Upgrade_Login::readSession($panDetected); $oPlugin = new Plugins_Authentication(); if ($oPlugin->suppliedCredentials()) { // The new Users, Account, Permissions & Preference feature was introduced in OpenX 2.5.46-dev $newLogin = $openadsDetected && version_compare($oUpgrader->versionInitialApplication, '2.5.46-dev', '>=') == -1; if ($newLogin) { OA_Upgrade_Login::_checkLoginNew(); } else { if ($openadsDetected || $maxDetected) { OA_Upgrade_Login::_checkLoginOld('preference', true); } elseif ($max01Detected) { OA_Upgrade_Login::_checkLoginOld('config', true); } elseif ($panDetected) { OA_Upgrade_Login::_checkLoginOld('config', false); } else { return false; } } } return OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isUserLinkedToAdmin(); }
/** * testing for invalid version to upgrade and upgrade required * does not test for absent database * */ function test_detectMax() { $oUpgrade = new OA_Upgrade(); $oUpgrade->initDatabaseConnection(); $GLOBALS['_MAX']['CONF']['max']['installed'] = 1; // Mock::generatePartial( // 'OA_DB_Integrity', // 'OA_DB_Integrity_for_detectMax', // array('checkIntegrityQuick') // ); // $oUpgrade->oIntegrity = new OA_DB_Integrity_for_detectMax($this); // $oUpgrade->oIntegrity->setReturnValue('checkIntegrityQuick', true); // $oUpgrade->oIntegrity->expectOnce('checkIntegrityQuick'); $this->_createTestAppVarRecord('max_version', 'v0.3.30-alpha'); $this->assertFalse($oUpgrade->detectMAX(true), 'Max 0.3 not detected: found application version ' . $oUpgrade->versionInitialApplication); $this->assertEqual($oUpgrade->versionInitialApplication, 'v0.3.30-alpha', 'wrong initial application version expected v0.3.30-alpha got' . $oUpgrade->versionInitialApplication); $this->assertEqual($oUpgrade->existing_installation_status, OA_STATUS_MAX_VERSION_FAILED, 'wrong upgrade status code'); $this->assertEqual($oUpgrade->aPackageList[0], '', 'wrong package file assigned'); $this->_deleteTestAppVarRecordAllNames('max_version'); $this->_createTestAppVarRecord('max_version', 'v0.3.31-alpha'); $this->assertTrue($oUpgrade->detectMAX(true), 'Max 0.3 not detected: found application version ' . $oUpgrade->versionInitialApplication); $this->assertEqual($oUpgrade->versionInitialApplication, 'v0.3.31-alpha', 'wrong initial application version expected v0.3.31-alpha got' . $oUpgrade->versionInitialApplication); $this->assertEqual($oUpgrade->existing_installation_status, OA_STATUS_CAN_UPGRADE, 'wrong upgrade status code, expected ' . OA_STATUS_CAN_UPGRADE . ' got ' . $oUpgrade->existing_installation_status); $this->assertEqual($oUpgrade->aPackageList[0], 'openads_upgrade_2.3.31_to_2.3.32_beta.xml', 'wrong package file assigned'); $this->_deleteTestAppVarRecordAllNames('max_version'); unset($GLOBALS['_MAX']['CONF']['max']['installed']); // $oUpgrade->oIntegrity->tally(); }