You are here

public function CsrfTest::testBasicAuth in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/rest/src/Tests/CsrfTest.php \Drupal\rest\Tests\CsrfTest::testBasicAuth()

Tests that CSRF check is not triggered for Basic Auth requests.

File

core/modules/rest/src/Tests/CsrfTest.php, line 64
Contains \Drupal\rest\Tests\CsrfTest.

Class

CsrfTest
Tests the CSRF protection.

Namespace

Drupal\rest\Tests

Code

public function testBasicAuth() {
  $curl_options = $this
    ->getCurlOptions();
  $curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
  $curl_options[CURLOPT_USERPWD] = $this->account
    ->getUsername() . ':' . $this->account->pass_raw;
  $this
    ->curlExec($curl_options);
  $this
    ->assertResponse(201);

  // Ensure that the entity was created.
  $loaded_entity = $this
    ->loadEntityFromLocationHeader($this
    ->drupalGetHeader('location'));
  $this
    ->assertTrue($loaded_entity, 'An entity was created in the database');
}