예제 #1
0
def test_entryuuid_import_and_fixup_of_invalid_values(topology):
    """ Test that when we import a database with an invalid entryuuid
    that it is accepted *and* that subsequently we can fix the invalid
    entryuuid during a fixup.

    :id: ec8ef3a7-3cd2-4cbd-b6f1-2449fa17be75

    :setup: Standalone instance

    :steps:
        1. Import the db from the ldif
        2. Check the entryuuid is invalid
        3. Run the fixup
        4. Check the entryuuid is now valid (regenerated)

    :expectedresults:
        1. Success
        2. The entryuuid is invalid
        3. Success
        4. The entryuuid is valid
    """

    # 1. Import the db
    ldif_dir = topology.standalone.get_ldif_dir()
    target_ldif = os.path.join(ldif_dir, 'localhost-userRoot-invalid.ldif')
    import_ldif = os.path.join(DATADIR1, 'localhost-userRoot-invalid.ldif')
    shutil.copyfile(import_ldif, target_ldif)
    os.chmod(target_ldif, 0o777)

    be = Backends(topology.standalone).get('userRoot')
    task = be.import_ldif([target_ldif])
    task.wait()
    assert (task.is_complete() and task.get_exit_code() == 0)

    # 2. Check the entryuuid is invalid
    account = nsUserAccounts(topology.standalone,
                             DEFAULT_SUFFIX).get("demo_user")
    euuid = account.get_attr_val_utf8('entryUUID')
    assert (euuid == "INVALID_UUID")

    # 3. Run the fixup
    topology.standalone.config.loglevel(vals=(ErrorLog.DEFAULT,
                                              ErrorLog.PLUGIN))
    plug = EntryUUIDPlugin(topology.standalone)
    task = plug.fixup(DEFAULT_SUFFIX)
    task.wait()
    assert (task.is_complete() and task.get_exit_code() == 0)
    topology.standalone.config.loglevel(vals=(ErrorLog.DEFAULT, ))

    # 4. Check the entryuuid is valid
    euuid = account.get_attr_val_utf8('entryUUID')
    print(f"❄️   account entryUUID -> {euuid}")
    assert (euuid != "INVALID_UUID")
    # Raises an error if invalid
    uuid.UUID(euuid)
예제 #2
0
    def apply(self, inst):
        # Create a unique op id.
        op_id = str(uuid4())
        op_path = os.path.join(inst.get_ldif_dir(), f'{op_id}.ldif')

        with open(self.ldif_path, 'r') as f_import:
            with open(op_path, 'w') as f_outport:
                p = ImportTransformer(f_import, f_outport, self.exclude_attributes_set)
                p.parse()

        be = Backends(inst).get(self.suffix)
        task = be.export_ldif()
        task.wait()

        task = be.import_ldif([op_path])
        task.wait()
예제 #3
0
def _entryuuid_import_and_search(topology):
    # 1
    ldif_dir = topology.standalone.get_ldif_dir()
    target_ldif = os.path.join(ldif_dir,
                               'localhost-userRoot-2020_03_30_13_14_47.ldif')
    import_ldif = os.path.join(DATADIR1,
                               'localhost-userRoot-2020_03_30_13_14_47.ldif')
    shutil.copyfile(import_ldif, target_ldif)
    os.chmod(target_ldif, 0o777)

    be = Backends(topology.standalone).get('userRoot')
    task = be.import_ldif([target_ldif])
    task.wait()
    assert (task.is_complete() and task.get_exit_code() == 0)

    accounts = Accounts(topology.standalone, DEFAULT_SUFFIX)
    # 2 - positive eq test
    r2 = accounts.filter("(entryUUID=%s)" % IMPORT_UUID_A)
    assert (len(r2) == 1)
    r3 = accounts.filter("(entryuuid=%s)" % IMPORT_UUID_B)
    assert (len(r3) == 1)
    # 3 - negative eq test
    r4 = accounts.filter("(entryuuid=%s)" % UUID_MAX)
    assert (len(r4) == 0)
    # 4 - le search
    r5 = accounts.filter("(entryuuid<=%s)" % UUID_BETWEEN)
    assert (len(r5) == 1)
    # 5 - ge search
    r6 = accounts.filter("(entryuuid>=%s)" % UUID_BETWEEN)
    assert (len(r6) == 1)
    # 6 - le 0 search
    r7 = accounts.filter("(entryuuid<=%s)" % UUID_MIN)
    assert (len(r7) == 0)
    # 7 - ge f search
    r8 = accounts.filter("(entryuuid>=%s)" % UUID_MAX)
    assert (len(r8) == 0)
    # 8 - export db
    task = be.export_ldif()
    task.wait()
    assert (task.is_complete() and task.get_exit_code() == 0)