]> git.apps.os.sepia.ceph.com Git - s3-tests.git/commitdiff
s3: more testing for conditional put 663/head 673/head
authorAli Masarwa <ali.saed.masarwa@gmail.com>
Sun, 27 Jul 2025 12:18:26 +0000 (15:18 +0300)
committerAli Masarwa <ali.saed.masarwa@gmail.com>
Sun, 27 Jul 2025 13:33:33 +0000 (16:33 +0300)
Signed-off-by: Ali Masarwa <ali.saed.masarwa@gmail.com>
s3tests_boto3/functional/test_s3.py

index 1ca03da7053125d127e440ac67f349e8b98b0dd7..92715521e18b672bace890a233d5221442f97d29 100644 (file)
@@ -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():