Пример #1
0
 /**
  * testing setOpEndpoint
  *
  */
 public function testSetOpEndpoint()
 {
     $this->expectOutputRegex('/.*/');
     // Hide stdout from the component when the test run
     $storage = new Provider\Storage\File(__DIR__ . "/_files/provider");
     $provider = new 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 ResponseHelper(true);
     $storage->addAssociation(self::HANDLE, "sha256", pack("H*", '0102030405060708091011121314151617181920212223242526272829303132'), time() + 3660);
     $this->assertTrue($provider->respondToConsumer(array('openid_ns' => OpenId::NS_2_0, 'openid_assoc_handle' => self::HANDLE, 'openid_return_to' => 'http://www.test.com/test.php'), null, $response));
     $headers = $response->headers();
     $this->assertTrue($headers->has('Location'));
     $url = parse_url($headers->get('Location')->getFieldValue());
     $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(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);
 }
Пример #2
0
 /**
  * testing addSite
  *
  */
 public function testAddSite()
 {
     $storage = new Storage\File(__DIR__ . "/_files");
     $storage->delUser(self::USER);
     $this->assertTrue($storage->addUser(self::USER, self::PASSWORD));
     $this->assertTrue($storage->addSite(self::USER, self::SITE1, true));
     $trusted = $storage->getTrustedSites(self::USER);
     $this->assertTrue(is_array($trusted));
     $this->assertSame(1, count($trusted));
     reset($trusted);
     $this->assertSame(self::SITE1, key($trusted));
     $this->assertSame(true, current($trusted));
     $this->assertTrue($storage->delUser(self::USER));
     $this->assertFalse($storage->addSite(self::USER, self::SITE1, true));
     $this->assertTrue($storage->addUser(self::USER, self::PASSWORD));
     $trusted = $storage->getTrustedSites(self::USER);
     $this->assertTrue(is_array($trusted));
     $this->assertSame(0, count($trusted));
     $this->assertTrue($storage->addSite(self::USER, self::SITE1, self::SITE1));
     $this->assertTrue($storage->addSite(self::USER, self::SITE2, self::SITE2));
     $this->assertTrue($storage->addSite(self::USER, self::SITE1, self::USER));
     $trusted = $storage->getTrustedSites(self::USER);
     $this->assertTrue(is_array($trusted));
     $this->assertSame(2, count($trusted));
     $this->assertSame(self::USER, $trusted[self::SITE1]);
     $this->assertSame(self::SITE2, $trusted[self::SITE2]);
     $this->assertTrue($storage->addSite(self::USER, self::SITE2, null));
     $trusted = $storage->getTrustedSites(self::USER);
     $this->assertTrue(is_array($trusted));
     $this->assertSame(1, count($trusted));
     $this->assertSame(self::USER, $trusted[self::SITE1]);
     $this->assertTrue($storage->addSite(self::USER, self::SITE1, null));
     $trusted = $storage->getTrustedSites(self::USER);
     $this->assertTrue(is_array($trusted));
     $this->assertSame(0, count($trusted));
     $this->assertTrue($storage->delUser(self::USER));
     $storage->delUser(self::USER);
     $this->assertFalse($storage->getTrustedSites(self::USER));
 }