Skip to content

Commit 4b7fdd7

Browse files
committed
chore(pubsub): add subscriber role test for streaming
Pulling the messages using a streaming pull should work with accounts having only the pubsub.subscriber role. This commits add a test that covers this aspect.
1 parent 8c3b652 commit 4b7fdd7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pubsub/tests/system.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,38 @@ def test_streaming_pull_max_messages(
488488
finally:
489489
subscription_future.cancel() # trigger clean shutdown
490490

491+
def test_streaming_pull_subscriber_permissions_sufficient(
492+
self, publisher, topic_path, subscriber, subscription_path, cleanup
493+
):
494+
495+
# Make sure the topic and subscription get deleted.
496+
cleanup.append((publisher.delete_topic, topic_path))
497+
cleanup.append((subscriber.delete_subscription, subscription_path))
498+
499+
# create a topic and subscribe to it
500+
publisher.create_topic(topic_path)
501+
subscriber.create_subscription(subscription_path, topic_path)
502+
503+
# TODO: A service account granting only the pubsub.subscriber role must
504+
# be used
505+
filename = "/some/service/account/file.json.json"
506+
streaming_pull_subscriber = type(subscriber).from_service_account_file(filename)
507+
508+
# Subscribe to the topic, publish a message, and verify that subscriber
509+
# successfully pulls and processes it.
510+
callback = StreamingPullCallback(processing_time=0.01, resolve_at_msg_count=1)
511+
future = streaming_pull_subscriber.subscribe(subscription_path, callback)
512+
self._publish_messages(publisher, topic_path, batch_sizes=[1])
513+
514+
try:
515+
callback.done_future.result(timeout=10)
516+
except exceptions.TimeoutError:
517+
pytest.fail(
518+
"Timeout: receiving/processing streamed messages took too long."
519+
)
520+
else:
521+
assert 1 in callback.seen_message_ids
522+
491523
def _publish_messages(self, publisher, topic_path, batch_sizes):
492524
"""Publish ``count`` messages in batches and wait until completion."""
493525
publish_futures = []

0 commit comments

Comments
 (0)