def test_setexpiry(self): twodays = time.time() + (2 * 24 * 60 * 60) for user in self.users: (result, out, err) = self.runsubcmd( "user", "setexpiry", user["name"], "--days=2", "-H", "ldap://{0!s}".format(os.environ["DC_SERVER"]), "-U{0!s}%{1!s}".format(os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"]), ) self.assertCmdSuccess(result, "Can we run setexpiry with names") self.assertIn("Expiry for user '{0!s}' set to 2 days.".format(user["name"]), out) for user in self.users: found = self._find_user(user["name"]) expires = nttime2unix(int("{0!s}".format(found.get("accountExpires")))) self.assertWithin(expires, twodays, 5, "Ensure account expires is within 5 seconds of the expected time") # TODO: renable this after the filter case is sorted out if "filters are broken, bail now": return # now run the expiration based on a filter fourdays = time.time() + (4 * 24 * 60 * 60) (result, out, err) = self.runsubcmd( "user", "setexpiry", "--filter", "(&(objectClass=user)(company=comp2))", "--days=4", "-H", "ldap://{0!s}".format(os.environ["DC_SERVER"]), "-U{0!s}%{1!s}".format(os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"]), ) self.assertCmdSuccess(result, "Can we run setexpiry with a filter") for user in self.users: found = self._find_user(user["name"]) if ("{0!s}".format(found.get("company"))) == "comp2": expires = nttime2unix(int("{0!s}".format(found.get("accountExpires")))) self.assertWithin( expires, fourdays, 5, "Ensure account expires is within 5 seconds of the expected time" ) else: expires = nttime2unix(int("{0!s}".format(found.get("accountExpires")))) self.assertWithin( expires, twodays, 5, "Ensure account expires is within 5 seconds of the expected time" )
def test_setexpiry(self): twodays = time.time() + (2 * 24 * 60 * 60) for user in self.users: (result, out, err) = self.runsubcmd( "user", "setexpiry", user["name"], "--days=2", "-H", "ldap://%s" % os.environ["DC_SERVER"], "-U%s%%%s" % (os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"])) self.assertCmdSuccess(result, out, err, "Can we run setexpiry with names") self.assertIn("Expiry for user '%s' set to 2 days." % user["name"], out) for user in self.users: found = self._find_user(user["name"]) expires = nttime2unix(int("%s" % found.get("accountExpires"))) self.assertWithin( expires, twodays, 5, "Ensure account expires is within 5 seconds of the expected time" ) # TODO: renable this after the filter case is sorted out if "filters are broken, bail now": return # now run the expiration based on a filter fourdays = time.time() + (4 * 24 * 60 * 60) (result, out, err) = self.runsubcmd( "user", "setexpiry", "--filter", "(&(objectClass=user)(company=comp2))", "--days=4", "-H", "ldap://%s" % os.environ["DC_SERVER"], "-U%s%%%s" % (os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"])) self.assertCmdSuccess(result, out, err, "Can we run setexpiry with a filter") for user in self.users: found = self._find_user(user["name"]) if ("%s" % found.get("company")) == "comp2": expires = nttime2unix(int("%s" % found.get("accountExpires"))) self.assertWithin( expires, fourdays, 5, "Ensure account expires is within 5 seconds of the expected time" ) else: expires = nttime2unix(int("%s" % found.get("accountExpires"))) self.assertWithin( expires, twodays, 5, "Ensure account expires is within 5 seconds of the expected time" )
def get_utdv(samdb, dn): """This finds the uptodateness vector in the database.""" cursors = [] config_dn = samdb.get_config_basedn() for c in dsdb._dsdb_load_udv_v2(samdb, dn): inv_id = str(c.source_dsa_invocation_id) res = samdb.search(base=config_dn, expression=("(&(invocationId=%s)" "(objectClass=nTDSDSA))" % inv_id), attrs=["distinguishedName", "invocationId"]) settings_dn = str(res[0]["distinguishedName"][0]) prefix, dsa_dn = settings_dn.split(',', 1) if prefix != 'CN=NTDS Settings': raise CommandError("Expected NTDS Settings DN, got %s" % settings_dn) cursors.append((dsa_dn, inv_id, int(c.highest_usn), nttime2unix(c.last_sync_success))) return cursors
def get_utdv(self, samdb, dn): """This finds the uptodateness vector in the database.""" cursors = [] config_dn = samdb.get_config_basedn() for c in dsdb._dsdb_load_udv_v2(samdb, dn): inv_id = str(c.source_dsa_invocation_id) res = samdb.search(base=config_dn, expression=("(&(invocationId=%s)" "(objectClass=nTDSDSA))" % inv_id), attrs=["distinguishedName", "invocationId"]) settings_dn = res[0]["distinguishedName"][0] prefix, dsa_dn = settings_dn.split(',', 1) if prefix != 'CN=NTDS Settings': raise CommandError("Expected NTDS Settings DN, got %s" % settings_dn) cursors.append((dsa_dn, inv_id, int(c.highest_usn), nttime2unix(c.last_sync_success))) return cursors