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)
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()