def test_names(self): assert_true(validate_bucket_name('imagoodname')) assert_true(validate_bucket_name('still.passing')) assert_true(validate_bucket_name('can-have-dashes')) assert_true(validate_bucket_name('kinda.name.spaced')) assert_true(validate_bucket_name('a-o.valid')) assert_true(validate_bucket_name('11.12.m')) assert_true(validate_bucket_name('a--------a')) assert_true(validate_bucket_name('a' * 63))
def create_bucket(auth, node_addon, **kwargs): bucket_name = request.json.get('bucket_name', '') bucket_location = request.json.get('bucket_location', '') if not utils.validate_bucket_name(bucket_name): return { 'message': 'That bucket name is not valid.', 'title': 'Invalid bucket name', }, httplib.BAD_REQUEST # Get location and verify it is valid if not utils.validate_bucket_location(bucket_location): return { 'message': 'That bucket location is not valid.', 'title': 'Invalid bucket location', }, httplib.BAD_REQUEST try: utils.create_bucket(node_addon, bucket_name, bucket_location) except exception.S3ResponseError as e: return { 'message': e.message, 'title': 'Problem connecting to S3', }, httplib.BAD_REQUEST except exception.S3CreateError as e: return { 'message': e.message, 'title': "Problem creating bucket '{0}'".format(bucket_name), }, httplib.BAD_REQUEST except exception.BotoClientError as e: # Base class catchall return { 'message': e.message, 'title': 'Error connecting to S3', }, httplib.BAD_REQUEST return {}
def test_bad_names(self): assert_false(validate_bucket_name('')) assert_false(validate_bucket_name('no')) assert_false(validate_bucket_name('a' * 64)) assert_false(validate_bucket_name(' leadingspace')) assert_false(validate_bucket_name('trailingspace ')) assert_false(validate_bucket_name('bogus naMe')) assert_false(validate_bucket_name('.cantstartwithp')) assert_false(validate_bucket_name('or.endwith.')) assert_false(validate_bucket_name('..nodoubles')) assert_false(validate_bucket_name('no_unders_in')) assert_false(validate_bucket_name('-leadinghyphen')) assert_false(validate_bucket_name('trailinghyphen-')) assert_false(validate_bucket_name('Mixedcase')) assert_false(validate_bucket_name('empty..label')) assert_false(validate_bucket_name('label-.trailinghyphen')) assert_false(validate_bucket_name('label.-leadinghyphen')) assert_false(validate_bucket_name('8.8.8.8')) assert_false(validate_bucket_name('600.9000.0.28')) assert_false(validate_bucket_name('no_underscore')) assert_false(validate_bucket_name('_nounderscoreinfront')) assert_false(validate_bucket_name('no-underscore-in-back_')) assert_false(validate_bucket_name('no-underscore-in_the_middle_either'))
def test_bad_names(self): assert_false(validate_bucket_name('')) assert_false(validate_bucket_name('no')) assert_false(validate_bucket_name('a' * 64)) assert_false(validate_bucket_name(' leadingspace')) assert_false(validate_bucket_name('trailingspace ')) assert_false(validate_bucket_name('bogus naMe')) assert_false(validate_bucket_name('.cantstartwithp')) assert_false(validate_bucket_name('or.endwith.')) assert_false(validate_bucket_name('..nodoubles')) assert_false(validate_bucket_name('no_unders_in')) assert_false(validate_bucket_name('-leadinghyphen')) assert_false(validate_bucket_name('trailinghyphen-')) assert_false(validate_bucket_name('Mixedcase')) assert_false(validate_bucket_name('empty..label')) assert_false(validate_bucket_name('label-.trailinghyphen')) assert_false(validate_bucket_name('label.-leadinghyphen')) assert_false(validate_bucket_name('8.8.8.8')) assert_false(validate_bucket_name('600.9000.0.28')) assert_false(validate_bucket_name('no_underscore')) assert_false(validate_bucket_name('_nounderscoreinfront')) assert_false(validate_bucket_name('no-underscore-in-back_')) assert_false( validate_bucket_name('no-underscore-in_the_middle_either'))