| 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 copy |
| 12 |
import os |
| 13 |
import ldap |
| 14 |
from lib389._constants import * |
| 15 |
from test389.topologies import topology_st as topo |
| 16 |
|
| 17 |
from lib389.replica import Replicas |
| 18 |
from lib389.agreement import Agreements |
| 19 |
from lib389.utils import ds_is_older |
| 20 |
from lib389 import Entry |
| 21 |
|
| 22 |
pytestmark = pytest.mark.tier1 |
| 23 |
|
| 24 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 25 |
if DEBUGGING: |
| 26 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 27 |
else: |
| 28 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 29 |
log = logging.getLogger(__name__) |
| 30 |
|
| 31 |
notnum = 'invalid' |
| 32 |
too_big = '9223372036854775807' |
| 33 |
overflow = '9999999999999999999999999999999999999999999999999999999999999999999' |
| 34 |
|
| 35 |
replica_dict = {'nsDS5ReplicaRoot': 'dc=example,dc=com', |
| 36 |
'nsDS5ReplicaType': '3', |
| 37 |
'nsDS5Flags': '1', |
| 38 |
'nsDS5ReplicaId': '65534', |
| 39 |
'nsds5ReplicaPurgeDelay': '604800', |
| 40 |
'nsDS5ReplicaBindDN': 'cn=u', |
| 41 |
'cn': 'replica'} |
| 42 |
|
| 43 |
|
| 44 |
agmt_dict = {'cn': 'test_agreement', |
| 45 |
'nsDS5ReplicaRoot': 'dc=example,dc=com', |
| 46 |
'nsDS5ReplicaHost': 'localhost.localdomain', |
| 47 |
'nsDS5ReplicaPort': '5555', |
| 48 |
'nsDS5ReplicaBindDN': 'uid=tester', |
| 49 |
'nsds5ReplicaCredentials': 'password', |
| 50 |
'nsDS5ReplicaTransportInfo': 'LDAP', |
| 51 |
'nsDS5ReplicaBindMethod': 'SIMPLE'} |
| 52 |
|
| 53 |
|
| 54 |
repl_add_attrs = [('nsDS5ReplicaType', '-1', '4', overflow, notnum, '1'), |
| 55 |
('nsDS5Flags', '-1', '2', overflow, notnum, '1'), |
| 56 |
('nsDS5ReplicaId', '0', '65536', overflow, notnum, '1'), |
| 57 |
('nsds5ReplicaPurgeDelay', '-2', too_big, overflow, notnum, '1'), |
| 58 |
('nsDS5ReplicaBindDnGroupCheckInterval', '-2', too_big, overflow, notnum, '1'), |
| 59 |
('nsds5ReplicaTombstonePurgeInterval', '-2', too_big, overflow, notnum, '1'), |
| 60 |
('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '1'), |
| 61 |
('nsds5ReplicaReleaseTimeout', '-1', too_big, overflow, notnum, '1'), |
| 62 |
('nsds5ReplicaBackoffMin', '0', too_big, overflow, notnum, '3'), |
| 63 |
('nsds5ReplicaBackoffMax', '0', too_big, overflow, notnum, '6'), |
| 64 |
('nsds5ReplicaKeepAliveUpdateInterval', '59', too_big, overflow, notnum, '60'),] |
| 65 |
|
| 66 |
repl_mod_attrs = [('nsDS5Flags', '-1', '2', overflow, notnum, '1'), |
| 67 |
('nsds5ReplicaPurgeDelay', '-2', too_big, overflow, notnum, '1'), |
| 68 |
('nsDS5ReplicaBindDnGroupCheckInterval', '-2', too_big, overflow, notnum, '1'), |
| 69 |
('nsds5ReplicaTombstonePurgeInterval', '-2', too_big, overflow, notnum, '1'), |
| 70 |
('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '1'), |
| 71 |
('nsds5ReplicaReleaseTimeout', '-1', too_big, overflow, notnum, '1'), |
| 72 |
('nsds5ReplicaBackoffMin', '0', too_big, overflow, notnum, '3'), |
| 73 |
('nsds5ReplicaBackoffMax', '0', too_big, overflow, notnum, '6'), |
| 74 |
('nsds5ReplicaKeepAliveUpdateInterval', '59', too_big, overflow, notnum, '60'),] |
| 75 |
|
| 76 |
agmt_attrs = [ |
| 77 |
('nsds5ReplicaPort', '0', '65535', overflow, notnum, '389'), |
| 78 |
('nsds5ReplicaTimeout', '-1', too_big, overflow, notnum, '6'), |
| 79 |
('nsds5ReplicaBusyWaitTime', '-1', too_big, overflow, notnum, '6'), |
| 80 |
('nsds5ReplicaSessionPauseTime', '-1', too_big, overflow, notnum, '6'), |
| 81 |
('nsds5ReplicaFlowControlWindow', '-1', too_big, overflow, notnum, '6'), |
| 82 |
('nsds5ReplicaFlowControlPause', '-1', too_big, overflow, notnum, '6'), |
| 83 |
('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '6') |
| 84 |
] |
| 85 |
|
| 86 |
def replica_reset(topo): |
| 87 |
"""Purge all existing replica details""" |
| 88 |
replicas = Replicas(topo.standalone) |
| 89 |
for r in replicas.list(): |
| 90 |
r.delete() |
| 91 |
|
| 92 |
def replica_setup(topo): |
| 93 |
"""Add a valid replica config entry to modify |
| 94 |
""" |
| 95 |
replicas = Replicas(topo.standalone) |
| 96 |
for r in replicas.list(): |
| 97 |
r.delete() |
| 98 |
return replicas.create(properties=replica_dict) |
| 99 |
|
| 100 |
def agmt_reset(topo): |
| 101 |
"""Purge all existing agreements for testing""" |
| 102 |
agmts = Agreements(topo.standalone) |
| 103 |
for a in agmts.list(): |
| 104 |
a.delete() |
| 105 |
|
| 106 |
def agmt_setup(topo): |
| 107 |
"""Add a valid replica config entry to modify |
| 108 |
""" |
| 109 |
# Reset the agreements too. |
| 110 |
replica = replica_setup(topo) |
| 111 |
agmts = Agreements(topo.standalone, basedn=replica.dn) |
| 112 |
for a in agmts.list(): |
| 113 |
a.delete() |
| 114 |
return agmts.create(properties=agmt_dict) |
| 115 |
|
| 116 |
def perform_invalid_create(many, properties, attr, value): |
| 117 |
my_properties = copy.deepcopy(properties) |
| 118 |
my_properties[attr] = value |
| 119 |
with pytest.raises(ldap.LDAPError) as ei: |
| 120 |
many.create(properties=my_properties) |
| 121 |
return ei.value |
| 122 |
|
| 123 |
def perform_invalid_modify(o, attr, value): |
| 124 |
with pytest.raises(ldap.LDAPError) as ei: |
| 125 |
o.replace(attr, value) |
| 126 |
return ei.value |
| 127 |
|
| 128 |
@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", repl_add_attrs) |
| 129 |
def test_replica_num_add(topo, attr, too_small, too_big, overflow, notnum, valid): |
| 130 |
"""Test all the number values you can set for a replica config entry |
| 131 |
|
| 132 |
:id: a8b47d4a-a089-4d70-8070-e6181209bf92 |
| 133 |
:parametrized: yes |
| 134 |
:setup: standalone instance |
| 135 |
:steps: |
| 136 |
1. Use a value that is too small |
| 137 |
2. Use a value that is too big |
| 138 |
3. Use a value that overflows the int |
| 139 |
4. Use a value with character value (not a number) |
| 140 |
5. Use a valid value |
| 141 |
:expectedresults: |
| 142 |
1. Add is rejected |
| 143 |
2. Add is rejected |
| 144 |
3. Add is rejected |
| 145 |
4. Add is rejected |
| 146 |
5. Add is allowed |
| 147 |
""" |
| 148 |
replica_reset(topo) |
| 149 |
|
| 150 |
replicas = Replicas(topo.standalone) |
| 151 |
|
| 152 |
# Test too small |
| 153 |
perform_invalid_create(replicas, replica_dict, attr, too_small) |
| 154 |
# Test too big |
| 155 |
perform_invalid_create(replicas, replica_dict, attr, too_big) |
| 156 |
# Test overflow |
| 157 |
perform_invalid_create(replicas, replica_dict, attr, overflow) |
| 158 |
# test not a number |
| 159 |
perform_invalid_create(replicas, replica_dict, attr, notnum) |
| 160 |
# Test valid value |
| 161 |
my_replica = copy.deepcopy(replica_dict) |
| 162 |
my_replica[attr] = valid |
| 163 |
replicas.create(properties=my_replica) |
| 164 |
|
| 165 |
@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", repl_mod_attrs) |
| 166 |
def test_replica_num_modify(topo, attr, too_small, too_big, overflow, notnum, valid): |
| 167 |
"""Test all the number values you can set for a replica config entry |
| 168 |
|
| 169 |
:id: a8b47d4a-a089-4d70-8070-e6181209bf93 |
| 170 |
:parametrized: yes |
| 171 |
:setup: standalone instance |
| 172 |
:steps: |
| 173 |
1. Replace a value that is too small |
| 174 |
2. Repalce a value that is too big |
| 175 |
3. Replace a value that overflows the int |
| 176 |
4. Replace a value with character value (not a number) |
| 177 |
5. Replace a vlue with a valid value |
| 178 |
:expectedresults: |
| 179 |
1. Value is rejected |
| 180 |
2. Value is rejected |
| 181 |
3. Value is rejected |
| 182 |
4. Value is rejected |
| 183 |
5. Value is allowed |
| 184 |
""" |
| 185 |
replica = replica_setup(topo) |
| 186 |
|
| 187 |
# Value too small |
| 188 |
perform_invalid_modify(replica, attr, too_small) |
| 189 |
# Value too big |
| 190 |
perform_invalid_modify(replica, attr, too_big) |
| 191 |
# Value overflow |
| 192 |
perform_invalid_modify(replica, attr, overflow) |
| 193 |
# Value not a number |
| 194 |
perform_invalid_modify(replica, attr, notnum) |
| 195 |
# Value is valid |
| 196 |
replica.replace(attr, valid) |
| 197 |
|
| 198 |
def test_replica_config_add_nonexistent_replicaroot(topo): |
| 199 |
"""Test that adding a replica config entry with a non existent |
| 200 |
nsds5replicaroot is correctly rejected. |
| 201 |
|
| 202 |
:id: 8eec4244-8ebb-40e1-b6f7-364b85a1862b |
| 203 |
:parametrized: no |
| 204 |
:setup: standalone instance |
| 205 |
:steps: |
| 206 |
1. Attempt to add a replica config entry with an invalid nsds5replicaroot |
| 207 |
2. Verify that no replica entry is created |
| 208 |
3. Verify the server is still running |
| 209 |
:expectedresults: |
| 210 |
1. The operation is rejected with UNWILLING_TO_PERFORM |
| 211 |
2. Success |
| 212 |
3. Success |
| 213 |
""" |
| 214 |
inst = topo.standalone |
| 215 |
dn = "cn=replica,cn=dc\\3Dexample\\2Cdc\\3Dcom,cn=mapping tree,cn=config" |
| 216 |
|
| 217 |
replica_reset(topo) |
| 218 |
|
| 219 |
entry = Entry((dn, { |
| 220 |
'objectclass': [ |
| 221 |
'top', |
| 222 |
'nsds5replica', |
| 223 |
'extensibleObject' |
| 224 |
], |
| 225 |
'cn': 'replica', |
| 226 |
'nsds5replicaroot': 'ou=idontexist', |
| 227 |
'nsds5replicaid': '65535', |
| 228 |
'nsds5replicatype': '2', |
| 229 |
'nsds5ReplicaBindDN': 'cn=replication manager,cn=config', |
| 230 |
'nsds5flags': '0', |
| 231 |
})) |
| 232 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM ): |
| 233 |
inst.add_s(entry) |
| 234 |
|
| 235 |
with pytest.raises(ldap.NO_SUCH_OBJECT): |
| 236 |
inst.getEntry(dn, ldap.SCOPE_BASE, '(objectClass=*)') |
| 237 |
|
| 238 |
assert inst.status() |
| 239 |
|
| 240 |
@pytest.mark.xfail(reason="Agreement validation current does not work.") |
| 241 |
@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", agmt_attrs) |
| 242 |
def test_agmt_num_add(topo, attr, too_small, too_big, overflow, notnum, valid): |
| 243 |
"""Test all the number values you can set for a replica config entry |
| 244 |
|
| 245 |
:id: a8b47d4a-a089-4d70-8070-e6181209bf94 |
| 246 |
:parametrized: yes |
| 247 |
:setup: standalone instance |
| 248 |
:steps: |
| 249 |
1. Use a value that is too small |
| 250 |
2. Use a value that is too big |
| 251 |
3. Use a value that overflows the int |
| 252 |
4. Use a value with character value (not a number) |
| 253 |
5. Use a valid value |
| 254 |
:expectedresults: |
| 255 |
1. Add is rejected |
| 256 |
2. Add is rejected |
| 257 |
3. Add is rejected |
| 258 |
4. Add is rejected |
| 259 |
5. Add is allowed |
| 260 |
""" |
| 261 |
|
| 262 |
agmt_reset(topo) |
| 263 |
replica = replica_setup(topo) |
| 264 |
|
| 265 |
agmts = Agreements(topo.standalone, basedn=replica.dn) |
| 266 |
|
| 267 |
# Test too small |
| 268 |
perform_invalid_create(agmts, agmt_dict, attr, too_small) |
| 269 |
# Test too big |
| 270 |
perform_invalid_create(agmts, agmt_dict, attr, too_big) |
| 271 |
# Test overflow |
| 272 |
perform_invalid_create(agmts, agmt_dict, attr, overflow) |
| 273 |
# test not a number |
| 274 |
perform_invalid_create(agmts, agmt_dict, attr, notnum) |
| 275 |
# Test valid value |
| 276 |
my_agmt = copy.deepcopy(agmt_dict) |
| 277 |
my_agmt[attr] = valid |
| 278 |
agmts.create(properties=my_agmt) |
| 279 |
|
| 280 |
|
| 281 |
@pytest.mark.xfail(reason="Agreement validation current does not work.") |
| 282 |
@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", agmt_attrs) |
| 283 |
def test_agmt_num_modify(topo, attr, too_small, too_big, overflow, notnum, valid): |
| 284 |
"""Test all the number values you can set for a replica config entry |
| 285 |
|
| 286 |
:id: a8b47d4a-a089-4d70-8070-e6181209bf95 |
| 287 |
:parametrized: yes |
| 288 |
:setup: standalone instance |
| 289 |
:steps: |
| 290 |
1. Replace a value that is too small |
| 291 |
2. Replace a value that is too big |
| 292 |
3. Replace a value that overflows the int |
| 293 |
4. Replace a value with character value (not a number) |
| 294 |
5. Replace a vlue with a valid value |
| 295 |
:expectedresults: |
| 296 |
1. Value is rejected |
| 297 |
2. Value is rejected |
| 298 |
3. Value is rejected |
| 299 |
4. Value is rejected |
| 300 |
5. Value is allowed |
| 301 |
""" |
| 302 |
|
| 303 |
agmt = agmt_setup(topo) |
| 304 |
|
| 305 |
# Value too small |
| 306 |
perform_invalid_modify(agmt, attr, too_small) |
| 307 |
# Value too big |
| 308 |
perform_invalid_modify(agmt, attr, too_big) |
| 309 |
# Value overflow |
| 310 |
perform_invalid_modify(agmt, attr, overflow) |
| 311 |
# Value not a number |
| 312 |
perform_invalid_modify(agmt, attr, notnum) |
| 313 |
# Value is valid |
| 314 |
agmt.replace(attr, valid) |
| 315 |
|
| 316 |
|
| 317 |
@pytest.mark.skipif(ds_is_older('1.4.1.4'), reason="Not implemented") |
| 318 |
def test_same_attr_yields_same_return_code(topo): |
| 319 |
"""Test that various operations with same incorrect attribute value yield same return code |
| 320 |
|
| 321 |
:id: 4bae88d7-0da8-4a71-b062-9d0ff4e472cf |
| 322 |
:setup: standalone instance |
| 323 |
:steps: |
| 324 |
1. Purge all replica details |
| 325 |
2. Perform an invalid create operation |
| 326 |
3. Setup replica |
| 327 |
4. Perform an invalid modify operation |
| 328 |
:expectedresults: |
| 329 |
1. Success |
| 330 |
2. Value is rejected |
| 331 |
3. Success |
| 332 |
4. Value is rejected |
| 333 |
""" |
| 334 |
attr = 'nsDS5ReplicaId' |
| 335 |
|
| 336 |
replica_reset(topo) |
| 337 |
replicas = Replicas(topo.standalone) |
| 338 |
e = perform_invalid_create(replicas, replica_dict, attr, too_big) |
| 339 |
assert type(e) is ldap.UNWILLING_TO_PERFORM |
| 340 |
|
| 341 |
replica = replica_setup(topo) |
| 342 |
e = perform_invalid_modify(replica, attr, too_big) |
| 343 |
assert type(e) is ldap.UNWILLING_TO_PERFORM |
| 344 |
|
| 345 |
|
| 346 |
if __name__ == '__main__': |
| 347 |
# Run isolated |
| 348 |
# -s for DEBUG mode |
| 349 |
CURRENT_FILE = os.path.realpath(__file__) |
| 350 |
pytest.main(["-s", CURRENT_FILE]) |