You are here

protected function S3fsUrlGenerationTest::runTests in S3 File System 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/S3fsUrlGenerationTest.php \Drupal\Tests\s3fs\Functional\S3fsUrlGenerationTest::runTests()

Execute common tests.

Parameters

string $urlBase: Base path including scheme that links are expected to include.

11 calls to S3fsUrlGenerationTest::runTests()
S3fsUrlGenerationTest::testCustomEndpointWithPortUriGeneration in tests/src/Functional/S3fsUrlGenerationTest.php
Test with a custom S3 Endpoint that contains a non standard port.
S3fsUrlGenerationTest::testCustomHostname in tests/src/Functional/S3fsUrlGenerationTest.php
Test Custom Hostname link generation.
S3fsUrlGenerationTest::testCustomHostnameDifferentRegion in tests/src/Functional/S3fsUrlGenerationTest.php
Test Custom hostname using a different region.
S3fsUrlGenerationTest::testCustomHostnameWithPort in tests/src/Functional/S3fsUrlGenerationTest.php
Test Custom Hostname with port link generation.
S3fsUrlGenerationTest::testDefaultDifferentRegion in tests/src/Functional/S3fsUrlGenerationTest.php
Test default link generation using a different region.

... See full list

File

tests/src/Functional/S3fsUrlGenerationTest.php, line 203

Class

S3fsUrlGenerationTest
S3 File System Tests.

Namespace

Drupal\Tests\s3fs\Functional

Code

protected function runTests(string $urlBase) {
  $publicFile = 's3://public.txt';
  $signedLongFile = 's3://signreq/signed.txt';
  $signedShortFile = 's3://shortsignttl/shortsigned.txt';
  $torrentWorksFile = 's3://tordir/thisworks.txt';
  $torrentFail = 's3://signreq/tordir/thiswontwork.txt';
  $forcedSaveFile = 's3://saveas/forcedsave.txt';
  $forcedSavePresignFile = 's3://signreq/saveas/alsoforcesaved.txt';
  $publicFileUri = file_create_url($publicFile);
  $this
    ->assertEquals($urlBase . '/public.txt', $publicFileUri, 'Public request as expected');

  // Presigned URL.
  $signedLongUri = file_create_url($signedLongFile);
  $this
    ->assertStringContainsString($urlBase, $signedLongUri, "Signed request contains base url");
  $this
    ->assertStringContainsString('X-Amz-Signature', $signedLongUri, 'Signed request contains a signature');
  $this
    ->assertStringContainsString('X-Amz-SignedHeaders=host', $signedLongUri, 'Host is part of signed request');
  $this
    ->assertStringContainsString('X-Amz-Expires=600', $signedLongUri, 'Signed for 600 Seconds');

  // @todo Calculate a signature ourselves based on the URL to see if it is correct.
  $this
    ->assertStringContainsString('X-Amz-Expires=300', file_create_url($signedShortFile), 'Signed for 300 seconds');

  // Torrent based download.
  $this
    ->assertEquals($urlBase . '/tordir/thisworks.txt?torrent', file_create_url($torrentWorksFile), 'Download via torrent');
  $this
    ->assertStringNotContainsString('torrent', file_create_url($torrentFail), 'Signed URLS can not use torrent download');

  // Save URLS as file.
  $forcedSaveUri = file_create_url($forcedSaveFile);
  $this
    ->assertStringContainsString('X-Amz-Signature', $forcedSaveUri, 'Forced save request contains a signature');
  $this
    ->assertStringContainsString('response-content-disposition=attachment', $forcedSaveUri, 'Forced save includes content-disposition header');
  $forcedSavePresignUri = file_create_url($forcedSavePresignFile);
  $this
    ->assertStringContainsString('X-Amz-Signature', $forcedSavePresignUri, 'Forced Save on a presign contains a signature');
  $this
    ->assertStringContainsString('response-content-disposition=attachment', $forcedSavePresignUri, 'Forced Save with forced presign still includes content-disposition');
}