Skip to content

Commit 7216b1e

Browse files
authored
Merge branch 'master' into release-v2.0.0
2 parents 8f258a2 + 93482c6 commit 7216b1e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

system_tests/system_tests_sync/test_downscoping.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@
3737
_INACCESSIBLE_OBJECT_NAME = "other-customer-data.txt"
3838

3939

40-
@pytest.fixture
40+
@pytest.fixture(scope="module")
4141
def temp_bucket():
4242
"""Yields a bucket that is deleted after the test completes."""
4343
bucket = None
4444
while bucket is None or bucket.exists():
45-
bucket_name = "bucket-downscoping-test-{}".format(uuid.uuid4())
45+
bucket_name = "auth-python-downscope-test-{}".format(uuid.uuid4())
4646
bucket = storage.Client().bucket(bucket_name)
4747
bucket = storage.Client().create_bucket(bucket.name)
4848
yield bucket
4949
bucket.delete(force=True)
5050

5151

52-
@pytest.fixture
52+
@pytest.fixture(scope="module")
5353
def temp_blobs(temp_bucket):
54-
"""Yields a blob that is deleted after the test completes."""
54+
"""Yields two blobs that are deleted after the test completes."""
5555
bucket = temp_bucket
5656
# Downscoped tokens will have readonly access to this blob.
5757
accessible_blob = bucket.blob(_ACCESSIBLE_OBJECT_NAME)
@@ -60,6 +60,7 @@ def temp_blobs(temp_bucket):
6060
inaccessible_blob = bucket.blob(_INACCESSIBLE_OBJECT_NAME)
6161
inaccessible_blob.upload_from_string(_INACCESSIBLE_CONTENT)
6262
yield (accessible_blob, inaccessible_blob)
63+
bucket.delete_blobs([accessible_blob, inaccessible_blob])
6364

6465

6566
def get_token_from_broker(bucket_name, object_prefix):
@@ -81,9 +82,7 @@ def get_token_from_broker(bucket_name, object_prefix):
8182
# Only objects starting with the specified prefix string in the object name
8283
# will be allowed read access.
8384
availability_expression = (
84-
"resource.name.startsWith('projects/_/buckets/{}/objects/{}')".format(
85-
bucket_name, object_prefix
86-
)
85+
f"resource.name.startsWith('projects/_/buckets/{bucket_name}/objects/{object_prefix}')"
8786
)
8887
availability_condition = downscoped.AvailabilityCondition(availability_expression)
8988
# Define the single access boundary rule using the above properties.
@@ -151,13 +150,13 @@ def refresh_handler(request, scopes=None):
151150
assert blob.download_as_bytes().decode("utf-8") == _ACCESSIBLE_CONTENT
152151

153152
# Test write access fails.
154-
with pytest.raises(exceptions.GoogleCloudError) as excinfo:
153+
with pytest.raises(exceptions.Forbidden) as excinfo:
155154
blob.upload_from_string("Write operations are not allowed")
156155

157156
assert excinfo.match(r"does not have storage.objects.create access")
158157

159158
# Test read access fails to inaccessible blob.
160-
with pytest.raises(exceptions.GoogleCloudError) as excinfo:
159+
with pytest.raises(exceptions.Forbidden) as excinfo:
161160
bucket.blob(inaccessible_blob.name).download_as_bytes()
162161

163162
assert excinfo.match(r"does not have storage.objects.get access")

0 commit comments

Comments
 (0)