Exemple #1
0
def test_add_and_delete_referrals(cfg, ipaddr):
    """ Test add and delete an LDAP referral with ManageDdsIT control. """
    refdn = bonsai.LDAPDN("o=test-ref,ou=nerdherd,dc=bonsai,dc=test")
    ref = "ldap://test.host/cn=nobody"
    cli = LDAPClient("ldap://%s" % ipaddr)
    cli.set_credentials("SIMPLE",
                        user=cfg["SIMPLEAUTH"]["user"],
                        password=cfg["SIMPLEAUTH"]["password"])
    cli.managedsait = True
    with cli.connect() as conn:
        entry = bonsai.LDAPEntry(refdn, conn)
        entry["objectClass"] = ["referral", "extensibleObject"]
        entry["o"] = "test-ref"
        entry["ref"] = ref
        conn.add(entry)
        res = conn.search(refdn, 0, attrlist=["ref"])[0]
        assert entry.dn == res.dn
        assert entry["ref"] == res["ref"]
    cli.managedsait = False
    with cli.connect() as conn:
        with pytest.raises(bonsai.LDAPError):
            conn.delete(entry.dn)
    cli.managedsait = True
    with cli.connect() as conn:
        conn.delete(entry.dn)
        res = conn.search(refdn, 0, attrlist=["ref"])
        assert res == []
def test_add_and_delete_referrals(cfg, ipaddr):
    """ Test add and delete an LDAP referral with ManageDdsIT control. """
    refdn = bonsai.LDAPDN("o=test-ref,ou=nerdherd,dc=bonsai,dc=test")
    ref = "ldap://test.host/cn=nobody"
    cli = LDAPClient("ldap://%s" % ipaddr)
    cli.set_credentials(
        "SIMPLE", user=cfg["SIMPLEAUTH"]["user"], password=cfg["SIMPLEAUTH"]["password"]
    )
    cli.managedsait = True
    with cli.connect() as conn:
        entry = bonsai.LDAPEntry(refdn, conn)
        entry["objectClass"] = ["referral", "extensibleObject"]
        entry["o"] = "test-ref"
        entry["ref"] = ref
        conn.add(entry)
        res = conn.search(refdn, 0, attrlist=["ref"])[0]
        assert entry.dn == res.dn
        assert entry["ref"] == res["ref"]
    cli.managedsait = False
    with cli.connect() as conn:
        with pytest.raises(bonsai.LDAPError):
            conn.delete(entry.dn)
    cli.managedsait = True
    with cli.connect() as conn:
        conn.delete(entry.dn)
        res = conn.search(refdn, 0, attrlist=["ref"])
        assert res == []
Exemple #3
0
 def test_managedsait(self):
     """ Test managedsait property. """
     client = LDAPClient(self.url)
     self.assertRaises(TypeError, lambda: client.set_managedsait("B"))
     self.assertFalse(client.managedsait)
     client.managedsait = True
     self.assertTrue(client.managedsait)
Exemple #4
0
def test_modify_referrals(client):
    """ Test modifying an LDAP referral with ManageDdsIT control. """
    refdn = bonsai.LDAPDN("o=invalid-ref,ou=nerdherd,dc=bonsai,dc=test")
    newref = "ldap://invalid.host/cn=nobody"
    cli = LDAPClient(client.url)
    cli.set_credentials(client.mechanism, **client.credentials)
    cli.managedsait = True
    with cli.connect() as conn:
        entry = LDAPEntry(refdn, conn)
        entry.change_attribute("ref", LDAPModOp.ADD, newref)
        entry.modify()
        res = conn.search(refdn, 0, attrlist=["ref"])[0]
        assert len(res["ref"]) == 3
        assert newref in res["ref"]
        entry.change_attribute("ref", LDAPModOp.DELETE, newref)
        entry.modify()
Exemple #5
0
 def test_modify_referrals(self):
     """ Test modifying an LDAP referral with ManageDdsIT control. """
     refdn = bonsai.LDAPDN("o=invalid-ref,ou=nerdherd,dc=bonsai,dc=test")
     newref = "ldap://invalid.host/cn=nobody"
     cli = LDAPClient(self.client.url)
     cli.set_credentials(*self.creds)
     cli.managedsait = True
     with cli.connect() as conn:
         entry = LDAPEntry(refdn, conn)
         entry.change_attribute("ref", LDAPModOp.ADD, newref)
         entry.modify()
         res = conn.search(refdn, 0, attrlist=['ref'])[0]
         self.assertEqual(len(res['ref']), 3)
         self.assertIn(newref, res['ref'])
         entry.change_attribute("ref", LDAPModOp.DELETE, newref)
         entry.modify()
Exemple #6
0
def test_modify_referrals(client):
    """ Test modifying an LDAP referral with ManageDdsIT control. """
    refdn = bonsai.LDAPDN("o=invalid-ref,ou=nerdherd,dc=bonsai,dc=test")
    newref = "ldap://invalid.host/cn=nobody"
    cli = LDAPClient(client.url)
    cli.set_credentials(client.mechanism, **client.credentials)
    cli.managedsait = True
    with cli.connect() as conn:
        entry = LDAPEntry(refdn, conn)
        entry.change_attribute("ref", LDAPModOp.ADD, newref)
        entry.modify()
        res = conn.search(refdn, 0, attrlist=["ref"])[0]
        assert len(res["ref"]) == 3
        assert newref in res["ref"]
        entry.change_attribute("ref", LDAPModOp.DELETE, newref)
        entry.modify()