Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / rest / tests / src / Functional / BasicAuthResourceTestTrait.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional;
4
5 use Drupal\Core\Url;
6 use Psr\Http\Message\ResponseInterface;
7
8 /**
9  * Trait for ResourceTestBase subclasses testing $auth=basic_auth.
10  *
11  * Characteristics:
12  * - Every request must send an Authorization header.
13  * - When accessing a URI that requires authentication without being
14  *   authenticated, a 401 response must be sent.
15  * - Because every request must send an authorization, there is no danger of
16  *   CSRF attacks.
17  */
18 trait BasicAuthResourceTestTrait {
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function getAuthenticationRequestOptions($method) {
24     return [
25       'headers' => [
26         'Authorization' => 'Basic ' . base64_encode($this->account->name->value . ':' . $this->account->passRaw),
27       ],
28     ];
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function assertResponseWhenMissingAuthentication(ResponseInterface $response) {
35     $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function assertAuthenticationEdgeCases($method, Url $url, array $request_options) {}
42
43 }