Esempio n. 1
0
def test_usandsconf_dbgen_cos_indirect(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create a COS definition

        :id: ab4b799e-e801-432a-a61d-badad2628201
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate ldif with indirect COS definition
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    LDAP_RESULT = 'adding new entry "cn=My_Postal_Def_indirect,ou=cos indirect definitions,dc=example,dc=com"'

    standalone = topology_st.standalone

    args = FakeArgs()
    args.type = 'indirect'
    args.NAME = 'My_Postal_Def_indirect'
    args.parent = 'ou=cos indirect definitions,dc=example,dc=com'
    args.create_parent = True
    args.cos_specifier = 'businessCategory'
    args.cos_attr = ['postalcode', 'telephonenumber']
    args.cos_template = None
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'NAME={}'.format(args.NAME), 'type={}'.format(args.type),
        'parent={}'.format(args.parent), 'create-parent={}'.format(
            args.create_parent), 'cos-specifier={}'.format(args.cos_specifier),
        'cos-attr={}'.format(args.cos_attr),
        'ldif-file={}'.format(args.ldif_file), 'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create COS definition ldif')
    dbgen_create_cos_def(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)

    log.info('Check that COS definition is imported')
    cos_def = CosIndirectDefinitions(standalone, args.parent)
    assert cos_def.exists(args.NAME)
    new_cos = cos_def.get(args.NAME)
    assert new_cos.present('cosIndirectSpecifier', args.cos_specifier)
    assert new_cos.present('cosAttribute', args.cos_attr[0])
    assert new_cos.present('cosAttribute', args.cos_attr[1])
Esempio n. 2
0
def test_usandsconf_dbgen_filtered_role(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create a filtered role

        :id: cb3c8ea8-4234-40e2-8810-fb6a25973921
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate ldif with filtered role
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    LDAP_RESULT = 'adding new entry "cn=My_Filtered_Role,ou=filtered roles,dc=example,dc=com"'

    standalone = topology_st.standalone

    args = FakeArgs()

    args.NAME = 'My_Filtered_Role'
    args.parent = 'ou=filtered roles,dc=example,dc=com'
    args.create_parent = True
    args.type = 'filtered'
    args.filter = '"objectclass=posixAccount"'
    args.role_dn = None
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'NAME={}'.format(args.NAME), 'parent={}'.format(args.parent),
        'create-parent={}'.format(args.create_parent),
        'type={}'.format(args.type), 'filter={}'.format(args.filter),
        'ldif-file={}'.format(args.ldif_file), 'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create filtered role ldif')
    dbgen_create_role(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)

    log.info('Check that filtered role is imported')
    roles = FilteredRoles(standalone, DEFAULT_SUFFIX)
    assert roles.exists(args.NAME)
    new_role = roles.get(args.NAME)
    assert new_role.present('nsRoleFilter', args.filter)
Esempio n. 3
0
def test_usandsconf_dbgen_cos_template(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create a COS template

        :id: 544017c7-4a82-4e7d-a047-00b68a28e071
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate ldif with COS template
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    LDAP_RESULT = 'adding new entry "cn=My_Template,ou=cos templates,dc=example,dc=com"'

    standalone = topology_st.standalone

    args = FakeArgs()
    args.NAME = 'My_Template'
    args.parent = 'ou=cos templates,dc=example,dc=com'
    args.create_parent = True
    args.cos_priority = "1"
    args.cos_attr_val = 'postalcode:12345'
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'NAME={}'.format(args.NAME), 'parent={}'.format(args.parent),
        'create-parent={}'.format(args.create_parent),
        'cos-priority={}'.format(args.cos_priority),
        'cos-attr-val={}'.format(args.cos_attr_val),
        'ldif-file={}'.format(args.ldif_file), 'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create COS template ldif')
    dbgen_create_cos_tmp(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)

    log.info('Check that COS template is imported')
    cos_temp = CosTemplates(standalone, args.parent)
    assert cos_temp.exists(args.NAME)
    new_cos = cos_temp.get(args.NAME)
    assert new_cos.present('cosPriority', str(args.cos_priority))
    assert new_cos.present('postalcode', '12345')
