Example #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->object = new OpenID_ServiceEndpoints($this->identifier);
     $this->badService = new OpenID_ServiceEndpoint();
     $this->goodService = new OpenID_ServiceEndpoint();
     $this->goodService->setURIs(array($this->identifier));
 }
Example #2
0
 /**
  * Performs YADIS discovery
  * 
  * @throws OpenID_Discover_Exception on error
  * @return OpenID_ServiceEndpoints
  */
 public function discover()
 {
     try {
         try {
             $discoveredServices = $this->getServicesYadis()->discover();
         } catch (Services_Yadis_Exception $e) {
             $message = 'Yadis protocol could not locate a valid XRD document';
             if ($e->getMessage() == $message) {
                 return false;
             }
             throw $e;
         }
         if (!$discoveredServices->valid()) {
             return false;
         }
         $service = new OpenID_ServiceEndpoints($this->getServicesYadis()->getYadisId());
         foreach ($discoveredServices as $discoveredService) {
             $types = $discoveredService->getTypes();
             if (array_key_exists($types[0], OpenID::$versionMap)) {
                 $version = $types[0];
                 $localID = null;
                 $localIDs = $discoveredService->getElements('xrd:LocalID');
                 if (!empty($localIDs[0])) {
                     $localID = $localIDs[0];
                 }
                 // Modify version if appropriate
                 if ($localID && $version == OpenID::SERVICE_2_0_SERVER) {
                     $version = OpenID::SERVICE_2_0_SIGNON;
                 }
                 $opEndpoint = new OpenID_ServiceEndpoint();
                 $opEndpoint->setVersion($types[0]);
                 // Choose OpenID 2.0 if it's available
                 if (count($types) > 1) {
                     foreach ($types as $type) {
                         if ($type == OpenID::SERVICE_2_0_SERVER || $type == OpenID::SERVICE_2_0_SIGNON) {
                             $opEndpoint->setVersion($type);
                             break;
                         }
                     }
                 }
                 $opEndpoint->setTypes($types);
                 $opEndpoint->setURIs($discoveredService->getUris());
                 $opEndpoint->setLocalID($localID);
                 $opEndpoint->setSource(OpenID_Discover::TYPE_YADIS);
                 $service->addService($opEndpoint);
             }
         }
         // Add in expires information
         $service->setExpiresHeader($this->getServicesYadis()->getHTTPResponse()->getHeader('Expires'));
         return $service;
     } catch (Services_Yadis_Exception $e) {
         // Add logging or observer?
         throw new OpenID_Discover_Exception($e->getMessage());
     }
     // Did the identifier even respond to the initial HTTP request?
     if ($this->yadis->getUserResponse() === false) {
         throw new OpenID_Discover_Exception('No response from identifier');
     }
 }
Example #3
0
 /**
  * setUp 
  * 
  * @return void
  */
 public function setUp()
 {
     $this->rp = $this->getMock('OpenID_RelyingParty', array('getAssociationRequestObject', 'getAssertionObject'), array($this->returnTo, $this->realm, $this->id));
     $this->store = $this->getMock('OpenID_Store_Mock', array('getDiscover', 'getAssociation', 'getNonce'));
     OpenID::setStore($this->store);
     $this->discover = $this->getMock('OpenID_Discover', array('__get'), array($this->id));
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setURIs(array($this->opEndpointURL));
     $opEndpoint->setVersion(OpenID::SERVICE_2_0_SERVER);
     $opEndpoints = new OpenID_ServiceEndpoints($this->id, $opEndpoint);
     $this->discover->expects($this->any())->method('__get')->will($this->returnValue($opEndpoints));
     $params = array('uri' => 'http://example.com', 'expiresIn' => 600, 'created' => 1240980848, 'assocType' => 'HMAC-SHA256', 'assocHandle' => 'foobar{}', 'sharedSecret' => '12345qwerty');
     $this->association = $this->getMock('OpenID_Association', array('checkMessageSignature'), array($params));
 }
Example #4
0
 /**
  * Adds a nonce to the openid.return_to URL parameter.  Only used in OpenID 1.1
  * 
  * @return void
  */
 protected function addNonce()
 {
     $nonce = $this->getNonce()->createNonceAndStore();
     $returnToURL = new Net_URL2($this->message->get('openid.return_to'));
     $returnToURL->setQueryVariable(OpenID_Nonce::RETURN_TO_NONCE, urlencode($nonce));
     $this->message->set('openid.return_to', $returnToURL->getURL());
     // Observing
     $logMessage = "Nonce: {$nonce}\n";
     $logMessage = 'New ReturnTo: ' . $returnToURL->getURL() . "\n";
     $logMessage .= 'OP URIs: ' . print_r($this->serviceEndpoint->getURIs(), true);
     OpenID::setLastEvent(__METHOD__, $logMessage);
 }
