requestAuthenticationCode() public method

Call TwoFactorProviderRegistry, set trusted computer cookie if requested.
public requestAuthenticationCode ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context ) : Response | null
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
return Symfony\Component\HttpFoundation\Response | null
Ejemplo n.º 1
0
 /**
  * @test
  */
 public function requestAuthenticationCode_shouldCheckIfTrustedIsAllowedByContext()
 {
     $context = $this->getAuthenticationContext();
     $context->expects($this->once())->method('isAuthenticated')->willReturn(true);
     $context->expects($this->once())->method('useTrustedOption')->willReturn(false);
     $this->authHandler->expects($this->once())->method('requestAuthenticationCode')->with($context)->willReturn(new Response('<form></form>'));
     $this->cookieManager->expects($this->never())->method('createTrustedCookie');
     $returnValue = $this->trustedFilter->requestAuthenticationCode($context);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $returnValue);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function requestAuthenticationCode_authenticatedAndTrustedChecked_setTrustedCookie()
 {
     $request = $this->getRequest();
     $request->expects($this->any())->method('get')->with('trustedName')->will($this->returnValue(true));
     //Trusted option checked
     $user = $this->getSupportedUser();
     //Stub the context
     $context = $this->getAuthenticationContext($request, $user);
     $context->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true));
     //Stub the authentication handler
     $response = $this->getResponse();
     $this->authHandler->expects($this->once())->method('requestAuthenticationCode')->will($this->returnValue($response));
     //Mock the TrustedCookieManager
     $cookie = new Cookie('someCookie');
     $this->cookieManager->expects($this->once())->method('createTrustedCookie')->with($request, $user)->will($this->returnValue($cookie));
     //Expect cookie be set in response headers
     $response->headers->expects($this->once())->method('setCookie')->with($cookie);
     $this->trustedFilter->requestAuthenticationCode($context);
 }