Esempio n. 4
0
def test_dsconf_dbgen_nested_role(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create a nested role

        :id: 97fff0a8-3103-4adb-be04-2799ff58d8f4
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate ldif with nested role
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    LDAP_RESULT = 'adding new entry "cn=My_Nested_Role,ou=nested roles,dc=example,dc=com"'

    standalone = topology_st.standalone

    args = FakeArgs()
    args.NAME = 'My_Nested_Role'
    args.parent = 'ou=nested roles,dc=example,dc=com'
    args.create_parent = True
    args.type = 'nested'
    args.filter = None
    args.role_dn = ['cn=some_role,ou=roles,dc=example,dc=com']
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'NAME={}'.format(args.NAME), 'parent={}'.format(args.parent),
        'create-parent={}'.format(args.create_parent),
        'type={}'.format(args.type), 'role-dn={}'.format(args.role_dn),
        'ldif-file={}'.format(args.ldif_file), 'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create nested role ldif')
    dbgen_create_role(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)

    log.info('Check that nested role is imported')
    roles = NestedRoles(standalone, DEFAULT_SUFFIX)
    assert roles.exists(args.NAME)
    new_role = roles.get(args.NAME)
    assert new_role.present('nsRoleDN', args.role_dn[0])
Esempio n. 5
0
def test_usandsconf_dbgen_managed_role(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create a managed role

        :id: 10e77b41-0bc1-4ad5-a144-2c5107455b91
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate ldif with managed role
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    LDAP_RESULT = 'adding new entry "cn=My_Managed_Role,ou=managed roles,dc=example,dc=com"'

    standalone = topology_st.standalone

    args = FakeArgs()

    args.NAME = 'My_Managed_Role'
    args.parent = 'ou=managed roles,dc=example,dc=com'
    args.create_parent = True
    args.type = 'managed'
    args.filter = None
    args.role_dn = None
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'NAME={}'.format(args.NAME), 'parent={}'.format(args.parent),
        'create-parent={}'.format(args.create_parent),
        'type={}'.format(args.type), 'ldif-file={}'.format(args.ldif_file),
        'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create managed role ldif')
    dbgen_create_role(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)

    log.info('Check that managed role is imported')
    roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
    assert roles.exists(args.NAME)
Esempio n. 6
0
def test_usandsconf_dbgen_mod_ldif_mixed(topology_st, set_log_file_and_ldif):
    """Test ldifgen (formerly dbgen) tool to create mixed modification ldif

        :id: 4a2e0901-2b48-452e-a4a0-507735132c81
        :setup: Standalone instance
        :steps:
             1. Create DS instance
             2. Run ldifgen to generate modification ldif
             3. Import generated ldif to database
             4. Check it was properly imported
        :expectedresults:
             1. Success
             2. Success
             3. Success
             4. Success
        """

    standalone = topology_st.standalone

    args = FakeArgs()
    args.parent = DEFAULT_SUFFIX
    args.create_users = True
    args.delete_users = True
    args.create_parent = False
    args.num_users = "1000"
    args.add_users = "100"
    args.del_users = "999"
    args.modrdn_users = "100"
    args.mod_users = "10"
    args.mod_attrs = ['cn', 'uid', 'sn']
    args.randomize = False
    args.ldif_file = ldif_file

    content_list = [
        'Generating LDIF with the following options:',
        'create-users={}'.format(args.create_users), 'parent={}'.format(
            args.parent), 'create-parent={}'.format(args.create_parent),
        'delete-users={}'.format(args.delete_users), 'num-users={}'.format(
            args.num_users), 'add-users={}'.format(args.add_users),
        'del-users={}'.format(args.del_users), 'modrdn-users={}'.format(
            args.modrdn_users), 'mod-users={}'.format(args.mod_users),
        'mod-attrs={}'.format(args.mod_attrs),
        'randomize={}'.format(args.randomize),
        'ldif-file={}'.format(args.ldif_file), 'Writing LDIF',
        'Successfully created LDIF file: {}'.format(args.ldif_file)
    ]

    log.info('Run ldifgen to create modification ldif')
    dbgen_create_mods(standalone, log, args)

    log.info('Check if file exists')
    assert os.path.exists(ldif_file)

    check_value_in_log_and_reset(content_list)

    log.info('Get number of accounts before import')
    accounts = Accounts(standalone, DEFAULT_SUFFIX)
    count_account = len(accounts.filter('(uid=*)'))

    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
    # ldapmodify will complain about a lot of changes done which causes subprocess to return exit code != 0
    with pytest.raises(subprocess.CalledProcessError):
        run_ldapmodify_from_file(standalone, ldif_file)

    log.info('Check that some accounts are imported')
    assert len(accounts.filter('(uid=*)')) > count_account