-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add system tests for topic/subscription IAM policy get/set methods. #1654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tseaver
merged 4 commits into
googleapis:master
from
tseaver:pubsub-system_tests-iam_policy
Mar 29, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
21cfae6
Add system tests for topic/subscription IAM policy get/set methods.
tseaver e770e9e
Rename 'readers'->'viewers', 'writers'->'editors'.
tseaver da06d10
Use role-name constants.
tseaver 0116b18
Assert created topic/subscription exists before use.
tseaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,8 @@ def test_ctor_defaults(self): | |
| self.assertEqual(policy.etag, None) | ||
| self.assertEqual(policy.version, None) | ||
| self.assertEqual(list(policy.owners), []) | ||
| self.assertEqual(list(policy.writers), []) | ||
| self.assertEqual(list(policy.readers), []) | ||
| self.assertEqual(list(policy.editors), []) | ||
| self.assertEqual(list(policy.viewers), []) | ||
|
|
||
| def test_ctor_explicit(self): | ||
| VERSION = 17 | ||
|
|
@@ -39,8 +39,8 @@ def test_ctor_explicit(self): | |
| self.assertEqual(policy.etag, ETAG) | ||
| self.assertEqual(policy.version, VERSION) | ||
| self.assertEqual(list(policy.owners), []) | ||
| self.assertEqual(list(policy.writers), []) | ||
| self.assertEqual(list(policy.readers), []) | ||
| self.assertEqual(list(policy.editors), []) | ||
| self.assertEqual(list(policy.viewers), []) | ||
|
|
||
| def test_user(self): | ||
| EMAIL = '[email protected]' | ||
|
|
@@ -83,33 +83,33 @@ def test_from_api_repr_only_etag(self): | |
| self.assertEqual(policy.etag, 'ACAB') | ||
| self.assertEqual(policy.version, None) | ||
| self.assertEqual(list(policy.owners), []) | ||
| self.assertEqual(list(policy.writers), []) | ||
| self.assertEqual(list(policy.readers), []) | ||
| self.assertEqual(list(policy.editors), []) | ||
| self.assertEqual(list(policy.viewers), []) | ||
|
|
||
| def test_from_api_repr_complete(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, WRITER_ROLE, READER_ROLE | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| OWNER1 = 'user:[email protected]' | ||
| OWNER2 = 'group:[email protected]' | ||
| WRITER1 = 'domain:google.com' | ||
| WRITER2 = 'user:[email protected]' | ||
| READER1 = 'serviceAccount:[email protected]' | ||
| READER2 = 'user:[email protected]' | ||
| EDITOR1 = 'domain:google.com' | ||
| EDITOR2 = 'user:[email protected]' | ||
| VIEWER1 = 'serviceAccount:[email protected]' | ||
| VIEWER2 = 'user:[email protected]' | ||
| RESOURCE = { | ||
| 'etag': 'DEADBEEF', | ||
| 'version': 17, | ||
| 'bindings': [ | ||
| {'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]}, | ||
| {'role': WRITER_ROLE, 'members': [WRITER1, WRITER2]}, | ||
| {'role': READER_ROLE, 'members': [READER1, READER2]}, | ||
| {'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, | ||
| {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, | ||
| ], | ||
| } | ||
| klass = self._getTargetClass() | ||
| policy = klass.from_api_repr(RESOURCE) | ||
| self.assertEqual(policy.etag, 'DEADBEEF') | ||
| self.assertEqual(policy.version, 17) | ||
| self.assertEqual(sorted(policy.owners), [OWNER2, OWNER1]) | ||
| self.assertEqual(sorted(policy.writers), [WRITER1, WRITER2]) | ||
| self.assertEqual(sorted(policy.readers), [READER1, READER2]) | ||
| self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2]) | ||
| self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2]) | ||
|
|
||
| def test_from_api_repr_bad_role(self): | ||
| BOGUS1 = 'user:[email protected]' | ||
|
|
@@ -134,27 +134,27 @@ def test_to_api_repr_only_etag(self): | |
| self.assertEqual(policy.to_api_repr(), {'etag': 'DEADBEEF'}) | ||
|
|
||
| def test_to_api_repr_full(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, WRITER_ROLE, READER_ROLE | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| OWNER1 = 'group:[email protected]' | ||
| OWNER2 = 'user:[email protected]' | ||
| WRITER1 = 'domain:google.com' | ||
| WRITER2 = 'user:[email protected]' | ||
| READER1 = 'serviceAccount:[email protected]' | ||
| READER2 = 'user:[email protected]' | ||
| EDITOR1 = 'domain:google.com' | ||
| EDITOR2 = 'user:[email protected]' | ||
| VIEWER1 = 'serviceAccount:[email protected]' | ||
| VIEWER2 = 'user:[email protected]' | ||
| EXPECTED = { | ||
| 'etag': 'DEADBEEF', | ||
| 'version': 17, | ||
| 'bindings': [ | ||
| {'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]}, | ||
| {'role': WRITER_ROLE, 'members': [WRITER1, WRITER2]}, | ||
| {'role': READER_ROLE, 'members': [READER1, READER2]}, | ||
| {'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, | ||
| {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, | ||
| ], | ||
| } | ||
| policy = self._makeOne('DEADBEEF', 17) | ||
| policy.owners.add(OWNER1) | ||
| policy.owners.add(OWNER2) | ||
| policy.writers.add(WRITER1) | ||
| policy.writers.add(WRITER2) | ||
| policy.readers.add(READER1) | ||
| policy.readers.add(READER2) | ||
| policy.editors.add(EDITOR1) | ||
| policy.editors.add(EDITOR2) | ||
| policy.viewers.add(VIEWER1) | ||
| policy.viewers.add(VIEWER2) | ||
| self.assertEqual(policy.to_api_repr(), EXPECTED) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,20 +485,20 @@ def test_delete_w_alternate_client(self): | |
| self.assertEqual(req['path'], '/%s' % SUB_PATH) | ||
|
|
||
| def test_get_iam_policy_w_bound_client(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, WRITER_ROLE, READER_ROLE | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| OWNER1 = 'user:[email protected]' | ||
| OWNER2 = 'group:[email protected]' | ||
| WRITER1 = 'domain:google.com' | ||
| WRITER2 = 'user:[email protected]' | ||
| READER1 = 'serviceAccount:[email protected]' | ||
| READER2 = 'user:[email protected]' | ||
| EDITOR1 = 'domain:google.com' | ||
| EDITOR2 = 'user:[email protected]' | ||
| VIEWER1 = 'serviceAccount:[email protected]' | ||
| VIEWER2 = 'user:[email protected]' | ||
| POLICY = { | ||
| 'etag': 'DEADBEEF', | ||
| 'version': 17, | ||
| 'bindings': [ | ||
| {'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]}, | ||
| {'role': WRITER_ROLE, 'members': [WRITER1, WRITER2]}, | ||
| {'role': READER_ROLE, 'members': [READER1, READER2]}, | ||
| {'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, | ||
| {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, | ||
| ], | ||
| } | ||
| PROJECT = 'PROJECT' | ||
|
|
@@ -517,8 +517,8 @@ def test_get_iam_policy_w_bound_client(self): | |
| self.assertEqual(policy.etag, 'DEADBEEF') | ||
| self.assertEqual(policy.version, 17) | ||
| self.assertEqual(sorted(policy.owners), [OWNER2, OWNER1]) | ||
| self.assertEqual(sorted(policy.writers), [WRITER1, WRITER2]) | ||
| self.assertEqual(sorted(policy.readers), [READER1, READER2]) | ||
| self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2]) | ||
| self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2]) | ||
|
|
||
| self.assertEqual(len(conn._requested), 1) | ||
| req = conn._requested[0] | ||
|
|
@@ -547,8 +547,8 @@ def test_get_iam_policy_w_alternate_client(self): | |
| self.assertEqual(policy.etag, 'ACAB') | ||
| self.assertEqual(policy.version, None) | ||
| self.assertEqual(sorted(policy.owners), []) | ||
| self.assertEqual(sorted(policy.writers), []) | ||
| self.assertEqual(sorted(policy.readers), []) | ||
| self.assertEqual(sorted(policy.editors), []) | ||
| self.assertEqual(sorted(policy.viewers), []) | ||
|
|
||
| self.assertEqual(len(conn1._requested), 0) | ||
| self.assertEqual(len(conn2._requested), 1) | ||
|
|
@@ -557,21 +557,21 @@ def test_get_iam_policy_w_alternate_client(self): | |
| self.assertEqual(req['path'], '/%s' % PATH) | ||
|
|
||
| def test_set_iam_policy_w_bound_client(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, WRITER_ROLE, READER_ROLE | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| from gcloud.pubsub.iam import Policy | ||
| OWNER1 = 'group:[email protected]' | ||
| OWNER2 = 'user:[email protected]' | ||
| WRITER1 = 'domain:google.com' | ||
| WRITER2 = 'user:[email protected]' | ||
| READER1 = 'serviceAccount:[email protected]' | ||
| READER2 = 'user:[email protected]' | ||
| EDITOR1 = 'domain:google.com' | ||
| EDITOR2 = 'user:[email protected]' | ||
| VIEWER1 = 'serviceAccount:[email protected]' | ||
| VIEWER2 = 'user:[email protected]' | ||
| POLICY = { | ||
| 'etag': 'DEADBEEF', | ||
| 'version': 17, | ||
| 'bindings': [ | ||
| {'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]}, | ||
| {'role': WRITER_ROLE, 'members': [WRITER1, WRITER2]}, | ||
| {'role': READER_ROLE, 'members': [READER1, READER2]}, | ||
| {'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, | ||
| {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, | ||
| ], | ||
| } | ||
| RESPONSE = POLICY.copy() | ||
|
|
@@ -590,24 +590,24 @@ def test_set_iam_policy_w_bound_client(self): | |
| policy = Policy('DEADBEEF', 17) | ||
| policy.owners.add(OWNER1) | ||
| policy.owners.add(OWNER2) | ||
| policy.writers.add(WRITER1) | ||
| policy.writers.add(WRITER2) | ||
| policy.readers.add(READER1) | ||
| policy.readers.add(READER2) | ||
| policy.editors.add(EDITOR1) | ||
| policy.editors.add(EDITOR2) | ||
| policy.viewers.add(VIEWER1) | ||
| policy.viewers.add(VIEWER2) | ||
|
|
||
| new_policy = subscription.set_iam_policy(policy) | ||
|
|
||
| self.assertEqual(new_policy.etag, 'ABACABAF') | ||
| self.assertEqual(new_policy.version, 18) | ||
| self.assertEqual(sorted(new_policy.owners), [OWNER1, OWNER2]) | ||
| self.assertEqual(sorted(new_policy.writers), [WRITER1, WRITER2]) | ||
| self.assertEqual(sorted(new_policy.readers), [READER1, READER2]) | ||
| self.assertEqual(sorted(new_policy.editors), [EDITOR1, EDITOR2]) | ||
| self.assertEqual(sorted(new_policy.viewers), [VIEWER1, VIEWER2]) | ||
|
|
||
| self.assertEqual(len(conn._requested), 1) | ||
| req = conn._requested[0] | ||
| self.assertEqual(req['method'], 'POST') | ||
| self.assertEqual(req['path'], '/%s' % PATH) | ||
| self.assertEqual(req['data'], POLICY) | ||
| self.assertEqual(req['data'], {'policy': POLICY}) | ||
|
|
||
| def test_set_iam_policy_w_alternate_client(self): | ||
| from gcloud.pubsub.iam import Policy | ||
|
|
@@ -631,23 +631,24 @@ def test_set_iam_policy_w_alternate_client(self): | |
| self.assertEqual(new_policy.etag, 'ACAB') | ||
| self.assertEqual(new_policy.version, None) | ||
| self.assertEqual(sorted(new_policy.owners), []) | ||
| self.assertEqual(sorted(new_policy.writers), []) | ||
| self.assertEqual(sorted(new_policy.readers), []) | ||
| self.assertEqual(sorted(new_policy.editors), []) | ||
| self.assertEqual(sorted(new_policy.viewers), []) | ||
|
|
||
| self.assertEqual(len(conn1._requested), 0) | ||
| self.assertEqual(len(conn2._requested), 1) | ||
| req = conn2._requested[0] | ||
| self.assertEqual(req['method'], 'POST') | ||
| self.assertEqual(req['path'], '/%s' % PATH) | ||
| self.assertEqual(req['data'], {}) | ||
| self.assertEqual(req['data'], {'policy': {}}) | ||
|
|
||
| def test_check_iam_permissions_w_bound_client(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| PROJECT = 'PROJECT' | ||
| TOPIC_NAME = 'topic_name' | ||
| SUB_NAME = 'sub_name' | ||
| PATH = 'projects/%s/subscriptions/%s:testIamPermissions' % ( | ||
| PROJECT, SUB_NAME) | ||
| ROLES = ['roles/reader', 'roles/writer', 'roles/owner'] | ||
| ROLES = [VIEWER_ROLE, EDITOR_ROLE, OWNER_ROLE] | ||
| REQUESTED = { | ||
| 'permissions': ROLES, | ||
| } | ||
|
|
@@ -669,12 +670,13 @@ def test_check_iam_permissions_w_bound_client(self): | |
| self.assertEqual(req['data'], REQUESTED) | ||
|
|
||
| def test_check_iam_permissions_w_alternate_client(self): | ||
| from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE | ||
| PROJECT = 'PROJECT' | ||
| TOPIC_NAME = 'topic_name' | ||
| SUB_NAME = 'sub_name' | ||
| PATH = 'projects/%s/subscriptions/%s:testIamPermissions' % ( | ||
| PROJECT, SUB_NAME) | ||
| ROLES = ['roles/reader', 'roles/writer', 'roles/owner'] | ||
| ROLES = [VIEWER_ROLE, EDITOR_ROLE, OWNER_ROLE] | ||
| REQUESTED = { | ||
| 'permissions': ROLES, | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.