Beispiel #1
0
  def test_remove_all_roles(self):
    """Tests parsing a -d allUsers or -d user:[email protected] request."""
    # Input specifies remove all roles from allUsers.
    (is_grant, bindings) = bstt(False, 'allUsers')
    self.assertEquals(len(bindings), 1)
    self.assertIn(bvle(members=['allUsers'], role=''), bindings)
    self.assertEquals((is_grant, bindings), bstt(False, 'allUsers:'))

    # Input specifies remove all roles from a user.
    (_, bindings) = bstt(False, 'user:[email protected]')
    self.assertEquals(len(bindings), 1)
Beispiel #2
0
    def test_remove_all_roles(self):
        """Tests parsing a -d allUsers or -d user:[email protected] request."""
        # Input specifies remove all roles from allUsers.
        (is_grant, bindings) = bstt(False, 'allUsers')
        self.assertEquals(len(bindings), 1)
        self.assertIn(bvle(members=['allUsers'], role=''), bindings)
        self.assertEquals((is_grant, bindings), bstt(False, 'allUsers:'))

        # Input specifies remove all roles from a user.
        (_, bindings) = bstt(False, 'user:[email protected]')
        self.assertEquals(len(bindings), 1)
Beispiel #3
0
 def test_valid_member(self):
     """Tests member parsing."""
     (_, bindings) = bstt(True, 'user:[email protected]:admin')
     self.assertEquals(len(bindings), 1)
     self.assertIn(
         bvle(members=['user:[email protected]'], role='roles/storage.admin'),
         bindings)
Beispiel #4
0
 def test_valid_multiple_roles(self):
   """Tests parsing of multiple roles bound to one user."""
   (_, bindings) = bstt(True, 'allUsers:a,b,c')
   self.assertEquals(len(bindings), 3)
   self.assertIn(bvle(members=['allUsers'], role='roles/storage.a'), bindings)
   self.assertIn(bvle(members=['allUsers'], role='roles/storage.b'), bindings)
   self.assertIn(bvle(members=['allUsers'], role='roles/storage.c'), bindings)
Beispiel #5
0
 def test_valid_public_member_single_role(self):
   """Tests parsing single role."""
   (_, bindings) = bstt(True, 'allUsers:admin')
   self.assertEquals(len(bindings), 1)
   self.assertIn(
       bvle(members=['allUsers'], role='roles/storage.admin'),
       bindings)
Beispiel #6
0
 def test_invalid_input(self):
     """Tests invalid input handling."""
     with self.assertRaises(CommandException):
         bstt(True, 'non_valid_public_member:role')
     with self.assertRaises(CommandException):
         bstt(True, 'non_valid_type:id:role')
     with self.assertRaises(CommandException):
         bstt(True, 'user:r')
     with self.assertRaises(CommandException):
         bstt(True, 'projectViewer:123424:admin')
Beispiel #7
0
 def test_invalid_input(self):
   """Tests invalid input handling."""
   with self.assertRaises(CommandException):
     bstt(True, 'non_valid_public_member:role')
   with self.assertRaises(CommandException):
     bstt(True, 'non_valid_type:id:role')
   with self.assertRaises(CommandException):
     bstt(True, 'user:r')
   with self.assertRaises(CommandException):
     bstt(True, 'projectViewer:123424:admin')
Beispiel #8
0
 def test_valid_member(self):
   """Tests member parsing."""
   (_, bindings) = bstt(True, 'user:[email protected]:admin')
   self.assertEquals(len(bindings), 1)
   self.assertIn(
       bvle(
           members=['user:[email protected]'],
           role='roles/storage.admin'),
       bindings)
Beispiel #9
0
 def test_valid_multiple_roles(self):
     """Tests parsing of multiple roles bound to one user."""
     (_, bindings) = bstt(True, 'allUsers:a,b,c')
     self.assertEquals(len(bindings), 3)
     self.assertIn(bvle(members=['allUsers'], role='roles/storage.a'),
                   bindings)
     self.assertIn(bvle(members=['allUsers'], role='roles/storage.b'),
                   bindings)
     self.assertIn(bvle(members=['allUsers'], role='roles/storage.c'),
                   bindings)
Beispiel #10
0
 def test_grant_no_role_error(self):
     """Tests that an error is raised when no role is specified for a grant."""
     with self.assertRaises(CommandException):
         bstt(True, 'allUsers')
     with self.assertRaises(CommandException):
         bstt(True, 'user:[email protected]')
     with self.assertRaises(CommandException):
         bstt(True, 'user:[email protected]:')
Beispiel #11
0
 def test_grant_no_role_error(self):
   """Tests that an error is raised when no role is specified for a grant."""
   with self.assertRaises(CommandException):
     bstt(True, 'allUsers')
   with self.assertRaises(CommandException):
     bstt(True, 'user:[email protected]')
   with self.assertRaises(CommandException):
     bstt(True, 'user:[email protected]:')
Beispiel #12
0
 def test_invalid_n_args(self):
     """Tests invalid input due to too many colons."""
     with self.assertRaises(CommandException):
         bstt(True, 'allUsers:some_id:some_role')
     with self.assertRaises(CommandException):
         bstt(True, 'user:[email protected]:r:nonsense')
Beispiel #13
0
 def test_duplicate_roles(self):
     """Tests that duplicate roles are ignored."""
     (_, bindings) = bstt(True, 'allUsers:a,a')
     self.assertEquals(len(bindings), 1)
     self.assertIn(bvle(members=['allUsers'], role='roles/storage.a'),
                   bindings)
Beispiel #14
0
 def test_valid_public_member_single_role(self):
     """Tests parsing single role."""
     (_, bindings) = bstt(True, 'allUsers:admin')
     self.assertEquals(len(bindings), 1)
     self.assertIn(bvle(members=['allUsers'], role='roles/storage.admin'),
                   bindings)
Beispiel #15
0
 def test_invalid_n_args(self):
   """Tests invalid input due to too many colons."""
   with self.assertRaises(CommandException):
     bstt(True, 'allUsers:some_id:some_role')
   with self.assertRaises(CommandException):
     bstt(True, 'user:[email protected]:r:nonsense')
Beispiel #16
0
 def test_duplicate_roles(self):
   """Tests that duplicate roles are ignored."""
   (_, bindings) = bstt(True, 'allUsers:a,a')
   self.assertEquals(len(bindings), 1)
   self.assertIn(bvle(members=['allUsers'], role='roles/storage.a'), bindings)