You are here

public function StreamWrapperTest::testPresignedPath in AmazonS3 7.2

@covers \Drupal\amazons3\StreamWrapper::getExternalUrl @covers \Drupal\amazons3\StreamWrapper::usePresigned @covers \Drupal\amazons3\StreamWrapper::getS3Url

File

tests/StreamWrapperTest.php, line 472

Class

StreamWrapperTest
Tests \Drupal\amazons3\StreamWrapper.

Namespace

Drupal\amazons3Test

Code

public function testPresignedPath() {
  $config = StreamWrapperConfiguration::fromConfig([
    'bucket' => 'bucket.example.com',
    'region' => 'region',
    'caching' => FALSE,
    'expiration' => 0,
    'presignedPaths' => new MatchablePaths(PresignedPath::factory(array(
      'presigned/.*' => 30,
    ))),
  ]);
  $wrapper = new StreamWrapper($config);
  $wrapper
    ->setUri('s3://bucket.example.com/presigned/test');
  $url = Url::factory($wrapper
    ->getExternalUrl());
  $this
    ->assertNotNull($url
    ->getQuery()
    ->get('AWSAccessKeyId'));
  $this
    ->assertNotNull($url
    ->getQuery()
    ->get('Signature'));
  $this
    ->assertGreaterThanOrEqual(time(), $url
    ->getQuery()
    ->get('Expires'));

  // We allow a bit of fuzziness in the expiry to cover a different call to
  // time() in getExternalUrl().
  $this
    ->assertLessThanOrEqual(time() + 32, $url
    ->getQuery()
    ->get('Expires'));
}