Exemple #1
0
    def test_that_perform_search(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()
        ldapobj.search_ext_s.return_value = ['result1']

        result = wazo_ldap.perform_search('base', 'scope')
        self.assertEqual(result, 'result1')
Exemple #2
0
    def test_that_perform_bind_return_false_when_no_wrong_credential(
            self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()

        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()
        ldapobj.simple_bind_s.side_effect = ldap.INVALID_CREDENTIALS()
        result = wazo_ldap.perform_bind('username', 'password')
        self.assertEqual(result, False)
Exemple #3
0
    def test_that_perform_search_return_none_when_no_result(
            self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()
        ldapobj.search_ext_s.return_value = []

        result_dn, result_attr = wazo_ldap.perform_search('base', 'scope')
        self.assertEqual(result_dn, None)
        self.assertEqual(result_attr, None)
Exemple #4
0
    def test_that_perform_search_return_none_when_multiple_result(
            self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()
        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()
        ldapobj.search_ext_s.side_effect = ldap.SIZELIMIT_EXCEEDED()

        result_dn, result_attr = wazo_ldap.perform_search('base', 'scope')
        self.assertEqual(result_dn, None)
        self.assertEqual(result_attr, None)
Exemple #5
0
    def test_wazo_ldap_init(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()

        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()

        ldap_initialize.assert_called_once_with(wazo_ldap.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)
        ldapobj.set_option.assert_any_call(ldap.OPT_PROTOCOL_VERSION,
                                           ldap.VERSION3)
Exemple #6
0
    def test_wazo_ldap_init_tls(self, ldap_initialize):
        ldapobj = ldap_initialize.return_value = Mock()

        with patch.dict(self.config, {'protocol_security': 'tls'}):
            wazo_ldap = _WazoLDAP(self.config)
            wazo_ldap.connect()

        ldap_initialize.assert_called_once_with(wazo_ldap.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)
        ldapobj.set_option.assert_any_call(ldap.OPT_PROTOCOL_VERSION,
                                           ldap.VERSION3)
        ldapobj.set_option.assert_any_call(ldap.OPT_X_TLS_NEWCTX, 0)
        ldapobj.start_tls_s.assert_called_once()
Exemple #7
0
    def test_that_perform_bind(self):
        wazo_ldap = _WazoLDAP(self.config)
        wazo_ldap.connect()

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