Debian Codegraph @

dirsrvtests/tests/suites/config/config_delete_attr_test.py

raw
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 import pytest
10
11 from lib389.utils import os, logging, ds_is_older, ldap
12 from test389.topologies import topology_st
13
14 logging.getLogger(__name__).setLevel(logging.DEBUG)
15 log = logging.getLogger(__name__)
16
17 # Skip on older versions
18 pytestmark = [pytest.mark.tier2,
19 pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")]
20
21
22 def test_delete_storagescheme(topology_st):
23 """ Test that deletion of passwordStorageScheme is rejected
24
25 :id: 53ab2dbf-e37c-4d30-8cce-0d5f44ed204a
26 :setup: Standalone instance
27 :steps:
28 1. Create instance
29 2. Modify passwordStorageScheme attribute
30 3. Remove passwordStorageScheme attribute
31 4. Check exception message
32 :expectedresults:
33 1. Success
34 2. Success
35 3. Removal should be rejected
36 4. Message should be about rejected change
37 """
38
39 standalone = topology_st.standalone
40
41 log.info('Check we can modify passwordStorageScheme')
42 standalone.config.set('passwordStorageScheme', 'CLEAR')
43 assert standalone.config.get_attr_val_utf8('passwordStorageScheme') == 'CLEAR'
44
45 log.info('Check removal of passwordStorageScheme is rejected')
46 with pytest.raises(ldap.OPERATIONS_ERROR) as excinfo:
47 standalone.config.remove('passwordStorageScheme', None)
48 assert "deleting the value is not allowed" in str(excinfo.value)
49
50
51 def test_reset_attributes(topology_st):
52 """ Test that we can reset some attributes while others are rejected
53
54 :id: 5f78088f-36d3-4a0b-8c1b-4abc161e996f
55 :setup: Standalone instance
56 :steps:
57 1. Create instance
58 2. Check attributes from attr_to_test can be reset
59 3. Check value of that attribute is empty
60 4. Check reset of attributes from attr_to_fail is rejected
61 :expectedresults:
62 1. Success
63 2. Success
64 3. Success
65 4. Success
66 """
67
68 standalone = topology_st.standalone
69
70 # These attributes should not be able to reset
71 attr_to_fail = [
72 'nsslapd-localuser',
73 'nsslapd-defaultnamingcontext',
74 'nsslapd-accesslog',
75 'nsslapd-auditlog',
76 'nsslapd-securitylog',
77 'nsslapd-errorlog',
78 'nsslapd-tmpdir',
79 'nsslapd-rundir',
80 'nsslapd-bakdir',
81 'nsslapd-certdir',
82 'nsslapd-instancedir',
83 'nsslapd-ldifdir',
84 'nsslapd-lockdir',
85 'nsslapd-schemadir',
86 'nsslapd-workingdir',
87 'nsslapd-localhost',
88 'nsslapd-certmap-basedn',
89 'nsslapd-port',
90 'nsslapd-secureport',
91 'nsslapd-rootpw',
92 'nsslapd-hash-filters',
93 'nsslapd-requiresrestart',
94 'nsslapd-plugin',
95 'nsslapd-privatenamespaces',
96 'nsslapd-allowed-to-delete-attrs',
97 'nsslapd-accesslog-list',
98 'nsslapd-auditfaillog-list',
99 'nsslapd-auditlog-list',
100 'nsslapd-errorlog-list',
101 'nsslapd-config',
102 'nsslapd-versionstring',
103 'objectclass',
104 'cn',
105 'nsslapd-backendconfig',
106 'nsslapd-betype',
107 'nsslapd-connection-buffer',
108 'nsslapd-malloc-mmap-threshold',
109 'nsslapd-malloc-mxfast',
110 'nsslapd-malloc-trim-threshold',
111 'nsslapd-referralmode',
112 'nsslapd-saslpath',
113 'passwordadmindn'
114 ]
115
116 attr_to_test = {
117 'nsslapd-listenhost': 'localhost',
118 'nsslapd-securelistenhost': 'localhost',
119 'nsslapd-allowed-sasl-mechanisms': 'GSSAPI',
120 'nsslapd-svrtab': 'Some data'
121 }
122
123 for attr in attr_to_test:
124 newval = attr_to_test[attr]
125
126 log.info("Change %s value to --> %s" % (attr, newval))
127 standalone.config.set(attr, newval)
128 assert standalone.config.get_attr_val_utf8(attr) == newval
129
130 log.info('Now reset the attribute')
131 standalone.config.reset(attr)
132 assert standalone.config.get_attr_val_utf8(attr) == ''
133 log.info("%s is reset to None" % attr)
134
135 for attr in attr_to_fail:
136 log.info("Resetting %s" % attr)
137 try:
138 standalone.config.reset(attr)
139 # Shouldn't reach here, the reset should fail!
140 log.info('Attribute deletion should fail => test failed!')
141 assert False
142 except (ldap.UNWILLING_TO_PERFORM, ldap.OPERATIONS_ERROR, ldap.OBJECT_CLASS_VIOLATION):
143 log.info('Change was rejected, test passed')
144 pass
145 except ldap.NO_SUCH_ATTRIBUTE:
146 log.info("This attribute isn't part of cn=config, so is already default!")
147 pass
148
149
150 if __name__ == '__main__':
151 # Run isolated
152 # -s for DEBUG mode
153 CURRENT_FILE = os.path.realpath(__file__)
154 pytest.main("-s %s" % CURRENT_FILE)