Example #1
0
 def pam(self, required, passed):
     """
     Perform PAM authentication.
     :param required: Method specific auth specification.
     :type required: Options
     :param passed: The credentials passed.
     :type passed: Options
     :raise UserRequired: On user required and not passed.
     :raise PasswordRequired: On password required and not passed.
     :raise UserNotAuthorized: On user not authorized.
     :raise NotAuthenticated: On PAM auth failed.
     """
     if passed.pam:
         passed = Options(passed.pam)
     else:
         passed = Options()
     if not passed.user:
         raise UserRequired(self.method)
     if not passed.password:
         raise PasswordRequired(self.method)
     if passed.user != required.user:
         raise UserNotAuthorized(self.method, required.user, passed.user)
     valid = pam_authenticate(passed.user, passed.password, required.service)
     if not valid:
         raise NotAuthenticated(self.method, passed.user)
Example #2
0
 def test_init(self):
     # dict
     d = {'A': 1}
     options = Options(d)
     self.assertEqual(d, options.__dict__)
     # options
     d = {'A': 1}
     options = Options(Options(d))
     self.assertEqual(d, options.__dict__)
     # ValueError
     self.assertRaises(ValueError, Options, 1)
Example #3
0
 def test_iadd_other(self):
     opt1 = Options(a=1)
     opt2 = None
     try:
         opt1 += opt2
         self.assertTrue(0, msg='ValueError expected')
     except ValueError:
         pass
Example #4
0
 def log(document):
     request = Options(document.request)
     log.info(
         'call: %s.%s() sn=%s data=%s',
         request.classname,
         request.method,
         document.sn,
         document.data)
Example #5
0
 def __init__(self, url, address, **options):
     """
     :param url: The agent URL.
     :type url: str
     :param address: The AMQP address to the agent.
     :type address: str
     :param options: keyword options.  See documentation.
     :type options: dict
     """
     self.__url = url
     self.__address = address
     self.__options = Options(options)
Example #6
0
 def test_iter(self):
     options = Options(a=1, b=2)
     _list = list(iter(options))
     self.assertEqual(_list, ['a', 'b'])
Example #7
0
 def test_getattr(self):
     options = Options(a=1)
     self.assertEqual(options.a, 1)
Example #8
0
 def auth(document):
     return Options(
         uuid=document.routing[-1],
         secret=document.secret,
         pam=document.pam,)
Example #9
0
 def pam(self):
     if self.options.user:
         return Options(user=self.options.user,
                        password=self.options.password)
     else:
         return None
Example #10
0
 def test_stub(self):
     builder = Builder()
     builder('Test', 'http://', 'queue66', Options())
Example #11
0
 def test_unicode(self):
     options = Options(a=1, b=2)
     self.assertEqual(str(options), unicode(options.__dict__))
Example #12
0
 def test_str(self):
     options = Options(a=1, b=2)
     self.assertEqual(str(options), str(options.__dict__))
Example #13
0
 def test_repr(self):
     options = Options(a=1, b=2)
     self.assertEqual(repr(options), repr(options.__dict__))
Example #14
0
 def test_get_item(self):
     options = Options(a=1)
     self.assertEqual(options['a'], 1)
Example #15
0
 def test_len(self):
     options = Options(a=1, b=2)
     self.assertEqual(len(options), 2)
Example #16
0
 def test_set_item(self):
     options = Options()
     options['a'] = 1
     self.assertEqual(options['a'], 1)
Example #17
0
 def test_iadd_dict(self):
     opt1 = Options(a=1)
     opt2 = dict(b=2)
     opt1 += opt2
     self.assertEqual(opt1.__dict__, {'a': 1, 'b': 2})