]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
website: Start redirect tests.
authorRobin H. Johnson <robbat2@gentoo.org>
Wed, 17 Jun 2015 00:44:06 +0000 (00:44 +0000)
committerRobin H. Johnson <robin.johnson@dreamhost.com>
Wed, 20 Apr 2016 23:08:57 +0000 (16:08 -0700)
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
s3tests/functional/test_s3_website.py

index 2714ec8e476bea22824eb3be742227d8d521344e..7f6b0f900edff37beb99cc2b99b536adf9ab3de8 100644 (file)
@@ -114,6 +114,14 @@ def _website_expected_error_response(res, bucket_name, status, reason, code):
     ok('<li>Code: '+code+'</li>' in body, 'HTML should contain "Code: %s" ' % (code, ))
     ok(('<li>BucketName: %s</li>' % (bucket_name, )) in body, 'HTML should contain bucket name')
 
+def _website_expected_redirect_response(res, status, reason, new_url):
+    body = res.read()
+    print(body)
+    __website_expected_reponse_status(res, status, reason)
+    loc = res.getheader('Location', None)
+    eq(loc, new_url, 'Location header should be set "%s" != "%s"' % (loc,new_url,))
+    ok(len(body) == 0, 'Body of a redirect should be empty')
+
 def _website_request(bucket_name, path, method='GET'):
     url = get_website_url('http', bucket_name, path)
     print("url", url)
@@ -542,3 +550,64 @@ def test_website_private_bucket_list_private_index_gooderrordoc():
     indexhtml.delete()
     errorhtml.delete()
     bucket.delete()
+
+# ------ redirect tests
+
+@attr(resource='bucket')
+@attr(method='get')
+@attr(operation='list')
+@attr(assertion='RedirectAllRequestsTo without protocol should TODO')
+@attr('s3website')
+def test_website_bucket_private_redirectall_base():
+    bucket = get_new_bucket()
+    f = _test_website_prep(bucket, WEBSITE_CONFIGS_XMLFRAG['RedirectAll'])
+    bucket.set_canned_acl('private')
+
+    res = _website_request(bucket.name, '')
+    # RGW returns "302 Found" per RFC2616
+    # S3 returns 302 Moved Temporarily per RFC1945
+    new_url = 'http://%s/' % f['RedirectAllRequestsTo_HostName']
+    _website_expected_redirect_response(res, 302, ['Found', 'Moved Temporarily'], new_url)
+
+    bucket.delete()
+
+@attr(resource='bucket')
+@attr(method='get')
+@attr(operation='list')
+@attr(assertion='RedirectAllRequestsTo without protocol should TODO')
+@attr('s3website')
+def test_website_bucket_private_redirectall_path():
+    bucket = get_new_bucket()
+    f = _test_website_prep(bucket, WEBSITE_CONFIGS_XMLFRAG['RedirectAll'])
+    bucket.set_canned_acl('private')
+
+    pathfragment = choose_bucket_prefix(template='{random}', max_len=16)
+
+    res = _website_request(bucket.name, '/'+pathfragment)
+    # RGW returns "302 Found" per RFC2616
+    # S3 returns 302 Moved Temporarily per RFC1945
+    new_url = 'http://%s/%s' % (f['RedirectAllRequestsTo_HostName'], pathfragment)
+    _website_expected_redirect_response(res, 302, ['Found', 'Moved Temporarily'], new_url)
+
+    bucket.delete()
+
+@attr(resource='bucket')
+@attr(method='get')
+@attr(operation='list')
+@attr(assertion='RedirectAllRequestsTo without protocol should TODO')
+@attr('s3website')
+def test_website_bucket_private_redirectall_path_upgrade():
+    bucket = get_new_bucket()
+    x = string.Template(WEBSITE_CONFIGS_XMLFRAG['RedirectAll+Protocol']).safe_substitute(RedirectAllRequestsTo_Protocol='https')
+    f = _test_website_prep(bucket, x)
+    bucket.set_canned_acl('private')
+
+    pathfragment = choose_bucket_prefix(template='{random}', max_len=16)
+
+    res = _website_request(bucket.name, pathfragment)
+    # RGW returns "302 Found" per RFC2616
+    # S3 returns 302 Moved Temporarily per RFC1945
+    new_url = 'https://%s/%s' % (f['RedirectAllRequestsTo_HostName'], pathfragment)
+    _website_expected_redirect_response(res, 302, ['Found', 'Moved Temporarily'], new_url)
+
+    bucket.delete()