/** * testObservers * * @return void */ public function testObservers() { $event1 = array('name' => 'foo1', 'data' => 'bar1'); $event2 = array('name' => 'foo2', 'data' => 'bar2'); $mock = new OpenID_Observer_Mock(); OpenID::attach($mock); // Test skipping existing observers OpenID::attach($mock); try { OpenID::setLastEvent($event1['name'], $event1['data']); // should not execute $this->assertTrue(false); } catch (OpenID_Exception $e) { } $this->assertSame($event1, OpenID::getLastEvent()); OpenID::detach($mock); // Test skipping missing observers OpenID::detach($mock); OpenID::setLastEvent($event2['name'], $event2['data']); $this->assertSame($event2, OpenID::getLastEvent()); }
/** * testVerifyUnsolicited * * @return void */ public function testVerifyUnsolicited() { $log = new OpenID_Observer_Log(); OpenID::attach($log); $this->rp = $this->getMock('OpenID_RelyingParty', array('getAssociationRequestObject', 'getAssertionObject'), array($this->returnTo, $this->realm)); $assertion = $this->getMock('OpenID_Assertion', array('checkAuthentication'), array(), '', false); $authMessage = new OpenID_Message(); $authMessage->set('is_valid', 'true'); $assertion->expects($this->once())->method('checkAuthentication')->will($this->returnValue($authMessage)); $this->rp->expects($this->once())->method('getAssertionObject')->will($this->returnValue($assertion)); $this->store->expects($this->any())->method('getDiscover')->will($this->returnValue($this->discover)); $this->store->expects($this->once())->method('getAssociation')->will($this->returnValue($this->association)); $this->association->expects($this->once())->method('checkMessageSignature')->will($this->returnValue(true)); $nonceObj = new OpenID_Nonce($this->opEndpointURL); $nonce = $nonceObj->createNonce(); $message = new OpenID_Message(); $message->set('openid.mode', 'id_res'); $message->set('openid.ns', OpenID::NS_2_0); $message->set('openid.return_to', $this->returnTo); $message->set('openid.claimed_id', $this->id); $message->set('openid.identity', $this->id); $message->set('openid.op_endpoint', $this->opEndpointURL); $message->set('openid.assoc_handle', '12345qwerty'); $message->set('openid.response_nonce', $nonce); $this->assertInstanceOf('OpenID_Assertion_Result', $this->rp->verify($this->messageToNetURL2($message), $message)); }