Beispiel #1
0
 def test_modify_zero_length(self):
     """Ensure zero-length modlists are ignored"""
     mock_sock = MockLDAPSocket()
     mock_sock.add_root_dse()
     ldap = LDAP(mock_sock)
     mock_sock.clear_sent()
     ldap.modify('', [])
     self.assertEqual(mock_sock.num_sent(), 0)
Beispiel #2
0
    def test_modify_bad_response(self):
        """Ensure modify complains when receiving a bad response from the server"""
        mock_sock = MockLDAPSocket()
        mock_sock.add_root_dse()
        ldap = LDAP(mock_sock)

        mock_sock.add_ldap_result(rfc4511.ModifyResponse, 'modifyResponse', result_code=protoutils.RESULT_compareFalse)
        with self.assertRaises(exceptions.LDAPError):
            ldap.modify('', [
                Mod(Mod.ADD, 'foo', ['bar', 'baz']),
            ])
Beispiel #3
0
    def test_ignore_empty_list(self):
        """Ensure emtpy value lists are ignored"""

        mock_sock = MockLDAPSocket()
        mock_sock.add_root_dse()
        ldap = LDAP(mock_sock, ignore_empty_list=True)

        mock_sock.clear_sent()

        # this should succeed without sending a request to the server or expecting a response
        ldap.modify('o=foo', [Mod(Mod.REPLACE, 'foo', [])])
        self.assertEqual(mock_sock.num_sent(), 0)
Beispiel #4
0
    def test_modify(self):
        """Ensure protocol-level modlist is contructed without error"""
        mock_sock = MockLDAPSocket()
        mock_sock.add_root_dse()
        ldap = LDAP(mock_sock)

        mock_sock.add_ldap_result(rfc4511.ModifyResponse, 'modifyResponse')
        ldap.modify('', [
            Mod(Mod.ADD, 'foo', ['bar', 'baz']),
            Mod(Mod.REPLACE, 'foo', []),
            Mod(Mod.REPLACE, 'foo', ['foo']),
            Mod(Mod.DELETE, 'foo', []),
            Mod(Mod.DELETE, 'foo', ['foo'])
        ])
Beispiel #5
0
    def test_error_empty_list(self):
        """Ensure the error_empty_list option is respected with all invocations"""

        mock_sock = MockLDAPSocket()
        mock_sock.add_root_dse()
        ldap = LDAP(mock_sock, error_empty_list=True)

        with self.assertRaises(exceptions.LDAPError):
            ldap.modify('o=foo', [Mod(Mod.REPLACE, 'foo', [])])

        with self.assertRaises(exceptions.LDAPError):
            ldap.replace_attrs('o=foo', {'foo': []})

        with self.assertRaises(exceptions.LDAPError):
            ldap.delete_attrs('o=foo', {'foo': []}, current={'foo': ['bar']})

        with self.assertRaises(exceptions.LDAPError):
            ldap.obj('o=foo').modify([Mod(Mod.REPLACE, 'foo', [])])

        with self.assertRaises(exceptions.LDAPError):
            ldap.obj('o=foo').replace_attrs({'foo': []})

        with self.assertRaises(exceptions.LDAPError):
            ldap.obj('o=foo', attrs_dict={'foo': ['bar']}).delete_attrs({'foo': []})