]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
s3: fixed tests
authorAli Masarwa <ali.saed.masarwa@gmail.com>
Wed, 9 Jul 2025 15:43:00 +0000 (18:43 +0300)
committerCasey Bodley <cbodley@redhat.com>
Mon, 28 Jul 2025 16:33:47 +0000 (12:33 -0400)
we expected an error if we delete non-existent objects but that is not
true

Signed-off-by: Ali Masarwa <ali.saed.masarwa@gmail.com>
(cherry picked from commit 68334301db8e2c24d4d6f2ed2f0d54ae4f453e0f)

s3tests_boto3/functional/test_s3.py

index 03208cb4eb9f826656f3415e5cca80b731586d99..9814439ef615d552a2c5a8e4f16835ed33896218 100644 (file)
@@ -3172,8 +3172,8 @@ def test_put_object_ifmatch_nonexisted_failed():
     client.meta.events.register('before-call.s3.PutObject', lf)
     e = assert_raises(ClientError, client.put_object, Bucket=bucket_name, Key='foo', Body='bar')
     status, error_code = _get_status_and_error_code(e.response)
-    assert status == 412
-    assert error_code == 'PreconditionFailed'
+    assert status == 404
+    assert error_code == 'NoSuchKey'
 
     e = assert_raises(ClientError, client.get_object, Bucket=bucket_name, Key='foo')
     status, error_code = _get_status_and_error_code(e.response)
@@ -18087,10 +18087,11 @@ def test_delete_object_if_match():
 
     client.delete_object(Bucket=bucket, Key=key, IfMatch=etag)
 
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    # -ENOENT doesn't raise error in delete op
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatch='badetag')
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
     # recreate to test IfMatch='*'
     client.put_object(Bucket=bucket, Key=key)
@@ -18104,11 +18105,11 @@ def test_delete_object_current_if_match():
     check_configure_versioning_retry(bucket, "Enabled", "Enabled")
     key = 'obj'
 
-    # on nonexistent object
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    # -ENOENT doesn't raise error in delete op
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatch='badetag')
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
     response = client.put_object(Bucket=bucket, Key=key)
     version = response['VersionId']
@@ -18121,11 +18122,10 @@ def test_delete_object_current_if_match():
     response = client.delete_object(Bucket=bucket, Key=key, IfMatch=etag)
     assert response['DeleteMarker']
 
-    # on current delete marker
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    # -ENOENT doesn't raise error in delete op
+    client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
     e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
     # remove delete marker to retest IfMatch='*'
     client.delete_object(Bucket=bucket, Key=key, VersionId=version)
@@ -18148,13 +18148,11 @@ def test_delete_object_version_if_match():
     assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
     response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch=etag)
-    assert not response['DeleteMarker']
+    assert 'DeleteMarker' not in response
 
-    # on nonexistent version
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatch='*')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatch='badetag')
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    # -ENOENT doesn't raise error in delete op
+    client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch='*')
+    client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch='badetag')
 
     # recreate to test IfMatch='*'
     response = client.put_object(Bucket=bucket, Key=key)
@@ -18178,8 +18176,8 @@ def test_delete_object_if_match_last_modified_time():
 
     client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=mtime)
 
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18200,8 +18198,9 @@ def test_delete_object_current_if_match_last_modified_time():
     response = client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=mtime)
     assert response['DeleteMarker']
 
+    # object is marked as deleted but still exists
     e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18214,16 +18213,16 @@ def test_delete_object_version_if_match_last_modified_time():
     badmtime = datetime.datetime(2015, 1, 1)
 
     version = client.put_object(Bucket=bucket, Key=key)['VersionId']
-    mtime = client.head_object(Bucket=bucket, Key=key)['LastModified']
+    mtime = client.head_object(Bucket=bucket, Key=key, VersionId=version)['LastModified']
 
     e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
     assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
     response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=mtime)
