Thursday 31 January 2019

Error: Unable to find the controller for path "/login_check". The route is wrongly configured. (LexikJWTAuthentication)

Description

When I'm doing a normal request to my symfony server running on http://localhost:8000/api/admin/login_check it returns the desired jwt token.

However, when I do it with the functional tests (with ./bin/phpunit) I get the following error:

Error: Unable to find the controller for path \"/api/admin/login_check\". The route is wrongly configured.

I also went through the functional test docs.

Bug Reproduced

I was also able to reproduce the bug by cloning a working example provided by one of the creators of the lexikjwtauthenticationbundle.

Logs

[2019-01-29 21:30:24] request.INFO: Matched route "api_admin_login". {"route":"api_admin_login","route_parameters":{"_route":"api_admin_login"},"request_uri":"http://localhost/api/admin/login_check","method":"POST"} []
[2019-01-29 21:30:24] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-01-29 21:30:24] request.WARNING: Unable to look for the controller as the "_controller" parameter is missing. [] []

Test method:

    public function testLogin(){

        $client = static::createClient();
        $client->request('POST', '/api/admin/login_check', [], [],
            [
                'Content-Type' => 'application/json',
                'Accept' => 'application/json'
            ],
            json_encode([
                'email' => 'email@test.com',
                'password' => 'qwerty123'
            ])
        );

        $this->assertEquals(200, $client->getResponse()->getStatusCode());

    }

Routes:

# Admin Routes
api_admin_login_check:
    path: /api/admin/login_check
    methods:  [POST]

security:

security:

# more configs here

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        login_admin:
            pattern: ^/api/admin/login
            stateless: true
            anonymous: true
            json_login:
                username_path: email
                provider: app_admin_provider
                check_path: /api/admin/login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure

        admin_api:
            pattern: ^/api/admin
            stateless: true
            provider: app_admin_provider
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

    access_control:
        - { path: ^/api/admin/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api/admin, roles: ROLE_ADMIN }
        - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

Why is there a 404 route not found for /api/admin/login_check route during Functional Testing but works fine with curl and postman?

Github #610



from Error: Unable to find the controller for path "/login_check". The route is wrongly configured. (LexikJWTAuthentication)

No comments:

Post a Comment