Example #5
0
 /**
  * Tests the isValid() method
  *
  * @return void
  */
 public function testIsValidTrue()
 {
     $this->object->setURIs(array('http://example.com'));
     $isValid = $this->object->isValid();
     $this->assertTrue($isValid);
 }
Example #6
0
 /**
  * Builds the service endpoint
  * 
  * @param array $results Array of items discovered via HTML
  * 
  * @return OpenID_ServiceEndpoints
  */
 protected function buildServiceEndpoint(array $results)
 {
     if (count($results['openid2.provider'])) {
         $version = OpenID::SERVICE_2_0_SIGNON;
         if (count($results['openid2.local_id'])) {
             $localID = $results['openid2.local_id'][0];
         }
         $endpointURIs = $results['openid2.provider'];
     } elseif (count($results['openid.server'])) {
         $version = OpenID::SERVICE_1_1_SIGNON;
         $endpointURIs = $results['openid.server'];
         if (count($results['openid.delegate'])) {
             $localID = $results['openid.delegate'][0];
         }
     } else {
         throw new OpenID_Discover_Exception('Discovered information does not conform to spec');
     }
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setVersion($version);
     $opEndpoint->setTypes(array($version));
     $opEndpoint->setURIs($endpointURIs);
     $opEndpoint->setSource(OpenID_Discover::TYPE_HTML);
     if (isset($localID)) {
         $opEndpoint->setLocalID($localID);
     }
     return new OpenID_ServiceEndpoints($this->identifier, $opEndpoint);
 }
Example #7
0
 /**
  * Adds a service to the services array
  *
  * @param OpenID_ServiceEndpoint $endpoint The service endpoint object
  *
  * @return void
  */
 public function addService(OpenID_ServiceEndpoint $endpoint)
 {
     if (!$endpoint->isValid()) {
         return;
     }
     $this->_services[] = $endpoint;
 }
Example #8
0
 /**
  * testGetAuthorizeURLSignonLocalIDOneOne 
  * 
  * @return void
  */
 public function testGetAuthorizeURLSignonLocalIDOneOne()
 {
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setVersion(OpenID::SERVICE_1_1_SIGNON);
     $opEndpoint->setTypes(array(OpenID::SERVICE_1_1_SIGNON));
     $opEndpoint->setLocalID($this->identifier);
     $opEndpoint->setURIs(array($this->opURL));
     OpenID_Discover_Mock::$opEndpoint = $opEndpoint;
     $this->setObjects();
     $url = $this->authRequest->getAuthorizeURL();
     $split = preg_split('/\\?/', $url);
     $message = new OpenID_Message($split[1], OpenID_Message::FORMAT_HTTP);
     $this->assertNotSame($this->returnTo, $message->get('openid.return_to'));
     $this->assertSame($this->identifier, $message->get('openid.identity'));
     $this->assertSame(null, $message->get('openid.claimed_id'));
     $this->assertSame($this->opURL, $split[0]);
     // Mock nonce/store rather than have a new one created
     $store = new OpenID_Store_Mock();
     $nonce = new OpenID_Nonce($this->opURL, null, $store);
     $this->authRequest->setNonce($nonce);
     $url = $this->authRequest->getAuthorizeURL();
 }
Example #9
0
 /**
  * testCheckAuthentication 
  * 
  * @return void
  */
 public function testCheckAuthentication()
 {
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setURIs(array($this->opEndpointURL));
     $opEndpoints = new OpenID_ServiceEndpoints($this->claimedID, $opEndpoint);
     $this->discover = $this->getMock('OpenID_Discover', array('__get'), array($this->claimedID));
     $this->discover->expects($this->once())->method('__get')->will($this->returnValue($opEndpoints));
     $this->store->expects($this->once())->method('getDiscover')->will($this->returnValue($this->discover));
     $this->store->expects($this->once())->method('getNonce')->will($this->returnValue(false));
     $this->createObjects();
     $adapter = new HTTP_Request2_Adapter_Mock();
     $content = "HTTP/1.1 200\n";
     $content .= "Content-Type: text/html; charset=iso-8859-1\n\n\n";
     $content .= "foo:bar\n";
     $adapter->addResponse($content);
     $httpRequest = new HTTP_Request2();
     $httpRequest->setAdapter($adapter);
     $this->assertion->expects($this->once())->method('getHTTPRequest2Instance')->will($this->returnValue($httpRequest));
     $result = $this->assertion->checkAuthentication();
 }