-    assert not response['DeleteMarker']
+    assert 'DeleteMarker' not in response
 
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18242,8 +18241,8 @@ def test_delete_object_if_match_size():
 
     client.delete_object(Bucket=bucket, Key=key, IfMatchSize=size)
 
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchSize=badsize)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    response = client.delete_object(Bucket=bucket, Key=key, IfMatchSize=badsize)
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18262,10 +18261,10 @@ def test_delete_object_current_if_match_size():
     assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
     response = client.delete_object(Bucket=bucket, Key=key, IfMatchSize=size)
-    assert response['DeleteMarker']
+    assert 'DeleteMarker' in response
 
     e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchSize=badsize)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18284,10 +18283,10 @@ def test_delete_object_version_if_match_size():
     assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
 
     response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchSize=size)
-    assert not response['DeleteMarker']
+    assert 'DeleteMarker' not in response
 
-    e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchSize=badsize)
-    assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+    response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchSize=badsize)
+    assert 204 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18304,8 +18303,9 @@ def test_delete_objects_if_match():
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': etag}]})
     assert key == response['Deleted'][0]['Key'] # success
 
+    # -ENOENT doesn't raise error in delete op
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': 'badetag'}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18324,8 +18324,9 @@ def test_delete_objects_current_if_match():
     assert key == response['Deleted'][0]['Key'] # success
     assert response['Deleted'][0]['DeleteMarker']
 
+    # object is marked as deleted but still exists
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': 'badetag'}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 'PreconditionFailed' == response['Errors'][0]['Code']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18344,10 +18345,10 @@ def test_delete_objects_version_if_match():
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'ETag': etag}]})
     assert key == response['Deleted'][0]['Key'] # success
-    assert not response['Deleted'][0]['DeleteMarker']
+    assert 'DeleteMarker' not in response['Deleted'][0]
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'ETag': 'badetag'}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18368,7 +18369,7 @@ def test_delete_objects_if_match_last_modified_time():
     assert key == response['Deleted'][0]['Key'] # success
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'LastModifiedTime': badmtime}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18390,8 +18391,9 @@ def test_delete_objects_current_if_match_last_modified_time():
     assert key == response['Deleted'][0]['Key'] # success
     assert response['Deleted'][0]['DeleteMarker']
 
+    # object exists, but marked as deleted
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'LastModifiedTime': badmtime}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 'PreconditionFailed' == response['Errors'][0]['Code']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18404,8 +18406,10 @@ def test_delete_objects_version_if_match_last_modified_time():
     badmtime = datetime.datetime(2015, 1, 1)
 
     version = client.put_object(Bucket=bucket, Key=key)['VersionId']
+    mtime = client.head_object(Bucket=bucket, Key=key, VersionId=version)['LastModified']
+
+    # create a different version as current
     client.put_object(Bucket=bucket, Key=key)
-    mtime = client.head_object(Bucket=bucket, Key=key)['LastModified']
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'LastModifiedTime': badmtime}]})
     assert 'PreconditionFailed' == response['Errors'][0]['Code']
@@ -18414,7 +18418,7 @@ def test_delete_objects_version_if_match_last_modified_time():
     assert key == response['Deleted'][0]['Key'] # success
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'LastModifiedTime': badmtime}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18435,7 +18439,7 @@ def test_delete_objects_if_match_size():
     assert key == response['Deleted'][0]['Key'] # success
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'Size': badsize}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18457,8 +18461,9 @@ def test_delete_objects_current_if_match_size():
     assert key == response['Deleted'][0]['Key'] # success
     assert response['Deleted'][0]['DeleteMarker']
 
+    # object exists, but marked as deleted
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'Size': badsize}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 'PreconditionFailed' == response['Errors'][0]['Code']
 
 @pytest.mark.fails_on_aws # only supported for directory buckets
 @pytest.mark.conditional_write
@@ -18480,4 +18485,4 @@ def test_delete_objects_version_if_match_size():
     assert key == response['Deleted'][0]['Key'] # success
 
     response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'Size': badsize}]})
-    assert 'NoSuchKey' == response['Errors'][0]['Code']
+    assert 200 == response['ResponseMetadata']['HTTPStatusCode']