示例#1
0
def test_wrong_search_param(ipaddr):
    """ Test passing wrong parameters for search method. """
    with pytest.raises(ClosedConnection):
        cli = LDAPClient("ldap://%s" % ipaddr)
        LDAPConnection(cli).search()
    with pytest.raises(ValueError):
        cli = LDAPClient("ldap://%s" % ipaddr)
        LDAPConnection(cli).open().search()
    with pytest.raises(TypeError):
        cli = LDAPClient("ldap://%s" % ipaddr)
        LDAPConnection(cli).open().search("", 0, 3)
示例#2
0
def test_wrong_delete_param(conn, ipaddr):
    """ Test passing wrong parameter for delete method. """
    with pytest.raises(ClosedConnection):
        cli = LDAPClient("ldap://%s" % ipaddr)
        LDAPConnection(cli).delete("cn=dummy")
    with pytest.raises(TypeError):
        conn.delete(0)
示例#3
0
def test_wrong_add_param(conn, ipaddr):
    """ Test passing wrong parameter for add method. """
    with pytest.raises(ClosedConnection):
        cli = LDAPClient("ldap://%s" % ipaddr)
        LDAPConnection(cli).add(bonsai.LDAPEntry("cn=dummy"))
    with pytest.raises(TypeError):
        conn.add("wrong")
示例#4
0
 def setUp(self):
     """ Set LDAP URL and open connection. """
     curdir = os.path.abspath(os.path.dirname(__file__))
     self.cfg = configparser.ConfigParser()
     self.cfg.read(os.path.join(curdir, 'test.ini'))
     self.url = "ldap://%s:%s/%s?%s?%s" % (self.cfg["SERVER"]["hostip"], \
                                     self.cfg["SERVER"]["port"], \
                                     self.cfg["SERVER"]["basedn"], \
                                     self.cfg["SERVER"]["search_attr"], \
                                     self.cfg["SERVER"]["search_scope"])
     self.basedn = self.cfg["SERVER"]["basedn"]
     client = LDAPClient(self.url)
     client.set_credentials("SIMPLE", (self.cfg["SIMPLEAUTH"]["user"],
                                       self.cfg["SIMPLEAUTH"]["password"]))
     self.conn = client.connect()
     self.async_conn = LDAPConnection(client, True)
示例#5
0
def test_wrong_conn_param():
    """ Test passing wrong parameters for LDAPConnection. """
    with pytest.raises(TypeError):
        _ = LDAPConnection("wrong")
    with pytest.raises(TypeError):
        _ = LDAPConnection(1)
示例#6
0
 def close_conn():
     cli = LDAPClient("ldap://%s" % self.ipaddr)
     LDAPConnection(cli).delete("cn=dummy")
示例#7
0
 def close_conn():
     cli = LDAPClient("ldap://%s" % self.ipaddr)
     LDAPConnection(cli).add(bonsai.LDAPEntry("cn=dummy"))
示例#8
0
 def wrong():
     cli = LDAPClient("ldap://%s" % self.ipaddr)
     LDAPConnection(cli).open().search("", 0, 3)
示例#9
0
 def missing_scope():
     cli = LDAPClient("ldap://%s" % self.ipaddr)
     LDAPConnection(cli).open().search()
示例#10
0
 def close_conn():
     cli = LDAPClient("ldap://%s" % self.ipaddr)
     LDAPConnection(cli).search()
示例#11
0
 def test_wrong_conn_param(self):
     """ Test passing wrong parameters for LDAPConnection. """
     self.assertRaises(TypeError, lambda: LDAPConnection("wrong"))
     self.assertRaises(TypeError, lambda: LDAPConnection(LDAPClient(), 1))