/** * @group 55 */ public function testDoesNotPerformAuthenticationWhenMatchedControllerHasAuthMapEntryNotInDefinedAuthSchemes() { // Minimal HTTP adapter mock, as we are not expecting any method calls $httpAuth = $this->getMockBuilder('Zend\Authentication\Adapter\Http') ->disableOriginalConstructor() ->getMock(); $this->listener->setHttpAdapter($httpAuth); // No OAuth2 server, intentionally $map = array( 'Foo\V2' => 'oauth2', 'Bar\V1' => 'basic', 'Baz\V3' => 'digest', ); $this->listener->setAuthMap($map); $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Authorization: Bearer TOKEN'); $routeMatch = new RouteMatch(array('controller' => 'Foo\V2\Rest\Test\TestController')); $mvcEvent = $this->mvcAuthEvent->getMvcEvent(); $mvcEvent ->setRequest($request) ->setRouteMatch($routeMatch); $identity = $this->listener->__invoke($this->mvcAuthEvent); $this->assertInstanceOf('ZF\MvcAuth\Identity\GuestIdentity', $identity); }
/** * @group 23 */ public function testListenerPullsDigestUsernameFromAuthenticationIdentityWhenCreatingAuthenticatedIdentityInstance() { $httpAuth = $this->getMockBuilder('Zend\\Authentication\\Adapter\\Http')->disableOriginalConstructor()->getMock(); $resultIdentity = new AuthenticationResult(AuthenticationResult::SUCCESS, array('username' => 'user', 'realm' => 'User Area')); $httpAuth->expects($this->once())->method('authenticate')->will($this->returnValue($resultIdentity)); $this->listener->setHttpAdapter($httpAuth); $this->request->getHeaders()->addHeaderLine('Authorization: Digest username="******", realm="User Area", nonce="AB10BC99", uri="/", qop="auth", nc="AB10BC99", cnonce="AB10BC99", response="b19adb0300f4bd21baef59b0b4814898", opaque=""'); $identity = $this->listener->__invoke($this->mvcAuthEvent); $this->assertInstanceOf('ZF\\MvcAuth\\Identity\\AuthenticatedIdentity', $identity); $this->assertEquals('user', $identity->getRoleId()); }
/** * @param ServiceLocatorInterface $services * @return DefaultAuthenticationListener */ public function createService(ServiceLocatorInterface $services) { $listener = new DefaultAuthenticationListener(); $httpAdapter = $this->retrieveHttpAdapter($services); if ($httpAdapter) { $listener->setHttpAdapter($httpAdapter); } $oauth2Server = $this->createOAuth2Server($services); if ($oauth2Server) { $listener->setOauth2Server($oauth2Server); } return $listener; }