Test to check temp url support
Adds a test case to test_object_services.py so as to verify the
GET object using temp url.And also a method to GET object
using the temp url in object_client.py
Change-Id: I929ffabf8a1344f21c8acc492f8c4e31966556fd
implements: blueprint add-some-functional-swift-tests
diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py
index 03cd209..2256170 100644
--- a/tempest/services/object_storage/object_client.py
+++ b/tempest/services/object_storage/object_client.py
@@ -15,11 +15,14 @@
# License for the specific language governing permissions and limitations
# under the License.
+from hashlib import sha1
+import hmac
import httplib2
import json
import re
from tempest.common.rest_client import RestClient
from tempest import exceptions
+from urlparse import urlparse
class ObjectClient(RestClient):
@@ -120,6 +123,23 @@
resp, body = self.copy(url, headers=headers)
return resp, body
+ def get_object_using_temp_url(self, container, object_name, expires, key):
+ """Retrieve object's data using temp URL."""
+
+ self._set_auth()
+ method = 'GET'
+ path = "%s/%s/%s" % (urlparse(self.base_url).path, container,
+ object_name)
+ hmac_body = '%s\n%s\n%s' % (method, expires, path)
+ sig = hmac.new(key, hmac_body, sha1).hexdigest()
+
+ url = "%s/%s?temp_url_sig=%s&temp_url_expires=%s" % (container,
+ object_name,
+ sig, expires)
+
+ resp, body = self.get(url)
+ return resp, body
+
class ObjectClientCustomizedHeader(RestClient):
diff --git a/tempest/tests/object_storage/test_object_services.py b/tempest/tests/object_storage/test_object_services.py
index d380da6..fc3f45f 100644
--- a/tempest/tests/object_storage/test_object_services.py
+++ b/tempest/tests/object_storage/test_object_services.py
@@ -21,6 +21,7 @@
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
from tempest.tests.object_storage import base
+from time import time
import unittest2 as unittest
@@ -611,3 +612,47 @@
self.custom_object_client.delete_object,
self.container_name, object_name,
metadata=self.custom_headers)
+
+ @unittest.skip('Until bug 1097137 is resolved.')
+ @attr(type='positive')
+ def test_get_object_using_temp_url(self):
+ #Access object using temp url within expiry time
+
+ try:
+ #Update Account Metadata
+ # Flag to check if account metadata got updated
+ flag = False
+ key = 'Meta'
+ metadata = {'Temp-URL-Key': key}
+ resp, _ = \
+ self.account_client.create_account_metadata(metadata=metadata)
+ self.assertEqual(resp['status'], '204')
+ flag = True
+
+ resp, _ = self.account_client.list_account_metadata()
+ self.assertIn('x-account-meta-temp-url-key', resp)
+ self.assertEqual(resp['x-account-meta-temp-url-key'], key)
+
+ # Create Object
+ object_name = rand_name(name='ObjectTemp')
+ data = arbitrary_string(size=len(object_name),
+ base_text=object_name)
+ self.object_client.create_object(self.container_name,
+ object_name, data)
+
+ expires = int(time() + 10)
+
+ #Trying to GET object using temp URL with in expiry time
+ _, body = \
+ self.object_client.get_object_using_temp_url(
+ self.container_name, object_name, expires, key)
+
+ self.assertEqual(body, data)
+
+ finally:
+ if flag:
+ resp, _ = \
+ self.account_client.delete_account_metadata(
+ metadata=metadata)
+ resp, _ = self.account_client.list_account_metadata()
+ self.assertNotIn('x-account-meta-temp-url-key', resp)