/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { // phpCAS::setDebug(dirname(__FILE__).'/../test.log'); // error_reporting(E_ALL); CAS_GracefullTerminationException::throwInsteadOfExiting(); $_SERVER['SERVER_NAME'] = 'www.clientapp.com'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_ADMIN'] = 'root@localhost'; $_SERVER['REQUEST_URI'] = '/'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SESSION = array(); $this->object = new CAS_Client(CAS_VERSION_2_0, true, 'cas.example.edu', 443, '/cas/', false); $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest'); $this->object->setCasServerCACert('/path/to/ca_cert.crt'); /********************************************************* * Enumerate our responses *********************************************************/ // Set up our response. $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate'); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:authenticationSuccess>\n <cas:user>jsmith</cas:user>\n </cas:authenticationSuccess>\n</cas:serviceResponse>\n"); CAS_TestHarness_DummyRequest::addResponse($response); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $_SERVER['SERVER_NAME'] = 'www.service.com'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_ADMIN'] = 'root@localhost'; $_SERVER['REQUEST_URI'] = '/'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SESSION = array(); // $_GET['ticket'] = 'ST-123456-asdfasdfasgww2323radf3'; $this->object = new CAS_Client(CAS_VERSION_2_0, false, 'cas.example.edu', 443, '/cas/', false); $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest'); $this->object->setCasServerCACert('/path/to/ca_cert.crt'); /********************************************************* * Enumerate our responses *********************************************************/ // Valid ticket response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate'); $response->matchQueryParameters(array('service' => 'http://www.service.com/', 'ticket' => 'ST-123456-asdfasdfasgww2323radf3')); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:authenticationSuccess>\n <cas:user>jsmith</cas:user>\n <cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket>\n </cas:authenticationSuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); // Invalid ticket response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate'); $response->matchQueryParameters(array('service' => 'http://www.service.com/')); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:authenticationFailure code='INVALID_TICKET'>\n Ticket ST-1856339-aA5Yuvrxzpv8Tau1cYQ7 not recognized\n </cas:authenticationFailure>\n</cas:serviceResponse>\n\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $_SERVER['SERVER_NAME'] = 'www.service.com'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_ADMIN'] = 'root@localhost'; $_SERVER['REQUEST_URI'] = '/'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SESSION = array(); $this->object = new CAS_Client(CAS_VERSION_2_0, false, 'cas.example.edu', 443, '/cas/', false); $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest'); $this->object->setCasServerCACert('/path/to/ca_cert.crt'); $this->object->setNoClearTicketsFromUrl(); // phpCAS::setDebug(dirname(__FILE__).'/../test.log'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { // phpCAS::setDebug(dirname(__FILE__).'/../test.log'); // error_reporting(E_ALL); $_SERVER['SERVER_NAME'] = 'www.clientapp.com'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_ADMIN'] = 'root@localhost'; $_SERVER['REQUEST_URI'] = '/'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SESSION = array(); $this->object = new CAS_Client(CAS_VERSION_2_0, true, 'cas.example.edu', 443, '/cas/', false); $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest'); $this->object->setCasServerCACert('/path/to/ca_cert.crt', true); // Bypass PGT storage since CAS_Client->callback() will exit. Just build // up the session manually so that we are in a state from which we can // attempt to fetch proxy tickets and make proxied requests. $_SESSION['phpCAS']['user'] = '******'; $_SESSION['phpCAS']['pgt'] = 'PGT-clientapp-abc123'; $_SESSION['phpCAS']['proxies'] = array(); $_SESSION['phpCAS']['service_cookies'] = array(); $_SESSION['phpCAS']['attributes'] = array(); // Force Authentication to initialize the client. $this->object->forceAuthentication(); /********************************************************* * Enumerate our responses *********************************************************/ /********************************************************* * 1. Valid Proxy ticket and service *********************************************************/ // Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'imap://mail.example.edu/path/to/something', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxySuccess>\n <cas:proxyTicket>PT-asdfas-dfasgww2323radf3</cas:proxyTicket>\n </cas:proxySuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * 2. Proxy Ticket Error *********************************************************/ // Error Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'imap://mail.example.edu/path/that/doesnt/exist', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxyFailure code='INTERNAL_ERROR'>\n an internal error occurred during ticket validation\n </cas:proxyFailure>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * Ensure that IMAP constants are defined even if the IMAP * module is not installed. *********************************************************/ if (!defined('OP_READONLY')) { // Not sure what this should actually be. It is defined as: // REGISTER_LONG_CONSTANT( // "OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS // ); // in http://php-imap.sourcearchive.com/lines/5.1.2-1/php__imap_8c-source.html // For now, just ensure that it is an integer. define('OP_READONLY', 1); } }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { // phpCAS::setDebug(dirname(__FILE__).'/../test.log'); // error_reporting(E_ALL); $_SERVER['SERVER_NAME'] = 'www.clientapp.com'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_ADMIN'] = 'root@localhost'; $_SERVER['REQUEST_URI'] = '/'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SESSION = array(); $this->object = new CAS_Client(CAS_VERSION_2_0, true, 'cas.example.edu', 443, '/cas/', false); $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest'); $this->object->setCasServerCACert('/path/to/ca_cert.crt'); // Bypass PGT storage since CAS_Client->callback() will exit. Just build // up the session manually so that we are in a state from which we can // attempt to fetch proxy tickets and make proxied requests. $_SESSION['phpCAS']['user'] = '******'; $_SESSION['phpCAS']['pgt'] = 'PGT-clientapp-abc123'; $_SESSION['phpCAS']['proxies'] = array(); $_SESSION['phpCAS']['service_cookies'] = array(); $_SESSION['phpCAS']['attributes'] = array(); // Force Authentication to initialize the client. $this->object->forceAuthentication(); /********************************************************* * Enumerate our responses *********************************************************/ /********************************************************* * 1. Valid Proxy ticket and service *********************************************************/ // Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_webservice', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxySuccess>\n <cas:proxyTicket>PT-asdfas-dfasgww2323radf3</cas:proxyTicket>\n </cas:proxySuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); // Valid Service Response $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/my_webservice'); $response->matchQueryParameters(array('ticket' => 'PT-asdfas-dfasgww2323radf3')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/plain;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("Hello from the service."); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * 2. Proxy Ticket Error *********************************************************/ // Error Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_other_webservice', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxyFailure code='INTERNAL_ERROR'>\n an internal error occurred during ticket validation\n </cas:proxyFailure>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * 3. Server that doesn't respond/exist (sending failure) *********************************************************/ // Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'ssh://me.example.net', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxySuccess>\n <cas:proxyTicket>PT-ssh-1234abce</cas:proxyTicket>\n </cas:proxySuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * 4. Service With Error status. *********************************************************/ // Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_webservice_that_has_problems', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxySuccess>\n <cas:proxyTicket>PT-12345-abscasdfasdf</cas:proxyTicket>\n </cas:proxySuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); // Service Error Response $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/my_webservice_that_has_problems'); $response->matchQueryParameters(array('ticket' => 'PT-12345-abscasdfasdf')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 500 INTERNAL SERVER ERROR', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/plain;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("Problems have Occurred."); CAS_TestHarness_DummyRequest::addResponse($response); /********************************************************* * 5. Valid Proxy ticket and POST service *********************************************************/ // Proxy ticket Response $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy'); $response->matchQueryParameters(array('targetService' => 'http://www.service.com/post_webservice', 'pgt' => 'PGT-clientapp-abc123')); $response->ensureIsGet(); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n <cas:proxySuccess>\n <cas:proxyTicket>PT-posting-dfasgww2323radf3</cas:proxyTicket>\n </cas:proxySuccess>\n</cas:serviceResponse>\n"); $response->ensureCaCertPathEquals('/path/to/ca_cert.crt'); CAS_TestHarness_DummyRequest::addResponse($response); // Valid Service Response $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/post_webservice'); $response->matchQueryParameters(array('ticket' => 'PT-posting-dfasgww2323radf3')); $response->ensureIsPost(); $response->ensurePostBodyEquals('<request><method>doSomething</method><param type="string">with this</param></request>'); $response->ensureHasHeader('Content-Length: ' . strlen('<request><method>doSomething</method><param type="string">with this</param></request>')); $response->ensureHasHeader('Content-Type: text/xml'); $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/xml;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked')); $response->setResponseBody("<result><string>Yay, it worked.</string></result>"); CAS_TestHarness_DummyRequest::addResponse($response); }
/** * Set the certificate of the CAS server CA and if the CN should be properly * verified. * * @param string $cert CA certificate file name * @param bool $validate_cn Validate CN in certificate (default true) * * @return void */ public static function setCasServerCACert($cert, $validate_cn = true) { phpCAS::traceBegin(); phpCAS::_validateClientExists(); try { self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn); } catch (Exception $e) { phpCAS::error(get_class($e) . ': ' . $e->getMessage()); } phpCAS::traceEnd(); }