/** * @test */ public function createTrustedCookie_localhostSkippedInCookie() { $request = Request::create(''); $user = $this->createMock('Scheb\\TwoFactorBundle\\Model\\TrustedComputerInterface'); $cookie = $this->cookieManager->createTrustedCookie($request, $user); $this->assertNull($cookie->getDomain()); }
/** * Call TwoFactorProviderRegistry, set trusted computer cookie if requested. * * @param AuthenticationContextInterface $context * * @return Response|null */ public function requestAuthenticationCode(AuthenticationContextInterface $context) { $request = $context->getRequest(); $user = $context->getUser(); $context->setUseTrustedOption($this->useTrustedOption); // Set trusted flag $response = $this->authHandler->requestAuthenticationCode($context); // On response validate if trusted cookie should be set if ($response instanceof Response) { // Set trusted cookie if ($context->isAuthenticated() && $context->useTrustedOption() && $request->get($this->trustedName)) { $cookie = $this->cookieManager->createTrustedCookie($request, $user); $response->headers->setCookie($cookie); } return $response; } return null; }
/** * @test */ public function createTrustedCookie_newTrustedToken_persistUserEntity() { $user = $this->getMock("Scheb\\TwoFactorBundle\\Model\\TrustedComputerInterface"); $request = $this->createRequest(); //Stub the TrustedTokenGenerator $this->tokenGenerator->expects($this->once())->method("generateToken")->will($this->returnValue("newTrustedCode")); //Mock the User object $user->expects($this->once())->method("addTrustedComputer")->with("newTrustedCode"); //Mock the persister $this->persister->expects($this->once())->method("persist")->with($user); $this->cookieManager->createTrustedCookie($request, $user); }