diff --git a/storage_s3/indico_storage_s3/storage.py b/storage_s3/indico_storage_s3/storage.py index 181d771..bc7ad5e 100644 --- a/storage_s3/indico_storage_s3/storage.py +++ b/storage_s3/indico_storage_s3/storage.py @@ -223,7 +223,7 @@ class DynamicS3Storage(S3StorageBase): def _get_bucket_name(self, date): name = self._replace_bucket_placeholders(self.bucket_name_template, date) token = hmac.new(self.bucket_secret.encode('utf-8'), name, hashlib.md5).hexdigest() - return '{}-{}'.format(name, token) + return '{}-{}'.format(name, token)[:63] def _replace_bucket_placeholders(self, name, date): name = name.replace('', date.strftime('%Y')) diff --git a/storage_s3/tests/plugin_test.py b/storage_s3/tests/plugin_test.py index 9928db5..994e147 100644 --- a/storage_s3/tests/plugin_test.py +++ b/storage_s3/tests/plugin_test.py @@ -102,8 +102,10 @@ def test_static_bucket_name_too_long(): def test_dynamic_bucket_name_too_long(): - DynamicS3Storage('bucket_secret=secret,bucket_template=test-' + 'x'*37) - DynamicS3Storage('bucket_secret=secret,bucket_template=test--' + 'x'*34) + s = DynamicS3Storage('bucket_secret=secret,bucket_template=test-' + 'x'*37) + assert len(s._get_current_bucket_name()) == 63 + s = DynamicS3Storage('bucket_secret=secret,bucket_template=test--' + 'x'*34) + assert len(s._get_current_bucket_name()) == 63 with pytest.raises(StorageError): DynamicS3Storage('bucket_secret=secret,bucket_template=test-' + 'x' * 38) with pytest.raises(StorageError):