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)
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)
def test_iadd_other(self): opt1 = Options(a=1) opt2 = None try: opt1 += opt2 self.assertTrue(0, msg='ValueError expected') except ValueError: pass
def log(document): request = Options(document.request) log.info( 'call: %s.%s() sn=%s data=%s', request.classname, request.method, document.sn, document.data)
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)
def test_iter(self): options = Options(a=1, b=2) _list = list(iter(options)) self.assertEqual(_list, ['a', 'b'])
def test_getattr(self): options = Options(a=1) self.assertEqual(options.a, 1)
def auth(document): return Options( uuid=document.routing[-1], secret=document.secret, pam=document.pam,)
def pam(self): if self.options.user: return Options(user=self.options.user, password=self.options.password) else: return None
def test_stub(self): builder = Builder() builder('Test', 'http://', 'queue66', Options())
def test_unicode(self): options = Options(a=1, b=2) self.assertEqual(str(options), unicode(options.__dict__))
def test_str(self): options = Options(a=1, b=2) self.assertEqual(str(options), str(options.__dict__))
def test_repr(self): options = Options(a=1, b=2) self.assertEqual(repr(options), repr(options.__dict__))
def test_get_item(self): options = Options(a=1) self.assertEqual(options['a'], 1)
def test_len(self): options = Options(a=1, b=2) self.assertEqual(len(options), 2)
def test_set_item(self): options = Options() options['a'] = 1 self.assertEqual(options['a'], 1)
def test_iadd_dict(self): opt1 = Options(a=1) opt2 = dict(b=2) opt1 += opt2 self.assertEqual(opt1.__dict__, {'a': 1, 'b': 2})