Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/OpenCloud/ObjectStore/Resource/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,18 @@ public function createSymlinkFrom($source)
*
* @link http://docs.rackspace.com/files/api/v1/cf-devguide/content/TempURL-d1a4450.html
*
* @param $expires Expiration time in seconds
* @param $method What method can use this URL? (`GET' or `PUT')
* @param int $expires Expiration time in seconds
* @param string $method What method can use this URL? (`GET' or `PUT')
* @param bool $forcePublicUrl If set to TRUE, a public URL will always be used. The default is to use whatever
* URL type the user has set for the main service.
*
* @return string
*
* @throws \OpenCloud\Common\Exceptions\InvalidArgumentError
* @throws \OpenCloud\Common\Exceptions\ObjectError
*
*/
public function getTemporaryUrl($expires, $method)
public function getTemporaryUrl($expires, $method, $forcePublicUrl = false)
{
$method = strtoupper($method);
$expiry = time() + (int) $expires;
Expand All @@ -477,7 +481,7 @@ public function getTemporaryUrl($expires, $method)
}
// @codeCoverageIgnoreEnd

$url = $this->getUrl();
$url = ($forcePublicUrl === true) ? $this->getService()->getEndpoint()->getPublicUrl() : $this->getUrl();
$urlPath = urldecode($url->getPath());
$body = sprintf("%s\n%d\n%s", $method, $expiry, $urlPath);
$hash = hash_hmac('sha1', $body, $secret);
Expand Down
30 changes: 28 additions & 2 deletions tests/OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,47 @@ public function test_Copy()
}

/**
* @expectedException OpenCloud\Common\Exceptions\NoNameError
* @expectedException \OpenCloud\Common\Exceptions\NoNameError
*/
public function test_Copy_Fails()
{
$this->container->dataObject()->copy(null);
}

/**
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
* @expectedException \OpenCloud\Common\Exceptions\InvalidArgumentError
*/
public function test_Temp_Url_Fails_With_Incorrect_Method()
{
$this->container->dataObject('foobar')->getTemporaryUrl(1000, 'DELETE');
}

public function test_Temp_Url_Inherits_Url_Type()
{
$service = $this->getClient()->objectStoreService(null, 'IAD', 'internalURL');
$object = $service->getContainer('foo')->dataObject('bar');

$this->addMockSubscriber(new Response(204, ['X-Account-Meta-Temp-URL-Key' => 'secret']));

$tempUrl = $object->getTemporaryUrl(60, 'GET');

// Check that internal URLs are used
$this->assertContains('snet-storage', $tempUrl);
}

public function test_temp_urls_can_be_forced_to_use_public_urls()
{
$service = $this->getClient()->objectStoreService(null, 'IAD', 'internalURL');
$object = $service->getContainer('foo')->dataObject('bar');

$this->addMockSubscriber(new Response(204, ['X-Account-Meta-Temp-URL-Key' => 'secret']));

$tempUrl = $object->getTemporaryUrl(60, 'GET', true);

// Check that internal URLs are NOT used
$this->assertNotContains('snet-storage', $tempUrl);
}

public function test_Purge()
{
$object = $this->container->dataObject('foobar');
Expand Down