HttpUtils example

public function getMessageKey(): string
            {
                return 'Session locked after %failed_attempts% failed attempts.';
            }
        });

        $this->assertSame(['error' => 'Session locked after 3 failed attempts.']json_decode($response->getContent(), true));
    }

    private function setUpAuthenticator(array $options = [])
    {
        $this->authenticator = new JsonLoginAuthenticator(new HttpUtils()$this->userProvider, null, null, $options);
    }
}
$this->setUpAuthenticator();

        $request = Request::create('/login/link/check?stuff=1&user=weaverryan');

        $passport = $this->authenticator->authenticate($request);

        $this->assertTrue($passport->hasBadge(RememberMeBadge::class));
    }

    private function setUpAuthenticator(array $options = [])
    {
        $this->authenticator = new LoginLinkAuthenticator($this->loginLinkHandler, new HttpUtils()$this->successHandler, $this->failureHandler, $options);
    }
}
$this->assertSame($shouldSupport$this->authenticator->supports($request));
    }

    public static function provideContentTypes()
    {
        yield ['application/json', false];
        yield ['application/x-www-form-urlencoded', true];
    }

    private function setUpAuthenticator(array $options = [])
    {
        $this->authenticator = new FormLoginAuthenticator(new HttpUtils()$this->userProvider, $this->successHandler, $this->failureHandler, $options);
    }

    private function createSession()
    {
        return $this->createMock(SessionInterface::class);
    }
}

class DummyUserClass
{
    public function __toString(): string
    {
use Symfony\Component\Security\Http\HttpUtils;

class DefaultAuthenticationSuccessHandlerTest extends TestCase
{
    /** * @dataProvider getRequestRedirections */
    public function testRequestRedirections(Request $request$options$redirectedUrl)
    {
        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
        $urlGenerator->expects($this->any())->method('generate')->willReturn('http://localhost/login');
        $httpUtils = new HttpUtils($urlGenerator);
        $token = $this->createMock(TokenInterface::class);
        $handler = new DefaultAuthenticationSuccessHandler($httpUtils$options);
        if ($request->hasSession()) {
            $handler->setFirewallName('admin');
        }
        $this->assertSame('http://localhost'.$redirectedUrl$handler->onAuthenticationSuccess($request$token)->getTargetUrl());
    }

    public function testRequestRedirectionsWithTargetPathInSessions()
    {
        $session = $this->createMock(SessionInterface::class);
        
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Security\Http\SecurityRequestAttributes;

class HttpUtilsTest extends TestCase
{
    public function testCreateRedirectResponseWithPath()
    {
        $utils = new HttpUtils($this->getUrlGenerator());
        $response = $utils->createRedirectResponse($this->getRequest(), '/foobar');

        $this->assertTrue($response->isRedirect('http://localhost/foobar'));
        $this->assertEquals(302, $response->getStatusCode());
    }

    public function testCreateRedirectResponseWithAbsoluteUrl()
    {
        $utils = new HttpUtils($this->getUrlGenerator());
        $response = $utils->createRedirectResponse($this->getRequest(), 'http://symfony.com/');

        
Home | Imprint | This part of the site doesn't use cookies.