From 8be24ac631850e7da8e52fad6041c36684acb606 Mon Sep 17 00:00:00 2001 From: Ali Masarwa Date: Sun, 27 Jul 2025 15:18:26 +0300 Subject: [PATCH] s3: more testing for conditional put Signed-off-by: Ali Masarwa --- s3tests_boto3/functional/test_s3.py | 69 ++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/s3tests_boto3/functional/test_s3.py b/s3tests_boto3/functional/test_s3.py index 1ca03da7..92715521 100644 --- a/s3tests_boto3/functional/test_s3.py +++ b/s3tests_boto3/functional/test_s3.py @@ -18314,6 +18314,8 @@ def test_put_object_if_match(): assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfNoneMatch=etag) assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + response = client.put_object(Bucket=bucket, Key=key, IfNoneMatch='badetag') + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] client.put_object(Bucket=bucket, Key=key, IfMatch=etag) @@ -18324,7 +18326,72 @@ def test_put_object_if_match(): e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch='badetag') assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response) - client.put_object(Bucket=bucket, Key=key, IfNoneMatch=etag) + response = client.put_object(Bucket=bucket, Key=key, IfNoneMatch=etag) + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + response = client.put_object(Bucket=bucket, Key=key, IfMatch='*') + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch='badetag') + assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + response = client.put_object(Bucket=bucket, Key=key, IfMatch=etag) + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + +@pytest.mark.conditional_write +def test_put_current_object_if_none_match(): + client = get_client() + bucket = get_new_bucket(client) + check_configure_versioning_retry(bucket, "Enabled", "Enabled") + key = 'obj' + data1 = 'data1' + data2 = 'data2' + + response = client.put_object(Bucket=bucket, Key=key, Body=data1, IfNoneMatch='*') + etag = response['ETag'] + + response = client.put_object(Bucket=bucket, Key=key, Body=data2) + etag2 = response['ETag'] + + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfNoneMatch='*') + assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfNoneMatch=etag2) + assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + + # we can't specify a version, so we only check against current object + response = client.put_object(Bucket=bucket, Key=key, IfNoneMatch=etag) + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + response = client.put_object(Bucket=bucket, Key=key, IfNoneMatch='badetag') + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + + client.delete_object(Bucket=bucket, Key=key) + +@pytest.mark.conditional_write +def test_put_current_object_if_match(): + client = get_client() + bucket = get_new_bucket(client) + check_configure_versioning_retry(bucket, "Enabled", "Enabled") + key = 'obj' + data1 = 'data1' + data2 = 'data2' + etag = 'deadbeef' + + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch='*') + assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response) + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch='badetag') + assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response) + + response = client.put_object(Bucket=bucket, Key=key, Body=data1, IfNoneMatch=etag) + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + etag = response['ETag'] + versionId = response['VersionId'] + response = client.put_object(Bucket=bucket, Key=key, Body=data2, IfMatch='*') + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] + etag2 = response['ETag'] + + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch='badetag') + assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + e = assert_raises(ClientError, client.put_object, Bucket=bucket, Key=key, IfMatch=etag) + assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response) + response = client.put_object(Bucket=bucket, Key=key, IfMatch=etag2) + assert 200 == response['ResponseMetadata']['HTTPStatusCode'] @pytest.mark.conditional_write def test_put_object_current_if_match(): -- 2.39.5