I try to load a page in a BrowserTestBase unit test. The route for that page has a _csrf_token: 'TRUE' setting. The drupalGet() in the Test fails with 403 - forbidden. When I remove the CSRF setting from the route it works well.

My Test:

  public function testLoad() {
    // check register page

My route:

  path: '/register'
    _controller: '\Drupal\mysite\Controller\LogonController::register'
    _title: 'Bei mysite mitmachen'
    _user_is_logged_in: 'FALSE'
    _csrf_token: 'TRUE'

The request has a token but the validation fails. - - [03/Dec/2018:16:04:35 +0100] "GET /register?token=h3gPpd5oTofLkrJ58LwHsU9XKFHnO4lDoJfBdwpfOOY HTTP/1.1" 403 6873 "http://mysite" "simpletest56467379:1543849475:5c054603bbe864.07918519:qk8GKuxn0W3bijlqNSsE-0NXaqBAEFqE2Wzs27z2GhY"

I've already tried to ->absolut() the Url and to create the token by hand - nothing helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.