예제 #1
0
    def test_xivo_ldap_init(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()

        _XivoLDAP(self.config['uri'])

        ldap_initialize.assert_called_once_with(self.config['uri'])
        ldapobj.set_option.assert_any_call(ldap.OPT_REFERRALS, 0)
        ldapobj.set_option.assert_any_call(ldap.OPT_NETWORK_TIMEOUT, 2)
        ldapobj.set_option.assert_any_call(ldap.OPT_TIMEOUT, 2)
예제 #2
0
    def test_that_perform_search(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        xivo_ldap = _XivoLDAP(self.config)
        ldapobj.search_ext_s.return_value = ['result1']

        result = xivo_ldap.perform_search('base', 'scope')
        self.assertEqual(result, 'result1')
예제 #3
0
    def test_that_perform_bind_return_false_when_no_wrong_credential(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()

        xivo_ldap = _XivoLDAP(self.config)
        ldapobj.simple_bind_s.side_effect = ldap.INVALID_CREDENTIALS()
        result = xivo_ldap.perform_bind('username', 'password')
        self.assertEqual(result, False)
예제 #4
0
    def test_that_perform_search_return_none_when_no_result(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        xivo_ldap = _XivoLDAP(self.config)
        ldapobj.search_ext_s.return_value = []

        result_dn, result_attr = xivo_ldap.perform_search('base', 'scope')
        self.assertEqual(result_dn, None)
        self.assertEqual(result_attr, None)
예제 #5
0
    def test_that_perform_search_return_none_when_multiple_result(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        xivo_ldap = _XivoLDAP(self.config)
        ldapobj.search_ext_s.side_effect = ldap.SIZELIMIT_EXCEEDED()

        result_dn, result_attr = xivo_ldap.perform_search('base', 'scope')
        self.assertEqual(result_dn, None)
        self.assertEqual(result_attr, None)
예제 #6
0
    def test_that_perform_bind(self):
        xivo_ldap = _XivoLDAP(self.config)

        result = xivo_ldap.perform_bind('username', 'password')
        self.assertEqual(result, True)