| 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 ldap |
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
import time |
| 14 |
from lib389._constants import DEFAULT_SUFFIX, PASSWORD |
| 15 |
from lib389.idm.domain import Domain |
| 16 |
from lib389.idm.user import UserAccounts |
| 17 |
from test389.topologies import topology_st as topo |
| 18 |
|
| 19 |
log = logging.getLogger(__name__) |
| 20 |
|
| 21 |
def test_expired_user_has_no_privledge(topo): |
| 22 |
"""Specify a test case purpose or name here |
| 23 |
|
| 24 |
:id: 3df86b45-9929-414b-9bf6-06c25301d207 |
| 25 |
:setup: Standalone Instance |
| 26 |
:steps: |
| 27 |
1. Set short password expiration time |
| 28 |
2. Add user and wait for expiration time to run out |
| 29 |
3. Set one aci that allows authenticated users full access |
| 30 |
4. Bind as user (password should be expired) |
| 31 |
5. Attempt modify |
| 32 |
:expectedresults: |
| 33 |
1. Success |
| 34 |
2. Success |
| 35 |
3. Success |
| 36 |
4. Success |
| 37 |
5. Success |
| 38 |
""" |
| 39 |
|
| 40 |
# Configured password epxiration |
| 41 |
topo.standalone.config.replace_many(('passwordexp', 'on'), ('passwordmaxage', '1')) |
| 42 |
|
| 43 |
# Set aci |
| 44 |
suffix = Domain(topo.standalone, DEFAULT_SUFFIX) |
| 45 |
ACI_TEXT = '(targetattr="*")(version 3.0; acl "test aci"; allow (all) (userdn="ldap:///all");)' |
| 46 |
suffix.replace('aci', ACI_TEXT) |
| 47 |
|
| 48 |
# Add user |
| 49 |
user = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None).create_test_user() |
| 50 |
user.replace('userpassword', PASSWORD) |
| 51 |
time.sleep(2) |
| 52 |
|
| 53 |
# Bind as user with expired password. Need to use raw ldap calls because |
| 54 |
# lib389 will close the connection when an error 49 is encountered. |
| 55 |
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, os.path.join(topo.standalone.get_config_dir(), "ca.crt")) |
| 56 |
ldap_object = ldap.initialize(topo.standalone.toLDAPURL()) |
| 57 |
with pytest.raises(ldap.INVALID_CREDENTIALS): |
| 58 |
res_type, res_data, res_msgid, res_ctrls = ldap_object.simple_bind_s( |
| 59 |
user.dn, PASSWORD) |
| 60 |
|
| 61 |
# Try modify |
| 62 |
with pytest.raises(ldap.INSUFFICIENT_ACCESS): |
| 63 |
modlist = [ (ldap.MOD_REPLACE, 'description', b'Should not work!') ] |
| 64 |
ldap_object.modify_ext_s(DEFAULT_SUFFIX, modlist) |
| 65 |
|
| 66 |
|
| 67 |
if __name__ == '__main__': |
| 68 |
# Run isolated |
| 69 |
# -s for DEBUG mode |
| 70 |
CURRENT_FILE = os.path.realpath(__file__) |
| 71 |
pytest.main(["-s", CURRENT_FILE]) |