| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022 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 |
import logging |
| 10 |
import pytest |
| 11 |
import os |
| 12 |
from lib389._constants import DEFAULT_SUFFIX |
| 13 |
from test389.topologies import topology_m1 as topo |
| 14 |
from lib389.backend import Backends |
| 15 |
from lib389.encrypted_attributes import EncryptedAttrs |
| 16 |
|
| 17 |
pytestmark = pytest.mark.tier1 |
| 18 |
|
| 19 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 20 |
if DEBUGGING: |
| 21 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 22 |
else: |
| 23 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 24 |
log = logging.getLogger(__name__) |
| 25 |
|
| 26 |
SECOND_SUFFIX = 'o=namingcontext' |
| 27 |
THIRD_SUFFIX = 'o=namingcontext2' |
| 28 |
|
| 29 |
def test_be_delete(topo): |
| 30 |
"""Test that we can delete a backend that contains replication |
| 31 |
configuration and encrypted attributes. The default naming |
| 32 |
context should also be updated to reflect the next available suffix |
| 33 |
|
| 34 |
:id: 5208f897-7c95-4925-bad0-9ceb95fee678 |
| 35 |
:setup: Supplier Instance |
| 36 |
:steps: |
| 37 |
1. Create second backend/suffix |
| 38 |
2. Add an encrypted attribute to the default suffix |
| 39 |
3. Delete default suffix |
| 40 |
4. Check the nsslapd-defaultnamingcontext is updated |
| 41 |
5. Delete the last backend |
| 42 |
6. Check the namingcontext has not changed |
| 43 |
7. Add new backend |
| 44 |
8. Set default naming context |
| 45 |
9. Verify the naming context is correct |
| 46 |
:expectedresults: |
| 47 |
1. Success |
| 48 |
2. Success |
| 49 |
3. Success |
| 50 |
4. Success |
| 51 |
5. Success |
| 52 |
6. Success |
| 53 |
7. Success |
| 54 |
8. Success |
| 55 |
9. Success |
| 56 |
""" |
| 57 |
|
| 58 |
inst = topo.ms["supplier1"] |
| 59 |
|
| 60 |
# Create second suffix |
| 61 |
backends = Backends(inst) |
| 62 |
default_backend = backends.get(DEFAULT_SUFFIX) |
| 63 |
new_backend = backends.create(properties={'nsslapd-suffix': SECOND_SUFFIX, |
| 64 |
'name': 'namingRoot'}) |
| 65 |
|
| 66 |
# Add encrypted attribute entry under default suffix |
| 67 |
encrypt_attrs = EncryptedAttrs(inst, basedn='cn=encrypted attributes,{}'.format(default_backend.dn)) |
| 68 |
encrypt_attrs.create(properties={'cn': 'employeeNumber', 'nsEncryptionAlgorithm': 'AES'}) |
| 69 |
|
| 70 |
# Delete default suffix |
| 71 |
default_backend.delete() |
| 72 |
|
| 73 |
# Check that the default naming context is set to the new/second suffix |
| 74 |
default_naming_ctx = inst.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') |
| 75 |
assert default_naming_ctx == SECOND_SUFFIX |
| 76 |
|
| 77 |
# delete new backend, but the naming context should not change |
| 78 |
new_backend.delete() |
| 79 |
|
| 80 |
# Check that the default naming context is still set to the new/second suffix |
| 81 |
default_naming_ctx = inst.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') |
| 82 |
assert default_naming_ctx == SECOND_SUFFIX |
| 83 |
|
| 84 |
# Add new backend |
| 85 |
new_backend = backends.create(properties={'nsslapd-suffix': THIRD_SUFFIX, |
| 86 |
'name': 'namingRoot2'}) |
| 87 |
|
| 88 |
# manaully set naming context |
| 89 |
inst.config.set('nsslapd-defaultnamingcontext', THIRD_SUFFIX) |
| 90 |
|
| 91 |
# Verify naming context is correct |
| 92 |
default_naming_ctx = inst.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') |
| 93 |
assert default_naming_ctx == THIRD_SUFFIX |
| 94 |
|
| 95 |
|
| 96 |
if __name__ == '__main__': |
| 97 |
# Run isolated |
| 98 |
# -s for DEBUG mode |
| 99 |
CURRENT_FILE = os.path.realpath(__file__) |
| 100 |
pytest.main(["-s", CURRENT_FILE]) |
| 101 |
|