3 namespace Drupal\Tests\rest\Functional;
6 use Psr\Http\Message\ResponseInterface;
9 * Trait for ResourceTestBase subclasses testing $auth=basic_auth.
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
18 trait BasicAuthResourceTestTrait {
23 protected function getAuthenticationRequestOptions($method) {
26 'Authorization' => 'Basic ' . base64_encode($this->account->name->value . ':' . $this->account->passRaw),
34 protected function assertResponseWhenMissingAuthentication(ResponseInterface $response) {
35 $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response);
41 protected function assertAuthenticationEdgeCases($method, Url $url, array $request_options) {}