From 1b57e794dbb6a4b339338aa66daf7c9020d4d91c Mon Sep 17 00:00:00 2001 From: matt-in-a-hat Date: Wed, 20 Jan 2016 18:07:52 +1300 Subject: [PATCH] Fix temp public URL missing file path info Should fix #648 Using `combine` didn't work, as it would either override the path info, or when swapped it would override the external host info with the internal host. --- lib/OpenCloud/ObjectStore/Resource/DataObject.php | 6 +++++- .../OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/ObjectStore/Resource/DataObject.php b/lib/OpenCloud/ObjectStore/Resource/DataObject.php index 731d1c370..5eb3c085e 100644 --- a/lib/OpenCloud/ObjectStore/Resource/DataObject.php +++ b/lib/OpenCloud/ObjectStore/Resource/DataObject.php @@ -481,7 +481,11 @@ public function getTemporaryUrl($expires, $method, $forcePublicUrl = false) } // @codeCoverageIgnoreEnd - $url = ($forcePublicUrl === true) ? $this->getService()->getEndpoint()->getPublicUrl() : $this->getUrl(); + $url = $this->getUrl(); + if ($forcePublicUrl === true) { + $url->setHost($this->getService()->getEndpoint()->getPublicUrl()->getHost()); + } + $urlPath = urldecode($url->getPath()); $body = sprintf("%s\n%d\n%s", $method, $expiry, $urlPath); $hash = hash_hmac('sha1', $body, $secret); diff --git a/tests/OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php b/tests/OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php index 3dab21171..5aee9cd81 100644 --- a/tests/OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php +++ b/tests/OpenCloud/Tests/ObjectStore/Resource/DataObjectTest.php @@ -111,6 +111,9 @@ public function test_temp_urls_can_be_forced_to_use_public_urls() // Check that internal URLs are NOT used $this->assertNotContains('snet-storage', $tempUrl); + + // Check that the URL contains the required file path + $this->assertContains('/foo/bar', $tempUrl); } public function test_Purge()