/** * testing setOpEndpoint * */ public function testSetOpEndpoint() { $storage = new Zend_OpenId_Provider_Storage_File(dirname(__FILE__) . "/_files/provider"); $provider = new Zend_OpenId_ProviderHelper(null, null, $this->_user, $storage); $provider->setOpEndpoint("http://www.test.com/real_endpoint.php"); // OpenID 2.0 with SHA256 $_SERVER['SCRIPT_URI'] = "http://www.test.com/endpoint.php"; $response = new Zend_OpenId_ResponseHelper(true); $storage->addAssociation(self::HANDLE, "sha256", pack("H*", '0102030405060708091011121314151617181920212223242526272829303132'), time() + 3660); $this->assertTrue($provider->respondToConsumer(array('openid_ns' => Zend_OpenId::NS_2_0, 'openid_assoc_handle' => self::HANDLE, 'openid_return_to' => 'http://www.test.com/test.php'), null, $response)); $headers = $response->getHeaders(); $this->assertSame('Location', $headers[0]['name']); $url = parse_url($headers[0]['value']); $this->assertSame('www.test.com', $url['host']); $this->assertSame('/test.php', $url['path']); $ret = array(); foreach (explode('&', $url['query']) as $line) { list($key, $val) = explode('=', $line, 2); $ret[$key] = urldecode($val); } $this->assertSame('id_res', $ret['openid.mode']); $this->assertSame('http://www.test.com/test.php', $ret['openid.return_to']); $this->assertSame(self::HANDLE, $ret['openid.assoc_handle']); $this->assertTrue(isset($ret['openid.response_nonce'])); $this->assertTrue(isset($ret['openid.signed'])); $this->assertTrue(isset($ret['openid.sig'])); $this->assertSame(Zend_OpenId::NS_2_0, $ret['openid.ns']); $this->assertSame("http://www.test.com/real_endpoint.php", $ret['openid.op_endpoint']); $this->assertTrue($storage->getAssociation(self::HANDLE, $macFunc, $secret, $expires)); $this->assertSame('sha256', $macFunc); $storage->delAssociation(self::HANDLE); }
/** * testing getAssociation * */ public function testGetAssociationExpiratin() { $expiresIn = time() + 1; $storage = new Zend_OpenId_Provider_Storage_File(); $storage->delAssociation(self::HANDLE); $this->assertTrue( $storage->addAssociation(self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn) ); sleep(2); $this->assertFalse( $storage->getAssociation(self::HANDLE, $macFunc, $secret, $expires) ); }
/** * testing respondToConsumer * */ public function testRespondToConsumer() { $storage = new Zend_OpenId_Provider_Storage_File(); $provider = new Zend_OpenId_ProviderHelper(null, null, $this->_user, $storage); // dumb mode $response = new Zend_OpenId_ResponseHelper(true); $storage->delAssociation(self::HANDLE); $this->assertTrue( $provider->respondToConsumer(array( 'openid_assoc_handle' => self::HANDLE, 'openid_return_to' => 'http://www.test.com/test.php' ), null, $response) ); $headers = $response->getHeaders(); $this->assertSame( 'Location', $headers[0]['name'] ); $url = parse_url($headers[0]['value']); $this->assertSame( 'www.test.com', $url['host'] ); $this->assertSame( '/test.php', $url['path'] ); $ret = array(); foreach (explode('&', $url['query']) as $line) { list($key,$val) = explode('=', $line, 2); $ret[$key] = urldecode($val); } $this->assertSame( 'id_res', $ret['openid.mode'] ); $this->assertSame( 'http://www.test.com/test.php', $ret['openid.return_to'] ); $this->assertTrue( isset($ret['openid.assoc_handle']) ); $this->assertTrue( isset($ret['openid.response_nonce']) ); $this->assertTrue( isset($ret['openid.signed']) ); $this->assertTrue( isset($ret['openid.sig']) ); $this->assertTrue( $storage->getAssociation($ret['openid.assoc_handle'], $macFunc, $secret, $expires) ); $this->assertSame( 'sha1', $macFunc ); // OpenID 2.0 with SHA256 $_SERVER['SCRIPT_URI'] = "http://www.test.com/endpoint.php"; $response = new Zend_OpenId_ResponseHelper(true); $storage->addAssociation(self::HANDLE, "sha256", pack("H*", '0102030405060708091011121314151617181920212223242526272829303132'), time() + 3660); $this->assertTrue( $provider->respondToConsumer(array( 'openid_ns' => Zend_OpenId::NS_2_0, 'openid_assoc_handle' => self::HANDLE, 'openid_return_to' => 'http://www.test.com/test.php' ), null, $response) ); $headers = $response->getHeaders(); $this->assertSame( 'Location', $headers[0]['name'] ); $url = parse_url($headers[0]['value']); $this->assertSame( 'www.test.com', $url['host'] ); $this->assertSame( '/test.php', $url['path'] ); $ret = array(); foreach (explode('&', $url['query']) as $line) { list($key,$val) = explode('=', $line, 2); $ret[$key] = urldecode($val); } $this->assertSame( 'id_res', $ret['openid.mode'] ); $this->assertSame( 'http://www.test.com/test.php', $ret['openid.return_to'] ); $this->assertSame( self::HANDLE, $ret['openid.assoc_handle'] ); $this->assertTrue( isset($ret['openid.response_nonce']) ); $this->assertTrue( isset($ret['openid.signed']) ); $this->assertTrue( isset($ret['openid.sig']) ); $this->assertSame( Zend_OpenId::NS_2_0, $ret['openid.ns'] ); $this->assertSame( "http://www.test.com/endpoint.php", $ret['openid.op_endpoint'] ); $this->assertTrue( $storage->getAssociation(self::HANDLE, $macFunc, $secret, $expires) ); $this->assertSame( 'sha256', $macFunc ); $storage->delAssociation(self::HANDLE); // OpenID 1.1 with SHA1 $storage->addAssociation(self::HANDLE, "sha1", pack("H*", '0102030405060708091011121314151617181920'), time() + 3660); $response = new Zend_OpenId_ResponseHelper(true); $ret = $provider->respondToConsumer(array( 'openid_assoc_handle' => self::HANDLE, 'openid_return_to' => 'http://www.test.com/test.php', 'openid_claimed_id' => 'http://claimed_id/', 'openid_identity' => 'http://identity/', 'openid_unknown' => 'http://www.test.com/test.php', ), null, $response); $headers = $response->getHeaders(); $this->assertSame( 'Location', $headers[0]['name'] ); $url = parse_url($headers[0]['value']); $this->assertSame( 'www.test.com', $url['host'] ); $this->assertSame( '/test.php', $url['path'] ); $ret = array(); foreach (explode('&', $url['query']) as $line) { list($key,$val) = explode('=', $line, 2); $ret[$key] = urldecode($val); } $this->assertSame( 'id_res', $ret['openid.mode'] ); $this->assertSame( 'http://www.test.com/test.php', $ret['openid.return_to'] ); $this->assertSame( self::HANDLE, $ret['openid.assoc_handle'] ); $this->assertTrue( isset($ret['openid.response_nonce']) ); $this->assertTrue( isset($ret['openid.signed']) ); $this->assertTrue( isset($ret['openid.sig']) ); $this->assertFalse( isset($ret['openid.ns']) ); $this->assertFalse( isset($ret['openid.op_endpoint']) ); $this->assertSame( 'http://claimed_id/', $ret['openid.claimed_id'] ); $this->assertSame( 'http://identity/', $ret['openid.identity'] ); $this->assertFalse( isset($ret['openid.unknown']) ); $this->assertTrue( $storage->getAssociation(self::HANDLE, $macFunc, $secret, $expires) ); $this->assertSame( 'sha1', $macFunc ); $storage->delAssociation(self::HANDLE); // extensions $sreg = new Zend_OpenId_Extension_Sreg(array("nickname"=>"test_id")); $response = new Zend_OpenId_ResponseHelper(true); $this->assertTrue( $provider->respondToConsumer(array( 'openid_return_to' => 'http://www.test.com/test.php', ), $sreg, $response) ); $headers = $response->getHeaders(); $this->assertSame( 'Location', $headers[0]['name'] ); $url = parse_url($headers[0]['value']); $this->assertSame( 'www.test.com', $url['host'] ); $this->assertSame( '/test.php', $url['path'] ); $ret = array(); foreach (explode('&', $url['query']) as $line) { list($key,$val) = explode('=', $line, 2); $ret[$key] = urldecode($val); } $this->assertSame( 'test_id', $ret['openid.sreg.nickname'] ); }