def test_rename_good_subnet_to_good_subnet(self): """Make sure that we can rename subnets""" basedn = self.ldb.get_config_basedn() cidr = "10.16.0.0/24" new_cidr = "10.16.1.0/24" subnets.create_subnet(self.ldb, basedn, cidr, self.sitename) subnets.rename_subnet(self.ldb, basedn, cidr, new_cidr) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % new_cidr) self.assertEqual(len(ret), 1, 'Failed to rename subnet %s' % cidr) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % cidr) self.assertEqual(len(ret), 0, 'Failed to remove old subnet during rename %s' % cidr) subnets.delete_subnet(self.ldb, basedn, new_cidr)
def test_rename_delete_good_subnet_to_good_subnet_other_user(self): """Make sure that we can't rename or delete subnets when we aren't admin.""" basedn = self.ldb.get_config_basedn() cidr = "10.16.0.0/24" new_cidr = "10.16.1.0/24" subnets.create_subnet(self.ldb, basedn, cidr, self.sitename) user, non_admin_ldb = self.get_user_and_ldb("notadmin", "samba123@") try: subnets.rename_subnet(non_admin_ldb, basedn, cidr, new_cidr) except LdbError as e: self.assertEqual(e.args[0], ERR_INSUFFICIENT_ACCESS_RIGHTS, ("subnet rename by non-admin failed " "in the wrong way: %s" % e)) else: self.fail("subnet rename by non-admin succeeded") ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % cidr) self.assertEqual(len(ret), 1, ('Subnet %s destroyed or renamed ' 'by non-admin' % cidr)) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression=('(&(objectclass=subnet)(cn=%s))' % new_cidr)) self.assertEqual(len(ret), 0, 'New subnet %s created by non-admin' % cidr) try: subnets.delete_subnet(non_admin_ldb, basedn, cidr) except LdbError as e: self.assertEqual(e.args[0], ERR_INSUFFICIENT_ACCESS_RIGHTS, ("subnet delete by non-admin failed " "in the wrong way: %s" % e)) else: self.fail("subnet delete by non-admin succeeded:") ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % cidr) self.assertEqual(len(ret), 1, 'Subnet %s deleted non-admin' % cidr) subnets.delete_subnet(self.ldb, basedn, cidr)