Skip to content

Commit

Permalink
Fix ExcludedPrefixes in set/get bucket versioning config
Browse files Browse the repository at this point in the history
Fix parsing of ExlucdedPrefix in set/get bucket versioning API.
ExcludedPrefixes includes Prefix tag and not ExcludedPrefix as stated in
the S3 spec.
  • Loading branch information
Anis Eleuch committed Jan 10, 2025
1 parent 6425726 commit 0f89141
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
6 changes: 3 additions & 3 deletions minio/versioningconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def fromxml(cls: Type[A], element: ET.Element) -> A:
status = findtext(element, "Status")
mfa_delete = findtext(element, "MFADelete")
excluded_prefixes = [
prefix.text
findtext(prefix, "Prefix")
for prefix in findall(
element,
"ExcludedPrefixes/ExcludedPrefix",
"ExcludedPrefixes",
)
]
exclude_folders = findtext(element, "ExcludeFolders") == "true"
Expand All @@ -99,7 +99,7 @@ def toxml(self, element: ET.Element | None) -> ET.Element:
for prefix in self._excluded_prefixes or []:
SubElement(
SubElement(element, "ExcludedPrefixes"),
"ExcludedPrefix",
"Prefix",
prefix,
)
if self._exclude_folders:
Expand Down
57 changes: 56 additions & 1 deletion tests/functional/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
SelectRequest)
from minio.sse import SseCustomerKey
from minio.time import to_http_header
from minio.versioningconfig import VersioningConfig
from minio.versioningconfig import VersioningConfig, SUSPENDED

_CLIENT = None # initialized in main().
_TEST_FILE = None # initialized in main().
Expand Down Expand Up @@ -1934,6 +1934,60 @@ def test_upload_snowball_objects_with_staging( # pylint: disable=invalid-name
staging_filename = f"{uuid4()}.tar"
_test_upload_snowball_objects(log_entry, staging_filename)

def test_set_get_bucket_versioning(log_entry):
"""Test set/get bucket_versining"""

# Get a unique bucket_name and object_name
bucket_name = _gen_bucket_name()

log_entry["args"] = {
"bucket_name": bucket_name,
}

excl_prefixes = ['prefix1', 'prefix2']

_CLIENT.make_bucket(bucket_name)

try:
# Test all fields of versioning configuration
_CLIENT.set_bucket_versioning(
bucket_name,
VersioningConfig(status=ENABLED,
exclude_folders=True,
excluded_prefixes=excl_prefixes),
)

vcfg = _CLIENT.get_bucket_versioning(bucket_name)
if vcfg.status != ENABLED:
raise ValueError(f'(1) unexpected get_bucket_versioning result: '
f'status: {vcfg.status}')
if not vcfg.exclude_folders:
raise ValueError(f'(1) unexpected get_bucket_versioning result: '
f'exclude_folders: {vcfg.exclude_folders}')
if set(vcfg.excluded_prefixes) != set(excl_prefixes):
raise ValueError(f'(1) unexpected get_bucket_versioning result: '
f'excluded_prefixes: {vcfg.excluded_prefixes}')

# Disable all fields of versioning configuration
_CLIENT.set_bucket_versioning(
bucket_name,
VersioningConfig(status=SUSPENDED),
)

vcfg = _CLIENT.get_bucket_versioning(bucket_name)
if vcfg.status != SUSPENDED:
raise ValueError(f'(2) unexpected get_bucket_versioning result: '
f'status: {vcfg.status}')
if vcfg.exclude_folders:
raise ValueError(f'(2) unexpected get_bucket_versioning result: '
f'exclude_folders: {vcfg.exclude_folders}')
if len(vcfg.excluded_prefixes) != 0:
raise ValueError(f'(2) unexpected get_bucket_versioning result: '
f'excluded_prefixes: {vcfg.excluded_prefixes}')

finally:
_CLIENT.remove_bucket(bucket_name)


def main():
"""
Expand Down Expand Up @@ -2026,6 +2080,7 @@ def main():
test_presigned_put_object_expiry: None,
test_presigned_post_policy: None,
test_thread_safe: None,
test_set_get_bucket_versioning: None,
test_get_bucket_policy: None,
test_set_bucket_policy_readonly: None,
test_set_bucket_policy_readwrite: None,
Expand Down

0 comments on commit 0f89141

Please sign in to comment.