Skip to content

Commit 7ce4e0b

Browse files
authored
chore: fix system tests due to Public access prevention (#1526)
* fix: test_blob_acl_w_metageneration_match * fix: test_blob_acl_upload_predefined * remove unwanted comments and code * remove unwanted code
1 parent e84906c commit 7ce4e0b

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

tests/system/test_blob.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,26 +425,23 @@ def test_blob_acl_w_metageneration_match(
425425

426426
# Exercise blob ACL with metageneration/generation match
427427
acl = blob.acl
428-
blob.reload()
428+
acl.domain("google.com").grant_read()
429429

430430
with pytest.raises(exceptions.PreconditionFailed):
431-
acl.save_predefined(
432-
"publicRead", if_metageneration_match=wrong_metageneration_number
433-
)
434-
assert "READER" not in acl.all().get_roles()
431+
acl.save(if_metageneration_match=wrong_metageneration_number)
432+
assert "READER" not in acl.domain("google.com").get_roles()
435433

436-
acl.save_predefined("publicRead", if_metageneration_match=blob.metageneration)
437-
assert "READER" in acl.all().get_roles()
434+
acl.save(if_metageneration_match=blob.metageneration)
438435

439-
blob.reload()
440-
del acl.entities["allUsers"]
436+
assert "READER" in acl.domain("google.com").get_roles()
437+
acl.domain("google.com").revoke_read()
441438

442439
with pytest.raises(exceptions.PreconditionFailed):
443440
acl.save(if_generation_match=wrong_generation_number)
444-
assert acl.has_entity("allUsers")
441+
assert "READER" in acl.domain("google.com").get_roles()
445442

446443
acl.save(if_generation_match=blob.generation)
447-
assert not acl.has_entity("allUsers")
444+
assert "READER" not in acl.domain("google.com").get_roles()
448445

449446

450447
def test_blob_acl_upload_predefined(
@@ -453,31 +450,32 @@ def test_blob_acl_upload_predefined(
453450
file_data,
454451
service_account,
455452
):
456-
control = shared_bucket.blob(f"logo{uuid.uuid4().hex}")
457-
control_info = file_data["logo"]
453+
control_blob = shared_bucket.blob(f"logo{uuid.uuid4().hex}")
454+
control_blob_info = file_data["logo"]
458455

459456
blob = shared_bucket.blob(f"SmallFile{uuid.uuid4().hex}")
460457
info = file_data["simple"]
461458

462459
try:
463-
control.upload_from_filename(control_info["path"])
460+
control_blob.upload_from_filename(control_blob_info["path"])
464461
finally:
465-
blobs_to_delete.append(control)
466-
462+
blobs_to_delete.append(control_blob)
467463
try:
468-
blob.upload_from_filename(info["path"], predefined_acl="publicRead")
464+
blob.upload_from_filename(info["path"], predefined_acl="private")
469465
finally:
470466
blobs_to_delete.append(blob)
471467

472-
control_acl = control.acl
473-
assert "READER" not in control_acl.all().get_roles()
468+
control_blob_acl = control_blob.acl
474469

475470
acl = blob.acl
476-
assert "READER" in acl.all().get_roles()
477-
478-
acl.all().revoke_read()
479-
assert acl.all().get_roles() == set()
480-
assert control_acl.all().get_roles() == acl.all().get_roles()
471+
count = 0
472+
for entry in acl:
473+
count += 1
474+
entity = entry["entity"]
475+
assert count == 1
476+
assert entity.lstrip("user-") == service_account.service_account_email
477+
478+
assert sum(1 for _ in control_blob_acl) > 1
481479

482480

483481
def test_blob_patch_metadata(

0 commit comments

Comments
 (0)