Skip to content

Commit a644136

Browse files
committed
fix: add preconditions and retry config support to ACL patch operationss (googleapis#586)
* add preconditions and retry config support to ACL patch operations * update existing unit tests * add unit tests * add preconditions and retry config to bucket make public/private * add preconditions and retry config to blob make public/private * update docstrings * add system tests acl with metegeneration match * revise to use permitted group email
1 parent 12c553c commit a644136

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

tests/system/test_blob.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,41 @@ def test_blob_acl_w_user_project(
373373
assert not acl.has_entity("allUsers")
374374

375375

376+
def test_blob_acl_w_metageneration_match(
377+
shared_bucket, blobs_to_delete, file_data, service_account,
378+
):
379+
wrong_metageneration_number = 9
380+
wrong_generation_number = 6
381+
382+
blob = shared_bucket.blob("FilePatchACL")
383+
info = file_data["simple"]
384+
blob.upload_from_filename(info["path"])
385+
blobs_to_delete.append(blob)
386+
387+
# Exercise blob ACL with metageneration/generation match
388+
acl = blob.acl
389+
blob.reload()
390+
391+
with pytest.raises(exceptions.PreconditionFailed):
392+
acl.save_predefined(
393+
"publicRead", if_metageneration_match=wrong_metageneration_number
394+
)
395+
assert "READER" not in acl.all().get_roles()
396+
397+
acl.save_predefined("publicRead", if_metageneration_match=blob.metageneration)
398+
assert "READER" in acl.all().get_roles()
399+
400+
blob.reload()
401+
del acl.entities["allUsers"]
402+
403+
with pytest.raises(exceptions.PreconditionFailed):
404+
acl.save(if_generation_match=wrong_generation_number)
405+
assert acl.has_entity("allUsers")
406+
407+
acl.save(if_generation_match=blob.generation)
408+
assert not acl.has_entity("allUsers")
409+
410+
376411
def test_blob_acl_upload_predefined(
377412
shared_bucket, blobs_to_delete, file_data, service_account,
378413
):

tests/system/test_bucket.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,42 @@ def test_bucket_acls_iam_w_user_project(
246246
with_user_project.set_iam_policy(policy)
247247

248248

249+
def test_bucket_acls_w_metageneration_match(storage_client, buckets_to_delete):
250+
wrong_metageneration_number = 9
251+
bucket_name = _helpers.unique_name("acl-w-metageneration-match")
252+
bucket = _helpers.retry_429_503(storage_client.create_bucket)(bucket_name)
253+
buckets_to_delete.append(bucket)
254+
255+
# Exercise bucket ACL with metageneration match
256+
acl = bucket.acl
257+
acl.group("cloud-developer-relations@google.com").grant_read()
258+
bucket.reload()
259+
260+
with pytest.raises(exceptions.PreconditionFailed):
261+
acl.save(if_metageneration_match=wrong_metageneration_number)
262+
assert (
263+
"READER"
264+
not in acl.group("cloud-developer-relations@google.com").get_roles()
265+
)
266+
267+
acl.save(if_metageneration_match=bucket.metageneration)
268+
assert "READER" in acl.group("cloud-developer-relations@google.com").get_roles()
269+
270+
# Exercise default object ACL w/ metageneration match
271+
doa = bucket.default_object_acl
272+
doa.group("cloud-developer-relations@google.com").grant_owner()
273+
bucket.reload()
274+
275+
with pytest.raises(exceptions.PreconditionFailed):
276+
doa.save(if_metageneration_match=wrong_metageneration_number)
277+
assert (
278+
"OWNER" not in doa.group("cloud-developer-relations@google.com").get_roles()
279+
)
280+
281+
doa.save(if_metageneration_match=bucket.metageneration)
282+
assert "OWNER" in doa.group("cloud-developer-relations@google.com").get_roles()
283+
284+
249285
def test_bucket_copy_blob(
250286
storage_client, buckets_to_delete, blobs_to_delete, user_project,
251287
):

0 commit comments

Comments
 (0)