| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2016 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 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from test389.topologies import topology_st |
| 13 |
|
| 14 |
from lib389._constants import DEFAULT_SUFFIX, DN_PLUGIN, SUFFIX, PLUGIN_7_BIT_CHECK |
| 15 |
|
| 16 |
# Skip on older versions |
| 17 |
pytestmark = [pytest.mark.tier1, |
| 18 |
pytest.mark.skipif(ds_is_older('1.3'), reason="Not implemented")] |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
DN_7BITPLUGIN = "cn=7-bit check,%s" % DN_PLUGIN |
| 24 |
ATTRS = ["uid", "mail", "userpassword", ",", SUFFIX, None] |
| 25 |
|
| 26 |
|
| 27 |
@pytest.fixture(scope="module") |
| 28 |
def enable_plugin(topology_st): |
| 29 |
"""Enabling the 7-bit plugin for the |
| 30 |
environment setup""" |
| 31 |
log.info("Ticket 47431 - 0: Enable 7bit plugin...") |
| 32 |
topology_st.standalone.plugins.enable(name=PLUGIN_7_BIT_CHECK) |
| 33 |
|
| 34 |
|
| 35 |
def test_duplicate_values(topology_st, enable_plugin): |
| 36 |
"""Check 26 duplicate values are treated as one |
| 37 |
|
| 38 |
:id: b23e04f1-2757-42cc-b3a2-26426c903f6d |
| 39 |
:setup: Standalone instance, enable 7bit plugin |
| 40 |
:steps: |
| 41 |
1. Modify the entry for cn=7-bit check,cn=plugins,cn=config as : |
| 42 |
nsslapd-pluginarg0 : uid |
| 43 |
nsslapd-pluginarg1 : mail |
| 44 |
nsslapd-pluginarg2 : userpassword |
| 45 |
nsslapd-pluginarg3 : , |
| 46 |
nsslapd-pluginarg4 : dc=example,dc=com |
| 47 |
2. Set nsslapd-pluginarg2 to 'userpassword' for multiple time (ideally 27) |
| 48 |
3. Check whether duplicate values are treated as one |
| 49 |
:expectedresults: |
| 50 |
1. It should be modified successfully |
| 51 |
2. It should be successful |
| 52 |
3. It should be successful |
| 53 |
""" |
| 54 |
|
| 55 |
log.info("Ticket 47431 - 1: Check 26 duplicate values are treated as one...") |
| 56 |
expected = "str2entry_dupcheck.* duplicate values for attribute type nsslapd-pluginarg2 detected in entry cn=7-bit check,cn=plugins,cn=config." |
| 57 |
|
| 58 |
log.debug('modify_s %s' % DN_7BITPLUGIN) |
| 59 |
topology_st.standalone.modify_s(DN_7BITPLUGIN, |
| 60 |
[(ldap.MOD_REPLACE, 'nsslapd-pluginarg0', b"uid"), |
| 61 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg1', b"mail"), |
| 62 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg2', b"userpassword"), |
| 63 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg3', b","), |
| 64 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg4', ensure_bytes(SUFFIX))]) |
| 65 |
|
| 66 |
arg2 = "nsslapd-pluginarg2: userpassword" |
| 67 |
topology_st.standalone.stop() |
| 68 |
dse_ldif = topology_st.standalone.confdir + '/dse.ldif' |
| 69 |
os.system('mv %s %s.47431' % (dse_ldif, dse_ldif)) |
| 70 |
os.system( |
| 71 |
'sed -e "s/\\(%s\\)/\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1\\n\\1/" %s.47431 > %s' % ( |
| 72 |
arg2, dse_ldif, dse_ldif)) |
| 73 |
topology_st.standalone.start() |
| 74 |
|
| 75 |
cmdline = 'egrep -i "%s" %s' % (expected, topology_st.standalone.errlog) |
| 76 |
p = os.popen(cmdline, "r") |
| 77 |
line = p.readline() |
| 78 |
if line == "": |
| 79 |
log.error('Expected error "%s" not logged in %s' % (expected, topology_st.standalone.errlog)) |
| 80 |
assert False |
| 81 |
else: |
| 82 |
log.debug('line: %s' % line) |
| 83 |
log.info('Expected error "%s" logged in %s' % (expected, topology_st.standalone.errlog)) |
| 84 |
|
| 85 |
log.info("Ticket 47431 - 1: done") |
| 86 |
|
| 87 |
|
| 88 |
def test_multiple_value(topology_st, enable_plugin): |
| 89 |
"""Check two values belonging to one arg is fixed |
| 90 |
|
| 91 |
:id: 20c802bc-332f-4e8d-bcfb-8cd28123d695 |
| 92 |
:setup: Standalone instance, enable 7bit plugin |
| 93 |
:steps: |
| 94 |
1. Modify the entry for cn=7-bit check,cn=plugins,cn=config as : |
| 95 |
nsslapd-pluginarg0 : uid |
| 96 |
nsslapd-pluginarg0 : mail |
| 97 |
nsslapd-pluginarg1 : userpassword |
| 98 |
nsslapd-pluginarg2 : , |
| 99 |
nsslapd-pluginarg3 : dc=example,dc=com |
| 100 |
nsslapd-pluginarg4 : None |
| 101 |
(Note : While modifying add two attributes entries for nsslapd-pluginarg0) |
| 102 |
|
| 103 |
2. Check two values belonging to one arg is fixed |
| 104 |
:expectedresults: |
| 105 |
1. Entries should be modified successfully |
| 106 |
2. Operation should be successful |
| 107 |
""" |
| 108 |
|
| 109 |
log.info("Ticket 47431 - 2: Check two values belonging to one arg is fixed...") |
| 110 |
|
| 111 |
topology_st.standalone.modify_s(DN_7BITPLUGIN, |
| 112 |
[(ldap.MOD_REPLACE, 'nsslapd-pluginarg0', b"uid"), |
| 113 |
(ldap.MOD_ADD, 'nsslapd-pluginarg0', b"mail"), |
| 114 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg1', b"userpassword"), |
| 115 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg2', b","), |
| 116 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg3', ensure_bytes(SUFFIX)), |
| 117 |
(ldap.MOD_DELETE, 'nsslapd-pluginarg4', None)]) |
| 118 |
|
| 119 |
# PLUGIN LOG LEVEL |
| 120 |
topology_st.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'65536')]) |
| 121 |
|
| 122 |
topology_st.standalone.restart() |
| 123 |
|
| 124 |
cmdline = 'egrep -i %s %s' % ("NS7bitAttr_Init", topology_st.standalone.errlog) |
| 125 |
p = os.popen(cmdline, "r") |
| 126 |
i = 0 |
| 127 |
while ATTRS[i]: |
| 128 |
line = p.readline() |
| 129 |
log.debug('line - %s' % line) |
| 130 |
log.debug('ATTRS[%d] %s' % (i, ATTRS[i])) |
| 131 |
if line == "": |
| 132 |
break |
| 133 |
elif line.find(ATTRS[i]) >= 0: |
| 134 |
log.debug('%s was logged' % ATTRS[i]) |
| 135 |
else: |
| 136 |
log.error('%s was not logged.' % ATTRS[i]) |
| 137 |
assert False |
| 138 |
i = i + 1 |
| 139 |
|
| 140 |
log.info("Ticket 47431 - 2: done") |
| 141 |
|
| 142 |
|
| 143 |
def test_missing_args(topology_st, enable_plugin): |
| 144 |
"""Check missing args are fixed |
| 145 |
|
| 146 |
:id: b2814399-7ed2-4fe0-981d-b0bdbbe31cfb |
| 147 |
:setup: Standalone instance, enable 7bit plugin |
| 148 |
:steps: |
| 149 |
1. Modify the entry for cn=7-bit check,cn=plugins,cn=config as : |
| 150 |
nsslapd-pluginarg0 : None |
| 151 |
nsslapd-pluginarg1 : uid |
| 152 |
nsslapd-pluginarg2 : None |
| 153 |
nsslapd-pluginarg3 : mail |
| 154 |
nsslapd-pluginarg5 : userpassword |
| 155 |
nsslapd-pluginarg7 : , |
| 156 |
nsslapd-pluginarg9 : dc=example,dc=com |
| 157 |
(Note: While modifying add 2 entries as None) |
| 158 |
|
| 159 |
2. Change the nsslapd-errorlog-level to 65536 |
| 160 |
3. Check missing agrs are fixed |
| 161 |
:expectedresults: |
| 162 |
1. Entries should be modified successfully |
| 163 |
2. Operation should be successful |
| 164 |
3. Operation should be successful |
| 165 |
""" |
| 166 |
|
| 167 |
log.info("Ticket 47431 - 3: Check missing args are fixed...") |
| 168 |
|
| 169 |
topology_st.standalone.modify_s(DN_7BITPLUGIN, |
| 170 |
[(ldap.MOD_DELETE, 'nsslapd-pluginarg0', None), |
| 171 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg1', b"uid"), |
| 172 |
(ldap.MOD_DELETE, 'nsslapd-pluginarg2', None), |
| 173 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg3', b"mail"), |
| 174 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg5', b"userpassword"), |
| 175 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg7', b","), |
| 176 |
(ldap.MOD_REPLACE, 'nsslapd-pluginarg9', ensure_bytes(SUFFIX))]) |
| 177 |
|
| 178 |
# PLUGIN LOG LEVEL |
| 179 |
topology_st.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'65536')]) |
| 180 |
|
| 181 |
topology_st.standalone.stop() |
| 182 |
os.system('mv %s %s.47431' % (topology_st.standalone.errlog, topology_st.standalone.errlog)) |
| 183 |
os.system('touch %s' % (topology_st.standalone.errlog)) |
| 184 |
topology_st.standalone.start() |
| 185 |
|
| 186 |
cmdline = 'egrep -i %s %s' % ("NS7bitAttr_Init", topology_st.standalone.errlog) |
| 187 |
p = os.popen(cmdline, "r") |
| 188 |
i = 0 |
| 189 |
while ATTRS[i]: |
| 190 |
line = p.readline() |
| 191 |
if line == "": |
| 192 |
break |
| 193 |
elif line.find(ATTRS[i]) >= 0: |
| 194 |
log.debug('%s was logged' % ATTRS[i]) |
| 195 |
else: |
| 196 |
log.error('%s was not logged.' % ATTRS[i]) |
| 197 |
assert False |
| 198 |
i = i + 1 |
| 199 |
|
| 200 |
log.info("Ticket 47431 - 3: done") |
| 201 |
log.info('Test complete') |
| 202 |
|
| 203 |
|
| 204 |
if __name__ == '__main__': |
| 205 |
# Run isolated |
| 206 |
# -s for DEBUG mode |
| 207 |
CURRENT_FILE = os.path.realpath(__file__) |
| 208 |
pytest.main("-s %s" % CURRENT_FILE) |