setUpAuthenticator example

protected function setUp(): void
    {
        $this->userProvider = new InMemoryUserProvider();
    }

    /** * @dataProvider provideSupportData */
    public function testSupport($request)
    {
        $this->setUpAuthenticator();

        $this->assertTrue($this->authenticator->supports($request));
    }

    public static function provideSupportData()
    {
        yield [new Request([][][][][]['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}')];

        $request = new Request([][][][][][], '{"username": "dunglas", "password": "foo"}');
        $request->setRequestFormat('json-ld');
        yield [$request];
    }
protected function setUp(): void
    {
        $this->userProvider = new InMemoryUserProvider();
        $this->accessTokenHandler = new InMemoryAccessTokenHandler();
    }

    /** * @dataProvider provideSupportData */
    public function testSupport($request)
    {
        $this->setUpAuthenticator();

        $this->assertNull($this->authenticator->supports($request));
    }

    public static function provideSupportData(): iterable
    {
        yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN'])];
        yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer INVALID_ACCESS_TOKEN'])];
    }

    /** * @dataProvider provideSupportsWithCustomTokenTypeData */

        if ($ok) {
            $this->expectNotToPerformAssertions();
        } else {
            $this->expectException(BadCredentialsException::class);
            $this->expectExceptionMessage('Username too long.');
        }

        $request = Request::create('/login_check', 'POST', ['_username' => $username, '_password' => 's$cr$t']);
        $request->setSession($this->createSession());

        $this->setUpAuthenticator();
        $this->authenticator->authenticate($request);
    }

    public static function provideUsernamesForLength()
    {
        yield [str_repeat('x', UserBadge::MAX_USERNAME_LENGTH + 1), false];
        yield [str_repeat('x', UserBadge::MAX_USERNAME_LENGTH - 1), true];
    }

    /** * @dataProvider postOnlyDataProvider */
private AccessTokenAuthenticator $authenticator;
    private AccessTokenHandlerInterface $accessTokenHandler;

    protected function setUp(): void
    {
        $this->userProvider = new InMemoryUserProvider();
        $this->accessTokenHandler = new InMemoryAccessTokenHandler();
    }

    public function testSupport()
    {
        $this->setUpAuthenticator();
        $request = new Request([][][][][]['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
        $request->request->set('access_token', 'INVALID_ACCESS_TOKEN');
        $request->setMethod(Request::METHOD_POST);

        $this->assertNull($this->authenticator->supports($request));
    }

    public function testSupportsWithCustomParameter()
    {
        $this->setUpAuthenticator('protection-token');
        $request = new Request([][][][][]['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
        
protected function setUp(): void
    {
        $this->userProvider = new InMemoryUserProvider();
        $this->accessTokenHandler = new InMemoryAccessTokenHandler();
    }

    /** * @dataProvider provideSupportData */
    public function testSupport($request)
    {
        $this->setUpAuthenticator();

        $this->assertNull($this->authenticator->supports($request));
    }

    public static function provideSupportData(): iterable
    {
        yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN'])];
        yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer INVALID_ACCESS_TOKEN'])];
    }

    public function testAuthenticate()
    {

        $this->loginLinkHandler = $this->createMock(LoginLinkHandlerInterface::class);
        $this->successHandler = $this->createMock(AuthenticationSuccessHandlerInterface::class);
        $this->failureHandler = $this->createMock(AuthenticationFailureHandlerInterface::class);
    }

    /** * @dataProvider provideSupportData */
    public function testSupport(array $options$request, bool $supported)
    {
        $this->setUpAuthenticator($options);

        $this->assertEquals($supported$this->authenticator->supports($request));
    }

    public static function provideSupportData()
    {
        yield [['check_route' => '/validate_link'], Request::create('/validate_link?hash=abc123'), true];
        yield [['check_route' => '/validate_link'], Request::create('/login?hash=abc123'), false];
        yield [['check_route' => '/validate_link', 'check_post_only' => true], Request::create('/validate_link?hash=abc123'), false];
        yield [['check_route' => '/validate_link', 'check_post_only' => true], Request::create('/validate_link?hash=abc123', 'POST'), true];
    }

    
private AccessTokenAuthenticator $authenticator;
    private AccessTokenHandlerInterface $accessTokenHandler;

    protected function setUp(): void
    {
        $this->userProvider = new InMemoryUserProvider();
        $this->accessTokenHandler = new InMemoryAccessTokenHandler();
    }

    public function testSupport()
    {
        $this->setUpAuthenticator();
        $request = new Request();
        $request->query->set('access_token', 'INVALID_ACCESS_TOKEN');

        $this->assertNull($this->authenticator->supports($request));
    }

    public function testSupportsWithCustomParameter()
    {
        $this->setUpAuthenticator('protection-token');
        $request = new Request();
        $request->query->set('protection-token', 'INVALID_ACCESS_TOKEN');

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