Ejemplo n.º 1
0
 def test_hmac_expire(self):
     """ hmac will expire after a time """
     access = IMutableAccessBackend(signing_key='abc', token_expiration=-10)
     user = '******'
     token = access.get_signup_token(user)
     self.assertIsNone(access.validate_signup_token(token))
Ejemplo n.º 2
0
 def test_hmac_invalid(self):
     """ hmac will be invalid if mutated """
     access = IMutableAccessBackend(signing_key='abc')
     user = '******'
     token = access.get_signup_token(user)
     self.assertIsNone(access.validate_signup_token(token + 'a'))
Ejemplo n.º 3
0
 def test_hmac_validate(self):
     """ hmac will validate """
     access = IMutableAccessBackend(signing_key='abc')
     user = '******'
     token = access.get_signup_token(user)
     self.assertEqual(user, access.validate_signup_token(token))
Ejemplo n.º 4
0
 def test_no_need_admin(self):
     """ need_admin is False if 1+ admins """
     access = IMutableAccessBackend(None)
     with patch.object(access, 'user_data') as user_data:
         user_data.return_value = [{'admin': False}, {'admin': True}]
         self.assertFalse(access.need_admin())
Ejemplo n.º 5
0
 def test_abstract_methods(self):
     """ Abstract methods raise NotImplementedError """
     access = IMutableAccessBackend(None, pwd_context=get_pwd_context())
     with self.assertRaises(NotImplementedError):
         access.verify_user('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.groups()
     with self.assertRaises(NotImplementedError):
         access.group_members('a')
     with self.assertRaises(NotImplementedError):
         access.is_admin('a')
     with self.assertRaises(NotImplementedError):
         access.group_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_package_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.group_package_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_data()
     with self.assertRaises(NotImplementedError):
         access.allow_register()
     with self.assertRaises(NotImplementedError):
         access.set_allow_register(True)
     with self.assertRaises(NotImplementedError):
         access.register('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.pending_users()
     with self.assertRaises(NotImplementedError):
         access.approve_user('a')
     with self.assertRaises(NotImplementedError):
         access.edit_user_password('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.delete_user('a')
     with self.assertRaises(NotImplementedError):
         access.set_user_admin('a', True)
     with self.assertRaises(NotImplementedError):
         access.edit_user_group('a', 'a', 'add')
     with self.assertRaises(NotImplementedError):
         access.create_group('a')
     with self.assertRaises(NotImplementedError):
         access.delete_group('a')
     with self.assertRaises(NotImplementedError):
         access.edit_user_permission('a', 'b', 'c', True)
     with self.assertRaises(NotImplementedError):
         access.edit_group_permission('a', 'b', 'c', True)
 def test_no_need_admin(self):
     """ need_admin is False if 1+ admins """
     access = IMutableAccessBackend(None)
     with patch.object(access, 'user_data') as user_data:
         user_data.return_value = [{'admin': False}, {'admin': True}]
         self.assertFalse(access.need_admin())
 def test_abstract_methods(self):
     """ Abstract methods raise NotImplementedError """
     access = IMutableAccessBackend(None)
     with self.assertRaises(NotImplementedError):
         access.verify_user('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.groups()
     with self.assertRaises(NotImplementedError):
         access.group_members('a')
     with self.assertRaises(NotImplementedError):
         access.is_admin('a')
     with self.assertRaises(NotImplementedError):
         access.group_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_package_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.group_package_permissions('a')
     with self.assertRaises(NotImplementedError):
         access.user_data()
     with self.assertRaises(NotImplementedError):
         access.allow_register()
     with self.assertRaises(NotImplementedError):
         access.set_allow_register(True)
     with self.assertRaises(NotImplementedError):
         access.register('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.pending_users()
     with self.assertRaises(NotImplementedError):
         access.approve_user('a')
     with self.assertRaises(NotImplementedError):
         access.edit_user_password('a', 'b')
     with self.assertRaises(NotImplementedError):
         access.delete_user('a')
     with self.assertRaises(NotImplementedError):
         access.set_user_admin('a', True)
     with self.assertRaises(NotImplementedError):
         access.edit_user_group('a', 'a', 'add')
     with self.assertRaises(NotImplementedError):
         access.create_group('a')
     with self.assertRaises(NotImplementedError):
         access.delete_group('a')
     with self.assertRaises(NotImplementedError):
         access.edit_user_permission('a', 'b', 'c', True)
     with self.assertRaises(NotImplementedError):
         access.edit_group_permission('a', 'b', 'c', True)