| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 pytest |
| 10 |
import logging |
| 11 |
import time |
| 12 |
import ldap |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389._constants import DEFAULT_SUFFIX |
| 15 |
from lib389.idm.domain import Domain |
| 16 |
|
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier2 |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
def test_aci_with_ip_restrictions_does_not_crash_server(topology_st): |
| 25 |
""" Test that ACI's that use IP restrictions do not crash the server at |
| 26 |
shutdown |
| 27 |
|
| 28 |
:id: 2ca3e3c9-8ac4-4f73-8604-c9133c6c7956 |
| 29 |
:setup: Standalone instance |
| 30 |
:steps: |
| 31 |
1. Create an ACI with IP restriction |
| 32 |
2. Anonymous bind |
| 33 |
3. Search for the ACI to engage it |
| 34 |
4. Restart the server |
| 35 |
:expectedresults: |
| 36 |
1. Success |
| 37 |
2. Success |
| 38 |
3. Success |
| 39 |
4. Server should not crash |
| 40 |
""" |
| 41 |
|
| 42 |
# Add aci to restrict access my ip |
| 43 |
ACI_TARGET = ('(targetattr != "userPassword")') |
| 44 |
ACI_ALLOW = ('(version 3.0;acl "Enable anonymous access - IP"; allow (read,compare,search)') |
| 45 |
ACI_SUBJECT = ('(userdn = "ldap:///anyone") and (ip="127.0.0.1");)') |
| 46 |
ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT |
| 47 |
suffix = Domain(topology_st.standalone, DEFAULT_SUFFIX) |
| 48 |
|
| 49 |
try: |
| 50 |
suffix.add('aci', ACI) |
| 51 |
except ldap.LDAPError as e: |
| 52 |
log.error('Failed to add aci: ({}) error {}'.format(ACI,e.args[0]['desc'])) |
| 53 |
assert False |
| 54 |
except ldap.TYPE_OR_VALUE_EXISTS: |
| 55 |
pass |
| 56 |
time.sleep(1) |
| 57 |
|
| 58 |
# Anonymous search to engage the aci |
| 59 |
try: |
| 60 |
topology_st.standalone.simple_bind_s("", "", escapehatch="i am sure") |
| 61 |
except ldap.LDAPError as e: |
| 62 |
log.error('Failed to anonymously bind -error {}'.format(e.args[0]['desc'])) |
| 63 |
assert False |
| 64 |
|
| 65 |
try: |
| 66 |
entries = suffix.search(filter='objectclass=*')#topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'objectclass=*') |
| 67 |
if not entries: |
| 68 |
log.fatal('Failed return an entries from search') |
| 69 |
assert False |
| 70 |
except ldap.LDAPError as e: |
| 71 |
log.fatal('Search failed: ' + e.message['desc']) |
| 72 |
assert False |
| 73 |
|
| 74 |
# Restart the server |
| 75 |
topology_st.standalone.restart(timeout=10) |
| 76 |
|
| 77 |
# Check for crash |
| 78 |
if topology_st.standalone.detectDisorderlyShutdown(): |
| 79 |
log.fatal('Server crashed!') |
| 80 |
assert False |
| 81 |
|
| 82 |
log.info('Test complete') |
| 83 |
|
| 84 |
|
| 85 |
if __name__ == '__main__': |
| 86 |
# Run isolated |
| 87 |
# -s for DEBUG mode |
| 88 |
CURRENT_FILE = os.path.realpath(__file__) |
| 89 |
pytest.main("-s {}".format(CURRENT_FILE)) |