Example #1
0
 def test_equality_bindings_extra_roles(self):
     """Tests bindings equality when duplicate roles are added."""
     bindings = [bvle(role='x', members=['x', 'y'])]
     bindings2 = bindings * 2
     bindings3 = [
         bvle(role='x', members=['y']),
         bvle(role='x', members=['x']),
     ]
     self.assertTrue(IsEqualBindings(bindings, bindings2))
     self.assertTrue(IsEqualBindings(bindings, bindings3))
Example #2
0
    def _PatchIamHelperInternal(self,
                                storage_url,
                                bindings_tuples,
                                thread_state=None):

        policy = self.GetIamHelper(storage_url, thread_state=thread_state)
        (etag, bindings) = (policy.etag, policy.bindings)

        # Create a backup which is untainted by any references to the original
        # bindings.
        orig_bindings = list(bindings)

        for (is_grant, diff) in bindings_tuples:
            bindings = PatchBindings(bindings, BindingsTuple(is_grant, diff))

        if IsEqualBindings(bindings, orig_bindings):
            self.logger.info('No changes made to %s', storage_url)
            return

        policy = apitools_messages.Policy(bindings=bindings, etag=etag)

        # We explicitly wish for etag mismatches to raise an error and allow this
        # function to error out, so we are bypassing the exception handling offered
        # by IamCommand.SetIamHelper in lieu of our own handling (@Retry).
        self._SetIamHelperInternal(storage_url,
                                   policy,
                                   thread_state=thread_state)
Example #3
0
 def assertEqualsBindingsString(self, a, b):
     """Asserts two serialized binding lists are equal."""
     expected = [
         bvle(members=binding_dict['members'], role=binding_dict['role'])
         for binding_dict in json.loads(a)
     ]
     result = [
         bvle(members=binding_dict['members'], role=binding_dict['role'])
         for binding_dict in json.loads(b)
     ]
     self.assertTrue(IsEqualBindings(expected, result))
Example #4
0
    def test_patch_bindings_public_member_overwrite(self):
        """Tests public member vs. public member interaction."""
        base = [
            bvle(role='a', members=['allUsers']),
        ]
        diff = [
            bvle(role='a', members=['allAuthenticatedUsers']),
        ]

        res = PatchBindings(base, BindingsTuple(True, diff))
        self.assertTrue(IsEqualBindings(res, base + diff))
Example #5
0
 def test_patch_bindings_grant(self):
     """Tests patching a grant binding."""
     base = [
         bvle(role='a', members=['user:[email protected]']),
         bvle(role='b', members=['user:[email protected]']),
         bvle(role='c', members=['user:[email protected]']),
     ]
     diff = [
         bvle(role='d', members=['user:[email protected]']),
     ]
     expected = base + diff
     res = PatchBindings(base, BindingsTuple(True, diff))
     self.assertTrue(IsEqualBindings(res, expected))
Example #6
0
 def test_patch_bindings_multiple_users(self):
     """Tests expected behavior when multiple users exist."""
     expected = [
         bvle(members=['user:[email protected]'], role='b'),
     ]
     base = [
         bvle(members=['user:[email protected]'], role='a'),
         bvle(members=['user:[email protected]', 'user:[email protected]'], role='b'),
         bvle(members=['user:[email protected]'], role='c'),
     ]
     diff = [
         bvle(members=['user:[email protected]'], role='a'),
         bvle(members=['user:[email protected]'], role='b'),
         bvle(members=['user:[email protected]'], role='c'),
     ]
     res = PatchBindings(base, BindingsTuple(False, diff))
     self.assertTrue(IsEqualBindings(res, expected))
Example #7
0
    def test_patch_bindings_remove(self):
        """Tests patching a remove binding."""
        base = [
            bvle(members=['user:[email protected]'], role='a'),
            bvle(members=['user:[email protected]'], role='b'),
            bvle(members=['user:[email protected]'], role='c'),
        ]
        diff = [
            bvle(members=['user:[email protected]'], role='a'),
        ]
        expected = [
            bvle(members=['user:[email protected]'], role='b'),
            bvle(members=['user:[email protected]'], role='c'),
        ]

        res = PatchBindings(base, BindingsTuple(False, diff))
        self.assertTrue(IsEqualBindings(res, expected))
Example #8
0
    def test_patch_bindings_grant_all_users(self):
        """Tests a public member grant."""
        base = [
            bvle(role='a', members=['user:[email protected]']),
            bvle(role='b', members=['user:[email protected]']),
            bvle(role='c', members=['user:[email protected]']),
        ]
        diff = [
            bvle(role='a', members=['allUsers']),
        ]
        expected = [
            bvle(role='a', members=['allUsers', 'user:[email protected]']),
            bvle(role='b', members=['user:[email protected]']),
            bvle(role='c', members=['user:[email protected]']),
        ]

        res = PatchBindings(base, BindingsTuple(True, diff))
        self.assertTrue(IsEqualBindings(res, expected))
Example #9
0
 def test_equality_bindings_literal(self):
     """Tests an easy case of identical bindings."""
     bindings = [bvle(role='x', members=['y'])]
     self.assertTrue(IsEqualBindings([], []))
     self.assertTrue(IsEqualBindings(bindings, bindings))