sugar_config_old = $GLOBALS['sugar_config']; $_REQUEST['user_name'] = 'foo'; $_REQUEST['user_password'] = 'bar'; $_SESSION['authenticated_user_id'] = true; $_SESSION['hasExpiredPassword'] = false; $_SESSION['isMobile'] = null; $GLOBALS['sugar_config']['authenticationClass'] = 'SAMLAuthenticate'; $GLOBALS['sugar_config']['SAML_X509Cert'] = 'Bug50936_X509Cert'; //Create the custom directory if it does not exist if(!is_dir('custom/modules/Users/authentication/SAMLAuthenticate')) { mkdir_recursive('custom/modules/Users/authentication/SAMLAuthenticate'); } $contents = <<create(); echo \$url; EOQ; file_put_contents('custom/modules/Users/authentication/SAMLAuthenticate/index.php', $contents); $contents = <<idp_sso_target_url = 'www.sugarcrm.com'; // the certificate for the users account in the IdP \$settings->x509certificate = \$GLOBALS['sugar_config']['SAML_X509Cert']; // The URL where to the SAML Response/SAML Assertion will be posted \$settings->assertion_consumer_service_url = \$GLOBALS['sugar_config']['site_url']. "/index.php?module=Users&action=Authenticate"; // Name of this application \$settings->issuer = "php-saml"; // Tells the IdP to return the email address of the current user \$settings->name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"; return \$settings; } ?> EOQ; if(file_exists('custom/modules/Users/authentication/SAMLAuthenticate/settings.php')) { $this->customContents = file_get_contents('custom/modules/Users/authentication/SAMLAuthenticate/settings.php'); } file_put_contents('custom/modules/Users/authentication/SAMLAuthenticate/settings.php', $contents); } public function tearDown() { //If we had a custom settings.php file already, just restore it if(!empty($this->customContents)) { file_put_contents('custom/modules/Users/authentication/SAMLAuthenticate/settings.php', $this->customContents); } else { unlink('custom/modules/Users/authentication/SAMLAuthenticate/settings.php'); } //Remove the test index.php file if(file_exists('custom/modules/Users/authentication/SAMLAuthenticate/index.php')) { unlink('custom/modules/Users/authentication/SAMLAuthenticate/index.php'); } unset($GLOBALS['current_user']); $GLOBALS['sugar_config'] = $this->sugar_config_old; unset($_REQUEST['login_module']); unset($_REQUEST['login_action']); unset($_REQUEST['login_record']); unset($_REQUEST['user_name']); unset($_REQUEST['user_password']); unset($_SESSION['authenticated_user_id']); unset($_SESSION['hasExpiredPassword']); unset($_SESSION['isMobile']); } public function testLoadCustomSettingsFromIndex() { require('custom/modules/Users/authentication/SAMLAuthenticate/index.php'); $this->expectOutputRegex('/www\.sugarcrm\.com/', 'Failed to override custom/modules/Users/authentication/SAMLAuthenticate/settings.php'); } } ?>