/**
  * @covers Drupal\amazons3\Matchable\PresignedPath::factory
  */
 public function testFactory()
 {
     $paths = PresignedPath::factory(array('.*' => 30, '.?' => 60));
     $this->assertTrue(is_array($paths));
     foreach ($paths as $path) {
         $this->assertInstanceOf('Drupal\\amazons3\\Matchable\\PresignedPath', $path);
     }
     $this->assertEquals('.*', $paths[0]->getPath());
     $this->assertEquals(30, $paths[0]->getTimeout());
     $this->assertEquals('.?', $paths[1]->getPath());
     $this->assertEquals('60', $paths[1]->getTimeout());
 }
 /**
  * @covers \Drupal\amazons3\StreamWrapper::getExternalUrl
  * @covers \Drupal\amazons3\StreamWrapper::usePresigned
  * @covers \Drupal\amazons3\StreamWrapper::getS3Url
  */
 public function testPresignedPath()
 {
     $config = StreamWrapperConfiguration::fromConfig(['bucket' => 'bucket.example.com', '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'));
 }