/** * 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); }