| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2019 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 logging |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
|
| 14 |
from lib389._constants import * |
| 15 |
from test389.topologies import topology_st |
| 16 |
from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES |
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier3 |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.skipif(os.getenv('MIGRATION') is None, reason="This test is meant to execute in specific test environment") |
| 25 |
def test_export_data_from_source_host(topology_st): |
| 26 |
"""Prepare export file for migration using a single instance of Directory Server |
| 27 |
|
| 28 |
:id: 47f97d87-60f7-4f80-a72b-e7daa1de0061 |
| 29 |
:setup: Standalone |
| 30 |
:steps: |
| 31 |
1. Add a test user with employeeNumber and telephoneNumber |
| 32 |
2. Add a test user with escaped DN |
| 33 |
3. Create export file |
| 34 |
4. Check if values of searched attributes are present in exported file |
| 35 |
:expectedresults: |
| 36 |
1. Success |
| 37 |
2. Success |
| 38 |
3. Success |
| 39 |
4. Success |
| 40 |
""" |
| 41 |
|
| 42 |
standalone = topology_st.standalone |
| 43 |
output_file = os.path.join(topology_st.standalone.ds_paths.ldif_dir, "migration_export.ldif") |
| 44 |
|
| 45 |
log.info("Add a test user") |
| 46 |
users = UserAccounts(standalone, DEFAULT_SUFFIX) |
| 47 |
test_user = users.create(properties=TEST_USER_PROPERTIES) |
| 48 |
test_user.add('employeeNumber', '1000') |
| 49 |
test_user.add('telephoneNumber', '1234567890') |
| 50 |
|
| 51 |
assert test_user.present('employeeNumber', value='1000') |
| 52 |
assert test_user.present('telephoneNumber', value='1234567890') |
| 53 |
|
| 54 |
log.info("Creating user with escaped DN") |
| 55 |
users.create(properties={ |
| 56 |
'uid': '\\#\\,\\+"\\\\>:\\=\\<\\<\\>\\;/', |
| 57 |
'cn': 'tuser2', |
| 58 |
'sn': 'user', |
| 59 |
'uidNumber': '1000', |
| 60 |
'gidNumber': '2000', |
| 61 |
'homeDirectory': '/home/tuser2', |
| 62 |
}) |
| 63 |
|
| 64 |
log.info("Exporting LDIF offline...") |
| 65 |
standalone.stop() |
| 66 |
standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], |
| 67 |
excludeSuffixes=None, encrypt=None, repl_data=None, outputfile=output_file) |
| 68 |
standalone.start() |
| 69 |
|
| 70 |
log.info("Check that value of attribute is present in the exported file") |
| 71 |
with open(output_file, 'r') as ldif_file: |
| 72 |
ldif = ldif_file.read() |
| 73 |
assert 'employeeNumber: 1000' in ldif |
| 74 |
assert 'telephoneNumber: 1234567890' in ldif |
| 75 |
assert 'uid: \\#\\,\\+"\\\\>:\\=\\<\\<\\>\\;/' in ldif |
| 76 |
|
| 77 |
|
| 78 |
if __name__ == '__main__': |
| 79 |
# Run isolated |
| 80 |
# -s for DEBUG mode |
| 81 |
CURRENT_FILE = os.path.realpath(__file__) |
| 82 |
pytest.main(["-s", CURRENT_FILE]) |