Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebTestCase::loginAs() not working #487

Open
lukepass opened this issue Jan 16, 2019 · 4 comments
Open

WebTestCase::loginAs() not working #487

lukepass opened this issue Jan 16, 2019 · 4 comments
Labels
Milestone

Comments

@lukepass
Copy link

Hello, I followed the guide to authenticate using WebTestCase::loginAs() but it's not working and it's redirecting me to the login page.

This is my config_test.yml:

imports:
    - { resource: config_dev.yml }

framework:
    test: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
        storage_id: session.storage.mock_file
        name: MOCKSESSID
    profiler:
        collect: false

web_profiler:
    toolbar: false
    intercept_redirects: false

swiftmailer:
    disable_delivery: true

liip_functional_test:
    cache_db:
        sqlite: liip_functional_test.services_database_backup.sqlite

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_sqlite
                path:     "%kernel.cache_dir%/test.db"
security:
    firewalls:
        main:
            http_basic: ~

And this is the test:

class DivisionControllerTest extends FixtureWebTestCase
{
    public function testDivisionList()
    {
        $this->loginAs($this->fixtures->getReference('admin-user'), 'main');
        $client = $this->makeClient();

        $crawler = $client->request('GET', '/teachers/divisions/list');

        // successful
        $this->isSuccessful($client->getResponse());

        // more than 1 division
        $this->assertGreaterThan(
            1,
            $crawler->filter('tr')->count()
        );
    }
}

And this is the log:

[2019-01-16 12:49:32] request.INFO: Matched route "teacher_division_list". {"route":"teacher_division_list","route_parameters":{"orderBy":"name","_controller":"AppBundle\\Controller\\DivisionController::listAction","_route":"teacher_division_list"},"request_uri":"http://localhost/teachers/divisions/list","method":"GET"} []
[2019-01-16 12:49:32] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-01-16 12:49:32] security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at /xyz/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php:68)"} []
[2019-01-16 12:49:32] security.DEBUG: Calling Authentication entry point. [] []

Preconditions

  1. Symfony 3.4
  2. PHP v7.2
  3. Liip v2.0.0-alpha12

Steps to reproduce

See above.

Expected result

See above.

Actual result

See above.

@alexislefebvre alexislefebvre added this to the 2.0 milestone Jan 22, 2019
@lukepass
Copy link
Author

lukepass commented Oct 2, 2019

Hello, any news on this subject? Thanks!

@alexislefebvre
Copy link
Collaborator

No, sorry, is the problem still here with the 3.x branch?

@ElNelyo
Copy link

ElNelyo commented Jan 28, 2020

Got same problem here ..
We got 302 redirection (due to Access Denied)

@althaus
Copy link

althaus commented Apr 29, 2021

Is it working for you if you follow the redirect?

$client->followRedirects();

I just got into the same issue. With auto-follow the client goes to the login page, gets authenticated and redirected back. So the tests succeeds, but this feels weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants