| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2021 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
|
| 10 |
import pytest |
| 11 |
|
| 12 |
from lib389.utils import * |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389.cli_conf.backend import * |
| 15 |
from lib389.cli_base import FakeArgs |
| 16 |
from lib389._constants import DEFAULT_SUFFIX |
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier1 |
| 19 |
|
| 20 |
|
| 21 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 22 |
if DEBUGGING: |
| 23 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 24 |
else: |
| 25 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 26 |
log = logging.getLogger(__name__) |
| 27 |
|
| 28 |
|
| 29 |
def create_example_ldif(topology_st): |
| 30 |
ldif_dir = topology_st.standalone.get_ldif_dir() |
| 31 |
line1 = """version: 1 |
| 32 |
|
| 33 |
# entry-id: 1 |
| 34 |
dn: dc=example,dc=com |
| 35 |
nsUniqueId: e5c4172a-97aa11eb-aaa8e47e-b1e12808 |
| 36 |
objectClass: top |
| 37 |
objectClass: domain |
| 38 |
dc: example |
| 39 |
description: dc=example,dc=com |
| 40 |
creatorsName: cn=Directory Manager |
| 41 |
modifiersName: cn=Directory Manager |
| 42 |
createTimestamp: 20210407140942Z |
| 43 |
modifyTimestamp: 20210407140942Z |
| 44 |
aci: (targetattr="dc || description || objectClass")(targetfilter="(objectClas |
| 45 |
s=domain)")(version 3.0; acl "Enable anyone domain read"; allow (read, search |
| 46 |
, compare)(userdn="ldap:///anyone");) |
| 47 |
|
| 48 |
# entry-id: 3 |
| 49 |
dn: uid=demo,ou=People,dc=example,dc=com |
| 50 |
objectClass: person |
| 51 |
objectClass: inetOrgPerson |
| 52 |
objectClass: organizationalPerson |
| 53 |
objectClass: posixAccount |
| 54 |
objectClass: top |
| 55 |
uidNumber: 1119 |
| 56 |
gidNumber: 1000 |
| 57 |
nsUniqueId: 9a0e6603-a1cb11eb-aa2daeeb-95660ab0 |
| 58 |
creatorsName: |
| 59 |
modifiersName: cn=directory manager |
| 60 |
createTimestamp: 20210420112927Z |
| 61 |
modifyTimestamp: 20210420113016Z |
| 62 |
passwordGraceUserTime: 0 |
| 63 |
cn: demo |
| 64 |
homeDirectory: /home/demo |
| 65 |
uid: demo |
| 66 |
sn: demo |
| 67 |
|
| 68 |
""" |
| 69 |
with open(f'{ldif_dir}/warning_parent.ldif', 'w') as out: |
| 70 |
out.write(f'{line1}') |
| 71 |
os.chmod(out.name, 0o777) |
| 72 |
out.close() |
| 73 |
import_ldif1 = ldif_dir + '/warning_parent.ldif' |
| 74 |
return import_ldif1 |
| 75 |
|
| 76 |
|
| 77 |
@pytest.mark.skipif(ds_is_older('1.4.3.26'), reason="Fail because of bug 1951537") |
| 78 |
def test_import_warning(topology_st): |
| 79 |
"""Import ldif file with skipped entries to generate a warning message |
| 80 |
|
| 81 |
:id: 66f9275b-11b4-4718-b401-18fa6011b362 |
| 82 |
:setup: Standalone Instance |
| 83 |
:steps: |
| 84 |
1. Create LDIF file with skipped entries |
| 85 |
2. Import the LDIF file with backend import |
| 86 |
3. Check the topology logs |
| 87 |
4. Check errors log |
| 88 |
:expectedresults: |
| 89 |
1. Success |
| 90 |
2. Success |
| 91 |
3. Result message should contain warning code |
| 92 |
4. Errors log should contain skipped entry message |
| 93 |
""" |
| 94 |
|
| 95 |
standalone = topology_st.standalone |
| 96 |
message = 'The import task has finished successfully, with warning code 8, check the logs for more detail' |
| 97 |
|
| 98 |
args = FakeArgs() |
| 99 |
args.be_name = 'userRoot' |
| 100 |
args.ldifs = [create_example_ldif(topology_st)] |
| 101 |
args.chunks_size = None |
| 102 |
args.encrypted = False |
| 103 |
args.gen_uniq_id = None |
| 104 |
args.only_core = False |
| 105 |
args.include_suffixes = 'dc=example,dc=com' |
| 106 |
args.exclude_suffixes = None |
| 107 |
args.timeout = 0 |
| 108 |
args.watch = False |
| 109 |
|
| 110 |
log.info('Import the LDIF file') |
| 111 |
backend_import(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 112 |
|
| 113 |
log.info('Check logs for a warning message') |
| 114 |
assert topology_st.logcap.contains(message) |
| 115 |
assert standalone.ds_error_log.match('.*Skipping entry "uid=demo,ou=People,dc=example,dc=com" which has no parent.*') |
| 116 |
|
| 117 |
|
| 118 |
if __name__ == '__main__': |
| 119 |
# Run isolated |
| 120 |
# -s for DEBUG mode |
| 121 |
CURRENT_FILE = os.path.realpath(__file__) |
| 122 |
pytest.main("-s %s" % CURRENT_FILE) |