You are here

protected function FileUploadResourceTestBase::setUpAuthorization in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::setUpAuthorization()
  2. 10 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::setUpAuthorization()

Sets up the necessary authorization.

In case of a test verifying publicly accessible REST resources: grant permissions to the anonymous user role.

In case of a test verifying behavior when using a particular authentication provider: create a user with a particular set of permissions.

Because of the $method parameter, it's possible to first set up authentication for only GET, then add POST, et cetera. This then also allows for verifying a 403 in case of missing authorization.

Parameters

string $method: The HTTP method for which to set up authentication.

Overrides ResourceTestBase::setUpAuthorization

See also

::grantPermissionsToAnonymousRole()

::grantPermissionsToAuthenticatedRole()

11 calls to FileUploadResourceTestBase::setUpAuthorization()
FileUploadResourceTestBase::testFileUploadInvalidFileType in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with an invalid file type.
FileUploadResourceTestBase::testFileUploadLargerFileSize in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with a file size larger than allowed.
FileUploadResourceTestBase::testFileUploadMaliciousExtension in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload POST route with malicious extensions.
FileUploadResourceTestBase::testFileUploadNoExtensionSetting in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload POST route no extension configured.
FileUploadResourceTestBase::testFileUploadStrippedFilePath in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with any path prefixes being stripped.

... See full list

File

core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php, line 788

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

protected function setUpAuthorization($method) {
  switch ($method) {
    case 'GET':
      $this
        ->grantPermissionsToTestedRole([
        'view test entity',
      ]);
      break;
    case 'POST':
      $this
        ->grantPermissionsToTestedRole([
        'create entity_test entity_test_with_bundle entities',
        'access content',
      ]);
      break;
  }
}