Blind whole buckets with invalid name

This patch achieves to blind whole invalid name buckets made
by some reasons. (e.g. PUT from Swift API, +segment container for
MultiUpload usage)

Change-Id: I2a0488e62fc45ea4c878f2d328b5b45eddc35fa3
This commit is contained in:
Kota Tsuyuzaki
2014-12-15 18:23:51 -08:00
parent bb4dedd48c
commit dde7cb61ff
2 changed files with 43 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ from simplejson import loads
from swift3.controllers.base import Controller
from swift3.etree import Element, SubElement, tostring
from swift3.response import HTTPOk
from swift3.utils import validate_bucket_name
class ServiceController(Controller):
@@ -31,6 +32,10 @@ class ServiceController(Controller):
resp = req.get_response(self.app, query={'format': 'json'})
containers = loads(resp.body)
containers = filter(
lambda item: validate_bucket_name(item['name']), containers)
# we don't keep the creation time of a backet (s3cmd doesn't
# work without that) so we use something bogus.
elem = Element('ListAllMyBucketsResult')

View File

@@ -96,5 +96,43 @@ class TestSwift3Service(Swift3TestCase):
for i in self.buckets:
self.assertTrue(i[0] in names)
def test_service_GET_with_blind_resource(self):
buckets = (('apple', 1, 200), ('orange', 3, 430),
('apple+segment', 1, 200))
expected = buckets[:-1]
json_pattern = ['"name":%s', '"count":%s', '"bytes":%s']
json_pattern = '{' + ','.join(json_pattern) + '}'
json_out = []
for b in buckets:
name = simplejson.dumps(b[0])
json_out.append(json_pattern %
(name, b[1], b[2]))
bucket_list = '[' + ','.join(json_out) + ']'
self.swift.register('GET', '/v1/AUTH_test', swob.HTTPOk, {},
bucket_list)
req = Request.blank('/',
environ={'REQUEST_METHOD': 'GET'},
headers={'Authorization': 'AWS test:tester:hmac'})
status, headers, body = self.call_swift3(req)
self.assertEquals(status.split()[0], '200')
elem = fromstring(body, 'ListAllMyBucketsResult')
all_buckets = elem.find('./Buckets')
buckets = all_buckets.iterchildren('Bucket')
listing = list(list(buckets)[0])
self.assertEquals(len(listing), 2)
names = []
for b in all_buckets.iterchildren('Bucket'):
names.append(b.find('./Name').text)
self.assertEquals(len(names), len(expected))
for i in expected:
self.assertTrue(i[0] in names)
if __name__ == '__main__':
unittest.main()