| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2024 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, os, re, time |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from lib389 import Entry |
| 13 |
from ldap import SCOPE_SUBTREE, ALREADY_EXISTS |
| 14 |
from ldap.controls import SimplePagedResultsControl |
| 15 |
from ldap.controls.sessiontrack import SessionTrackingControl, SESSION_TRACKING_CONTROL_OID |
| 16 |
from test389.topologies import topology_m2 as topo_m2 |
| 17 |
from ldap.extop import ExtendedRequest |
| 18 |
|
| 19 |
from lib389._constants import DEFAULT_SUFFIX, PW_DM, PLUGIN_MEMBER_OF |
| 20 |
from test389.topologies import topology_st |
| 21 |
from lib389.plugins import MemberOfPlugin |
| 22 |
|
| 23 |
from lib389.schema import Schema |
| 24 |
from lib389.idm.user import UserAccount, UserAccounts |
| 25 |
from lib389.idm.account import Accounts |
| 26 |
from lib389.idm.account import Anonymous |
| 27 |
|
| 28 |
SESSION_SOURCE_IP = '10.0.0.10' |
| 29 |
SESSION_SOURCE_NAME = 'host.example.com' |
| 30 |
SESSION_TRACKING_FORMAT_OID = SESSION_TRACKING_CONTROL_OID + ".1234" |
| 31 |
|
| 32 |
pytestmark = pytest.mark.tier0 |
| 33 |
|
| 34 |
def test_short_session_tracking_srch(topology_st, request): |
| 35 |
"""Verify that a short session_tracking string |
| 36 |
is added (not truncate) during a search |
| 37 |
|
| 38 |
:id: c9efc1cc-03c7-42b7-801c-440f7a11ee13 |
| 39 |
:customerscenario: False |
| 40 |
:setup: Standalone instance, default backend |
| 41 |
:steps: |
| 42 |
1. Do a search with a short session tracking string |
| 43 |
2. Restart the instance to flush the log |
| 44 |
3. Check the exact same string is present in the access log |
| 45 |
:expectedresults: |
| 46 |
1. Search should succeed |
| 47 |
2. success |
| 48 |
3. Log should contain one log with that session |
| 49 |
""" |
| 50 |
|
| 51 |
|
| 52 |
SESSION_TRACKING_IDENTIFIER = "SRCH short" |
| 53 |
st_ctrl = SessionTrackingControl( |
| 54 |
SESSION_SOURCE_IP, |
| 55 |
SESSION_SOURCE_NAME, |
| 56 |
SESSION_TRACKING_FORMAT_OID, |
| 57 |
SESSION_TRACKING_IDENTIFIER |
| 58 |
) |
| 59 |
|
| 60 |
topology_st.standalone.search_ext_s(DEFAULT_SUFFIX, |
| 61 |
ldap.SCOPE_SUBTREE, |
| 62 |
'(uid=*)', |
| 63 |
serverctrls=[st_ctrl]) |
| 64 |
topology_st.standalone.restart(timeout=10) |
| 65 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=101.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 66 |
assert len(access_log_lines) == 1 |
| 67 |
|
| 68 |
def fin(): |
| 69 |
pass |
| 70 |
|
| 71 |
request.addfinalizer(fin) |
| 72 |
|
| 73 |
def test_short_session_tracking_add(topology_st, request): |
| 74 |
"""Verify that a short session_tracking string |
| 75 |
is added (not truncate) during a add |
| 76 |
|
| 77 |
:id: 04afd3de-365e-485f-9e00-913d913af931 |
| 78 |
:customerscenario: False |
| 79 |
:setup: Standalone instance, default backend |
| 80 |
:steps: |
| 81 |
1. Add a test entry with a short session tracking |
| 82 |
2. Restart the instance to flush the log |
| 83 |
3. Check the exact same string is present in the access log |
| 84 |
:expectedresults: |
| 85 |
1. Add should succeed |
| 86 |
2. success |
| 87 |
3. Log should contain one log with that session |
| 88 |
""" |
| 89 |
|
| 90 |
|
| 91 |
SESSION_TRACKING_IDENTIFIER = "ADD short" |
| 92 |
st_ctrl = SessionTrackingControl( |
| 93 |
SESSION_SOURCE_IP, |
| 94 |
SESSION_SOURCE_NAME, |
| 95 |
SESSION_TRACKING_FORMAT_OID, |
| 96 |
SESSION_TRACKING_IDENTIFIER |
| 97 |
) |
| 98 |
TEST_DN = "cn=test_add," + DEFAULT_SUFFIX |
| 99 |
try: |
| 100 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 101 |
[ |
| 102 |
('objectClass', b'person'), |
| 103 |
('sn', b'test_add'), |
| 104 |
('cn', b'test_add'), |
| 105 |
('userPassword', b'test_add'), |
| 106 |
], |
| 107 |
serverctrls=[st_ctrl]) |
| 108 |
except ldap.LDAPError as e: |
| 109 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 110 |
assert False |
| 111 |
|
| 112 |
topology_st.standalone.restart(timeout=10) |
| 113 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 114 |
assert len(access_log_lines) == 1 |
| 115 |
|
| 116 |
def fin(): |
| 117 |
try: |
| 118 |
topology_st.standalone.delete_s(TEST_DN) |
| 119 |
except: |
| 120 |
pass |
| 121 |
|
| 122 |
request.addfinalizer(fin) |
| 123 |
|
| 124 |
def test_short_session_tracking_del(topology_st, request): |
| 125 |
"""Verify that a short session_tracking string |
| 126 |
is added (not truncate) during a del |
| 127 |
|
| 128 |
:id: a1391fbc-2107-4474-aaaf-088c393767a6 |
| 129 |
:customerscenario: False |
| 130 |
:setup: Standalone instance, default backend |
| 131 |
:steps: |
| 132 |
1. Add a test entry |
| 133 |
2. Delete the test entry with a short session tracking |
| 134 |
3. Restart the instance to flush the log |
| 135 |
4. Check the exact same string is not present in the access log for the ADD |
| 136 |
5. Check the exact same string is present in the access log for the DEL |
| 137 |
:expectedresults: |
| 138 |
1. Add should succeed |
| 139 |
2. DEL should succeed |
| 140 |
3. success |
| 141 |
4. Log should not contain a log with that session for the ADD |
| 142 |
5. Log should contain one log with that session for the DEL |
| 143 |
""" |
| 144 |
|
| 145 |
|
| 146 |
SESSION_TRACKING_IDENTIFIER = "DEL short" |
| 147 |
st_ctrl = SessionTrackingControl( |
| 148 |
SESSION_SOURCE_IP, |
| 149 |
SESSION_SOURCE_NAME, |
| 150 |
SESSION_TRACKING_FORMAT_OID, |
| 151 |
SESSION_TRACKING_IDENTIFIER |
| 152 |
) |
| 153 |
TEST_DN = "cn=test_del," + DEFAULT_SUFFIX |
| 154 |
try: |
| 155 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 156 |
[ |
| 157 |
('objectClass', b'person'), |
| 158 |
('sn', b'test_del'), |
| 159 |
('cn', b'test_del'), |
| 160 |
('userPassword', b'test_del'), |
| 161 |
]) |
| 162 |
topology_st.standalone.delete_ext_s(TEST_DN, |
| 163 |
serverctrls=[st_ctrl]) |
| 164 |
except ldap.LDAPError as e: |
| 165 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 166 |
assert False |
| 167 |
|
| 168 |
topology_st.standalone.restart(timeout=10) |
| 169 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 170 |
assert len(access_log_lines) == 0 |
| 171 |
|
| 172 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=107.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 173 |
assert len(access_log_lines) == 1 |
| 174 |
|
| 175 |
def fin(): |
| 176 |
try: |
| 177 |
topology_st.standalone.delete_s(TEST_DN) |
| 178 |
except: |
| 179 |
pass |
| 180 |
|
| 181 |
request.addfinalizer(fin) |
| 182 |
|
| 183 |
def test_short_session_tracking_mod(topology_st, request): |
| 184 |
"""Verify that a short session_tracking string |
| 185 |
is added (not truncate) during a MOD |
| 186 |
|
| 187 |
:id: 00c91efc-071d-4187-8185-6cca27b5bf63 |
| 188 |
:customerscenario: False |
| 189 |
:setup: Standalone instance, default backend |
| 190 |
:steps: |
| 191 |
1. Add a test entry |
| 192 |
2. Modify the test entry with a short session tracking |
| 193 |
3. Restart the instance to flush the log |
| 194 |
4. Check the exact same string is not present in the access log for the ADD |
| 195 |
5. Check the exact same string is present in the access log for the MOD |
| 196 |
:expectedresults: |
| 197 |
1. Add should succeed |
| 198 |
2. Mod should succeed |
| 199 |
3. success |
| 200 |
4. Log should not contain a log with that session for the ADD |
| 201 |
5. Log should contain one log with that session for the MOD |
| 202 |
""" |
| 203 |
|
| 204 |
|
| 205 |
SESSION_TRACKING_IDENTIFIER = "MOD short" |
| 206 |
st_ctrl = SessionTrackingControl( |
| 207 |
SESSION_SOURCE_IP, |
| 208 |
SESSION_SOURCE_NAME, |
| 209 |
SESSION_TRACKING_FORMAT_OID, |
| 210 |
SESSION_TRACKING_IDENTIFIER |
| 211 |
) |
| 212 |
TEST_DN = "cn=test_mod," + DEFAULT_SUFFIX |
| 213 |
try: |
| 214 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 215 |
[ |
| 216 |
('objectClass', b'person'), |
| 217 |
('sn', b'test_del'), |
| 218 |
('cn', b'test_del'), |
| 219 |
('userPassword', b'test_del'), |
| 220 |
]) |
| 221 |
topology_st.standalone.modify_ext_s(TEST_DN, |
| 222 |
[(ldap.MOD_REPLACE, 'sn', b'new_sn')], |
| 223 |
serverctrls=[st_ctrl]) |
| 224 |
except ldap.LDAPError as e: |
| 225 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 226 |
assert False |
| 227 |
|
| 228 |
topology_st.standalone.restart(timeout=10) |
| 229 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 230 |
assert len(access_log_lines) == 0 |
| 231 |
|
| 232 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=103.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 233 |
assert len(access_log_lines) == 1 |
| 234 |
|
| 235 |
def fin(): |
| 236 |
try: |
| 237 |
topology_st.standalone.delete_s(TEST_DN) |
| 238 |
except: |
| 239 |
pass |
| 240 |
|
| 241 |
request.addfinalizer(fin) |
| 242 |
|
| 243 |
def test_short_session_tracking_compare(topology_st, request): |
| 244 |
"""Verify that a short session_tracking string |
| 245 |
is added (not truncate) during a compare |
| 246 |
|
| 247 |
:id: 6f2090fd-a960-48e5-b7f1-04ddef4a85af |
| 248 |
:customerscenario: False |
| 249 |
:setup: Standalone instance, default backend |
| 250 |
:steps: |
| 251 |
1. Add a test entry |
| 252 |
2. compare an attribute with a short session tracking |
| 253 |
3. Restart the instance to flush the log |
| 254 |
4. Check the exact same string is not present in the access log for the ADD |
| 255 |
5. Check the exact same string is present in the access log for the COMPARE |
| 256 |
:expectedresults: |
| 257 |
1. Add should succeed |
| 258 |
2. Compare should succeed |
| 259 |
3. success |
| 260 |
4. Log should not contain a log with that session for the ADD |
| 261 |
5. Log should contain one log with that session for the COMPARE |
| 262 |
""" |
| 263 |
|
| 264 |
|
| 265 |
SESSION_TRACKING_IDENTIFIER = "COMPARE short" |
| 266 |
st_ctrl = SessionTrackingControl( |
| 267 |
SESSION_SOURCE_IP, |
| 268 |
SESSION_SOURCE_NAME, |
| 269 |
SESSION_TRACKING_FORMAT_OID, |
| 270 |
SESSION_TRACKING_IDENTIFIER |
| 271 |
) |
| 272 |
TEST_DN = "cn=test_compare," + DEFAULT_SUFFIX |
| 273 |
try: |
| 274 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 275 |
[ |
| 276 |
('objectClass', b'person'), |
| 277 |
('sn', b'test_compare'), |
| 278 |
('cn', b'test_compare'), |
| 279 |
('userPassword', b'test_compare'), |
| 280 |
]) |
| 281 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_compare', serverctrls=[st_ctrl]) |
| 282 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_fail_compare', serverctrls=[st_ctrl]) |
| 283 |
except ldap.LDAPError as e: |
| 284 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 285 |
assert False |
| 286 |
|
| 287 |
topology_st.standalone.restart(timeout=10) |
| 288 |
|
| 289 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 290 |
assert len(access_log_lines) == 0 |
| 291 |
|
| 292 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=6 tag=111.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 293 |
assert len(access_log_lines) == 1 |
| 294 |
|
| 295 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=5 tag=111.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 296 |
assert len(access_log_lines) == 1 |
| 297 |
|
| 298 |
def fin(): |
| 299 |
try: |
| 300 |
topology_st.standalone.delete_s(TEST_DN) |
| 301 |
except: |
| 302 |
pass |
| 303 |
|
| 304 |
request.addfinalizer(fin) |
| 305 |
|
| 306 |
def test_short_session_tracking_abandon(topology_st, request): |
| 307 |
"""Verify that a short session_tracking string |
| 308 |
is added (not truncate) during an abandon |
| 309 |
|
| 310 |
:id: 58f54ada-e05c-411b-a1c6-8b19fd99843c |
| 311 |
:customerscenario: False |
| 312 |
:setup: Standalone instance, default backend |
| 313 |
:steps: |
| 314 |
1. Add 10 test entries |
| 315 |
2. Launch Page Search with a window of 3 |
| 316 |
3. Abandon the Page Search with a short session tracking |
| 317 |
4. Restart the instance to flush the log |
| 318 |
5. Check the exact same string is not present in the access log for the ADD |
| 319 |
6. Check the exact same string is present in the access log for the ABANDON |
| 320 |
:expectedresults: |
| 321 |
1. Add should succeed |
| 322 |
2. success |
| 323 |
3. success |
| 324 |
4. success |
| 325 |
5. Log should not contain log with that session for the ADDs |
| 326 |
6. Log should contain one log with that session for the abandon |
| 327 |
""" |
| 328 |
|
| 329 |
SESSION_TRACKING_IDENTIFIER = "ABANDON short" |
| 330 |
st_ctrl = SessionTrackingControl( |
| 331 |
SESSION_SOURCE_IP, |
| 332 |
SESSION_SOURCE_NAME, |
| 333 |
SESSION_TRACKING_FORMAT_OID, |
| 334 |
SESSION_TRACKING_IDENTIFIER |
| 335 |
) |
| 336 |
|
| 337 |
# provision more entries than the page search will fetch |
| 338 |
entries = [] |
| 339 |
for i in range(10): |
| 340 |
TEST_DN = "cn=test_abandon_%d,%s" % (i, DEFAULT_SUFFIX) |
| 341 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 342 |
[ |
| 343 |
('objectClass', b'person'), |
| 344 |
('sn', b'test_abandon'), |
| 345 |
('cn', b'test_abandon_%d' % i), |
| 346 |
('userPassword', b'test_abandon'), |
| 347 |
]) |
| 348 |
entries.append(TEST_DN) |
| 349 |
|
| 350 |
# run a page search (with the session) using a small window. So we can abandon it. |
| 351 |
req_ctrl = SimplePagedResultsControl(True, size=3, cookie='') |
| 352 |
msgid = topology_st.standalone.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, r'(objectclass=*)', ['cn'], serverctrls=[req_ctrl]) |
| 353 |
time.sleep(1) |
| 354 |
topology_st.standalone.abandon_ext(msgid, serverctrls=[st_ctrl]) |
| 355 |
|
| 356 |
|
| 357 |
topology_st.standalone.restart(timeout=10) |
| 358 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 359 |
assert len(access_log_lines) == 0 |
| 360 |
|
| 361 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*ABANDON.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 362 |
assert len(access_log_lines) == 1 |
| 363 |
|
| 364 |
def fin(): |
| 365 |
for ent in entries: |
| 366 |
try: |
| 367 |
topology_st.standalone.delete_s(ent) |
| 368 |
except: |
| 369 |
pass |
| 370 |
|
| 371 |
request.addfinalizer(fin) |
| 372 |
|
| 373 |
def test_short_session_tracking_extop(topology_st, request): |
| 374 |
"""Verify that a short session_tracking string |
| 375 |
is added (not truncate) during an extended operation |
| 376 |
|
| 377 |
:id: 65c2d014-d798-46f3-8168-b6f56b43d069 |
| 378 |
:customerscenario: False |
| 379 |
:setup: Standalone instance, default backend |
| 380 |
:steps: |
| 381 |
1. run whoami extop |
| 382 |
2. Check the exact same string is present in the access log for the EXTOP |
| 383 |
:expectedresults: |
| 384 |
1. success |
| 385 |
2. Log should contain one log with that session for the EXTOP |
| 386 |
""" |
| 387 |
SESSION_TRACKING_IDENTIFIER = "Extop short" |
| 388 |
st_ctrl = SessionTrackingControl( |
| 389 |
SESSION_SOURCE_IP, |
| 390 |
SESSION_SOURCE_NAME, |
| 391 |
SESSION_TRACKING_FORMAT_OID, |
| 392 |
SESSION_TRACKING_IDENTIFIER |
| 393 |
) |
| 394 |
|
| 395 |
extop = ExtendedRequest(requestName = '1.3.6.1.4.1.4203.1.11.3', requestValue=None) |
| 396 |
(oid_response, res) = topology_st.standalone.extop_s(extop, serverctrls=[st_ctrl]) |
| 397 |
|
| 398 |
topology_st.standalone.restart(timeout=10) |
| 399 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=120.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 400 |
assert len(access_log_lines) == 1 |
| 401 |
|
| 402 |
def fin(): |
| 403 |
pass |
| 404 |
|
| 405 |
request.addfinalizer(fin) |
| 406 |
|
| 407 |
def test_exact_max_lgth_session_tracking_srch(topology_st, request): |
| 408 |
"""Verify that a exact max length session_tracking string |
| 409 |
is added (not truncate) during a search |
| 410 |
|
| 411 |
:id: 2c8c86f9-4896-4ccc-a727-6a4033f6f44a |
| 412 |
:customerscenario: False |
| 413 |
:setup: Standalone instance, default backend |
| 414 |
:steps: |
| 415 |
1. Do a search with a exact max length session tracking string |
| 416 |
2. Restart the instance to flush the log |
| 417 |
3. Check the exact same string is present in the access log (without '.') |
| 418 |
:expectedresults: |
| 419 |
1. Search should succeed |
| 420 |
2. success |
| 421 |
3. Log should contain one log with that session |
| 422 |
""" |
| 423 |
|
| 424 |
|
| 425 |
SESSION_TRACKING_IDENTIFIER = "SRCH long ---->" |
| 426 |
st_ctrl = SessionTrackingControl( |
| 427 |
SESSION_SOURCE_IP, |
| 428 |
SESSION_SOURCE_NAME, |
| 429 |
SESSION_TRACKING_FORMAT_OID, |
| 430 |
SESSION_TRACKING_IDENTIFIER |
| 431 |
) |
| 432 |
|
| 433 |
topology_st.standalone.search_ext_s(DEFAULT_SUFFIX, |
| 434 |
ldap.SCOPE_SUBTREE, |
| 435 |
'(uid=*)', |
| 436 |
serverctrls=[st_ctrl]) |
| 437 |
topology_st.standalone.restart(timeout=10) |
| 438 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=101.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 439 |
assert len(access_log_lines) == 1 |
| 440 |
|
| 441 |
def fin(): |
| 442 |
pass |
| 443 |
|
| 444 |
request.addfinalizer(fin) |
| 445 |
|
| 446 |
def test_exact_max_lgth_session_tracking_add(topology_st, request): |
| 447 |
"""Verify that a exact max length of session_tracking string |
| 448 |
is added (not truncate) during a add |
| 449 |
|
| 450 |
:id: 41c0b4f3-5e75-404b-98af-98cc98b742c7 |
| 451 |
:customerscenario: False |
| 452 |
:setup: Standalone instance, default backend |
| 453 |
:steps: |
| 454 |
1. Add a test entry with a exact max lenght (15) session tracking |
| 455 |
2. Restart the instance to flush the log |
| 456 |
3. Check the exact same string is present in the access log |
| 457 |
:expectedresults: |
| 458 |
1. Add should succeed |
| 459 |
2. success |
| 460 |
3. Log should contain one log with that session |
| 461 |
""" |
| 462 |
|
| 463 |
|
| 464 |
SESSION_TRACKING_IDENTIFIER = "ADD long ----->" |
| 465 |
st_ctrl = SessionTrackingControl( |
| 466 |
SESSION_SOURCE_IP, |
| 467 |
SESSION_SOURCE_NAME, |
| 468 |
SESSION_TRACKING_FORMAT_OID, |
| 469 |
SESSION_TRACKING_IDENTIFIER |
| 470 |
) |
| 471 |
TEST_DN = "cn=test_add," + DEFAULT_SUFFIX |
| 472 |
try: |
| 473 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 474 |
[ |
| 475 |
('objectClass', b'person'), |
| 476 |
('sn', b'test_add'), |
| 477 |
('cn', b'test_add'), |
| 478 |
('userPassword', b'test_add'), |
| 479 |
], |
| 480 |
serverctrls=[st_ctrl]) |
| 481 |
except ldap.LDAPError as e: |
| 482 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 483 |
assert False |
| 484 |
|
| 485 |
topology_st.standalone.restart(timeout=10) |
| 486 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 487 |
assert len(access_log_lines) == 1 |
| 488 |
|
| 489 |
def fin(): |
| 490 |
try: |
| 491 |
topology_st.standalone.delete_s(TEST_DN) |
| 492 |
except: |
| 493 |
pass |
| 494 |
|
| 495 |
request.addfinalizer(fin) |
| 496 |
|
| 497 |
def test_exact_max_lgth_session_tracking_del(topology_st, request): |
| 498 |
"""Verify that a exact max lgth session_tracking string |
| 499 |
is added (not truncate) during a del |
| 500 |
|
| 501 |
:id: b8dca6c9-7cd4-4950-bcb5-7e9e6bb9202f |
| 502 |
:customerscenario: False |
| 503 |
:setup: Standalone instance, default backend |
| 504 |
:steps: |
| 505 |
1. Add a test entry |
| 506 |
2. Delete the test entry with a exact max length (15) session tracking |
| 507 |
3. Restart the instance to flush the log |
| 508 |
4. Check the exact same string is not present in the access log for the ADD |
| 509 |
5. Check the exact same string is present in the access log for the DEL |
| 510 |
:expectedresults: |
| 511 |
1. Add should succeed |
| 512 |
2. DEL should succeed |
| 513 |
3. success |
| 514 |
4. Log should not contain a log with that session for the ADD |
| 515 |
5. Log should contain one log with that session for the DEL |
| 516 |
""" |
| 517 |
|
| 518 |
|
| 519 |
SESSION_TRACKING_IDENTIFIER = "DEL long ----->" |
| 520 |
st_ctrl = SessionTrackingControl( |
| 521 |
SESSION_SOURCE_IP, |
| 522 |
SESSION_SOURCE_NAME, |
| 523 |
SESSION_TRACKING_FORMAT_OID, |
| 524 |
SESSION_TRACKING_IDENTIFIER |
| 525 |
) |
| 526 |
TEST_DN = "cn=test_del," + DEFAULT_SUFFIX |
| 527 |
try: |
| 528 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 529 |
[ |
| 530 |
('objectClass', b'person'), |
| 531 |
('sn', b'test_del'), |
| 532 |
('cn', b'test_del'), |
| 533 |
('userPassword', b'test_del'), |
| 534 |
]) |
| 535 |
topology_st.standalone.delete_ext_s(TEST_DN, |
| 536 |
serverctrls=[st_ctrl]) |
| 537 |
except ldap.LDAPError as e: |
| 538 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 539 |
assert False |
| 540 |
|
| 541 |
topology_st.standalone.restart(timeout=10) |
| 542 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 543 |
assert len(access_log_lines) == 0 |
| 544 |
|
| 545 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=107.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 546 |
assert len(access_log_lines) == 1 |
| 547 |
|
| 548 |
def fin(): |
| 549 |
try: |
| 550 |
topology_st.standalone.delete_s(TEST_DN) |
| 551 |
except: |
| 552 |
pass |
| 553 |
|
| 554 |
request.addfinalizer(fin) |
| 555 |
|
| 556 |
def test_exact_max_lgth_session_tracking_mod(topology_st, request): |
| 557 |
"""Verify that an exact max length session_tracking string |
| 558 |
is added (not truncate) during a MOD |
| 559 |
|
| 560 |
:id: 3bd1205f-a035-48a7-94c2-f8774e24ae91 |
| 561 |
:customerscenario: False |
| 562 |
:setup: Standalone instance, default backend |
| 563 |
:steps: |
| 564 |
1. Add a test entry |
| 565 |
2. Modify the test entry with an exact max length (15) session tracking |
| 566 |
3. Restart the instance to flush the log |
| 567 |
4. Check the exact same string is not present in the access log for the ADD |
| 568 |
5. Check the exact same string is present in the access log for the MOD |
| 569 |
:expectedresults: |
| 570 |
1. Add should succeed |
| 571 |
2. Mod should succeed |
| 572 |
3. success |
| 573 |
4. Log should not contain a log with that session for the ADD |
| 574 |
5. Log should contain one log with that session for the MOD |
| 575 |
""" |
| 576 |
|
| 577 |
|
| 578 |
SESSION_TRACKING_IDENTIFIER = "MOD long ----->" |
| 579 |
st_ctrl = SessionTrackingControl( |
| 580 |
SESSION_SOURCE_IP, |
| 581 |
SESSION_SOURCE_NAME, |
| 582 |
SESSION_TRACKING_FORMAT_OID, |
| 583 |
SESSION_TRACKING_IDENTIFIER |
| 584 |
) |
| 585 |
TEST_DN = "cn=test_mod," + DEFAULT_SUFFIX |
| 586 |
try: |
| 587 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 588 |
[ |
| 589 |
('objectClass', b'person'), |
| 590 |
('sn', b'test_del'), |
| 591 |
('cn', b'test_del'), |
| 592 |
('userPassword', b'test_del'), |
| 593 |
]) |
| 594 |
topology_st.standalone.modify_ext_s(TEST_DN, |
| 595 |
[(ldap.MOD_REPLACE, 'sn', b'new_sn')], |
| 596 |
serverctrls=[st_ctrl]) |
| 597 |
except ldap.LDAPError as e: |
| 598 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 599 |
assert False |
| 600 |
|
| 601 |
topology_st.standalone.restart(timeout=10) |
| 602 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 603 |
assert len(access_log_lines) == 0 |
| 604 |
|
| 605 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=103.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 606 |
assert len(access_log_lines) == 1 |
| 607 |
|
| 608 |
def fin(): |
| 609 |
try: |
| 610 |
topology_st.standalone.delete_s(TEST_DN) |
| 611 |
except: |
| 612 |
pass |
| 613 |
|
| 614 |
request.addfinalizer(fin) |
| 615 |
|
| 616 |
def test_exact_max_lgth_session_tracking_compare(topology_st, request): |
| 617 |
"""Verify that an exact max length session_tracking string |
| 618 |
is added (not truncate) during a compare |
| 619 |
|
| 620 |
:id: a6c8ad60-7edb-4ee4-b0e3-06727870687c |
| 621 |
:customerscenario: False |
| 622 |
:setup: Standalone instance, default backend |
| 623 |
:steps: |
| 624 |
1. Add a test entry |
| 625 |
2. compare an attribute with an exact max length session tracking |
| 626 |
3. Restart the instance to flush the log |
| 627 |
4. Check the exact same string is not present in the access log for the ADD |
| 628 |
5. Check the exact same string is present in the access log for the COMPARE |
| 629 |
:expectedresults: |
| 630 |
1. Add should succeed |
| 631 |
2. Compare should succeed |
| 632 |
3. success |
| 633 |
4. Log should not contain a log with that session for the ADD |
| 634 |
5. Log should contain one log with that session for the COMPARE |
| 635 |
""" |
| 636 |
|
| 637 |
|
| 638 |
SESSION_TRACKING_IDENTIFIER = "COMPARE long ->" |
| 639 |
st_ctrl = SessionTrackingControl( |
| 640 |
SESSION_SOURCE_IP, |
| 641 |
SESSION_SOURCE_NAME, |
| 642 |
SESSION_TRACKING_FORMAT_OID, |
| 643 |
SESSION_TRACKING_IDENTIFIER |
| 644 |
) |
| 645 |
TEST_DN = "cn=test_compare," + DEFAULT_SUFFIX |
| 646 |
try: |
| 647 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 648 |
[ |
| 649 |
('objectClass', b'person'), |
| 650 |
('sn', b'test_compare'), |
| 651 |
('cn', b'test_compare'), |
| 652 |
('userPassword', b'test_compare'), |
| 653 |
]) |
| 654 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_compare', serverctrls=[st_ctrl]) |
| 655 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_fail_compare', serverctrls=[st_ctrl]) |
| 656 |
except ldap.LDAPError as e: |
| 657 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 658 |
assert False |
| 659 |
|
| 660 |
topology_st.standalone.restart(timeout=10) |
| 661 |
|
| 662 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 663 |
assert len(access_log_lines) == 0 |
| 664 |
|
| 665 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=6 tag=111.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 666 |
assert len(access_log_lines) == 1 |
| 667 |
|
| 668 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=5 tag=111.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 669 |
assert len(access_log_lines) == 1 |
| 670 |
|
| 671 |
def fin(): |
| 672 |
try: |
| 673 |
topology_st.standalone.delete_s(TEST_DN) |
| 674 |
except: |
| 675 |
pass |
| 676 |
|
| 677 |
request.addfinalizer(fin) |
| 678 |
|
| 679 |
def test_exact_max_lgth_session_tracking_abandon(topology_st, request): |
| 680 |
"""Verify that an exact max length session_tracking string |
| 681 |
is added (not truncate) during an abandon |
| 682 |
|
| 683 |
:id: 708554b9-8403-411c-90b5-d9ecc2d3830f |
| 684 |
:customerscenario: False |
| 685 |
:setup: Standalone instance, default backend |
| 686 |
:steps: |
| 687 |
1. Add 10 test entries |
| 688 |
2. Launch Page Search with a window of 3 |
| 689 |
3. Abandon the Page Search with an exact max length session tracking |
| 690 |
4. Restart the instance to flush the log |
| 691 |
5. Check the exact same string is not present in the access log for the ADD |
| 692 |
6. Check the exact same string is present in the access log for the ABANDON |
| 693 |
:expectedresults: |
| 694 |
1. Add should succeed |
| 695 |
2. success |
| 696 |
3. success |
| 697 |
4. success |
| 698 |
5. Log should not contain log with that session for the ADDs |
| 699 |
6. Log should contain one log with that session for the abandon |
| 700 |
""" |
| 701 |
|
| 702 |
SESSION_TRACKING_IDENTIFIER = "ABANDON long ->" |
| 703 |
st_ctrl = SessionTrackingControl( |
| 704 |
SESSION_SOURCE_IP, |
| 705 |
SESSION_SOURCE_NAME, |
| 706 |
SESSION_TRACKING_FORMAT_OID, |
| 707 |
SESSION_TRACKING_IDENTIFIER |
| 708 |
) |
| 709 |
|
| 710 |
# provision more entries than the page search will fetch |
| 711 |
entries = [] |
| 712 |
for i in range(10): |
| 713 |
TEST_DN = "cn=test_abandon_%d,%s" % (i, DEFAULT_SUFFIX) |
| 714 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 715 |
[ |
| 716 |
('objectClass', b'person'), |
| 717 |
('sn', b'test_abandon'), |
| 718 |
('cn', b'test_abandon_%d' % i), |
| 719 |
('userPassword', b'test_abandon'), |
| 720 |
]) |
| 721 |
entries.append(TEST_DN) |
| 722 |
|
| 723 |
# run a page search (with the session) using a small window. So we can abandon it. |
| 724 |
req_ctrl = SimplePagedResultsControl(True, size=3, cookie='') |
| 725 |
msgid = topology_st.standalone.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, r'(objectclass=*)', ['cn'], serverctrls=[req_ctrl]) |
| 726 |
time.sleep(1) |
| 727 |
topology_st.standalone.abandon_ext(msgid, serverctrls=[st_ctrl]) |
| 728 |
|
| 729 |
|
| 730 |
topology_st.standalone.restart(timeout=10) |
| 731 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 732 |
assert len(access_log_lines) == 0 |
| 733 |
|
| 734 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*ABANDON.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 735 |
assert len(access_log_lines) == 1 |
| 736 |
|
| 737 |
def fin(): |
| 738 |
for ent in entries: |
| 739 |
try: |
| 740 |
topology_st.standalone.delete_s(ent) |
| 741 |
except: |
| 742 |
pass |
| 743 |
|
| 744 |
request.addfinalizer(fin) |
| 745 |
|
| 746 |
def test_exact_max_lgth_session_tracking_extop(topology_st, request): |
| 747 |
"""Verify that an exact max length session_tracking string |
| 748 |
is added (not truncate) during an extended operation |
| 749 |
|
| 750 |
:id: 078d33c4-9124-4766-966e-2e3eebdf0e18 |
| 751 |
:customerscenario: False |
| 752 |
:setup: Standalone instance, default backend |
| 753 |
:steps: |
| 754 |
1. run whoami extop |
| 755 |
2. Check the exact same string (max length 15) |
| 756 |
is present in the access log for the EXTOP |
| 757 |
:expectedresults: |
| 758 |
1. success |
| 759 |
2. Log should contain one log with that session for the EXTOP |
| 760 |
""" |
| 761 |
SESSION_TRACKING_IDENTIFIER = "Extop long --->" |
| 762 |
st_ctrl = SessionTrackingControl( |
| 763 |
SESSION_SOURCE_IP, |
| 764 |
SESSION_SOURCE_NAME, |
| 765 |
SESSION_TRACKING_FORMAT_OID, |
| 766 |
SESSION_TRACKING_IDENTIFIER |
| 767 |
) |
| 768 |
|
| 769 |
extop = ExtendedRequest(requestName = '1.3.6.1.4.1.4203.1.11.3', requestValue=None) |
| 770 |
(oid_response, res) = topology_st.standalone.extop_s(extop, serverctrls=[st_ctrl]) |
| 771 |
|
| 772 |
topology_st.standalone.restart(timeout=10) |
| 773 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=120.* sid="%s".*' % SESSION_TRACKING_IDENTIFIER) |
| 774 |
assert len(access_log_lines) == 1 |
| 775 |
|
| 776 |
def fin(): |
| 777 |
pass |
| 778 |
|
| 779 |
request.addfinalizer(fin) |
| 780 |
|
| 781 |
def test_long_session_tracking_srch(topology_st, request): |
| 782 |
"""Verify that a long session_tracking string |
| 783 |
is added (truncate) during a search |
| 784 |
|
| 785 |
:id: 56118d13-c0b1-401f-aaa4-6dc233156e36 |
| 786 |
:customerscenario: False |
| 787 |
:setup: Standalone instance, default backend |
| 788 |
:steps: |
| 789 |
1. Do a search with a long session tracking string |
| 790 |
2. Restart the instance to flush the log |
| 791 |
3. Check the exact same string is present in the access log (with '.') |
| 792 |
:expectedresults: |
| 793 |
1. Search should succeed |
| 794 |
2. success |
| 795 |
3. Log should contain one log with that session |
| 796 |
""" |
| 797 |
|
| 798 |
|
| 799 |
SESSION_TRACKING_IDENTIFIER_MAX = "SRCH long ---->" |
| 800 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 801 |
st_ctrl = SessionTrackingControl( |
| 802 |
SESSION_SOURCE_IP, |
| 803 |
SESSION_SOURCE_NAME, |
| 804 |
SESSION_TRACKING_FORMAT_OID, |
| 805 |
SESSION_TRACKING_IDENTIFIER |
| 806 |
) |
| 807 |
|
| 808 |
topology_st.standalone.search_ext_s(DEFAULT_SUFFIX, |
| 809 |
ldap.SCOPE_SUBTREE, |
| 810 |
'(uid=*)', |
| 811 |
serverctrls=[st_ctrl]) |
| 812 |
topology_st.standalone.restart(timeout=10) |
| 813 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=101.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 814 |
assert len(access_log_lines) == 1 |
| 815 |
|
| 816 |
def fin(): |
| 817 |
pass |
| 818 |
|
| 819 |
request.addfinalizer(fin) |
| 820 |
|
| 821 |
def test_long_session_tracking_add(topology_st, request): |
| 822 |
"""Verify that a long session_tracking string |
| 823 |
is added (truncate) during a add |
| 824 |
|
| 825 |
:id: ac97bc6b-f2c5-41e2-9ab6-df05afb2757c |
| 826 |
:customerscenario: False |
| 827 |
:setup: Standalone instance, default backend |
| 828 |
:steps: |
| 829 |
1. Add a test entry with a long session tracking |
| 830 |
2. Restart the instance to flush the log |
| 831 |
3. Check the exact same string is present in the access log (with '.') |
| 832 |
:expectedresults: |
| 833 |
1. Add should succeed |
| 834 |
2. success |
| 835 |
3. Log should contain one log with that session |
| 836 |
""" |
| 837 |
|
| 838 |
|
| 839 |
SESSION_TRACKING_IDENTIFIER_MAX = "ADD long ----->" |
| 840 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 841 |
st_ctrl = SessionTrackingControl( |
| 842 |
SESSION_SOURCE_IP, |
| 843 |
SESSION_SOURCE_NAME, |
| 844 |
SESSION_TRACKING_FORMAT_OID, |
| 845 |
SESSION_TRACKING_IDENTIFIER |
| 846 |
) |
| 847 |
TEST_DN = "cn=test_add," + DEFAULT_SUFFIX |
| 848 |
try: |
| 849 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 850 |
[ |
| 851 |
('objectClass', b'person'), |
| 852 |
('sn', b'test_add'), |
| 853 |
('cn', b'test_add'), |
| 854 |
('userPassword', b'test_add'), |
| 855 |
], |
| 856 |
serverctrls=[st_ctrl]) |
| 857 |
except ldap.LDAPError as e: |
| 858 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 859 |
assert False |
| 860 |
|
| 861 |
topology_st.standalone.restart(timeout=10) |
| 862 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 863 |
assert len(access_log_lines) == 1 |
| 864 |
|
| 865 |
def fin(): |
| 866 |
try: |
| 867 |
topology_st.standalone.delete_s(TEST_DN) |
| 868 |
except: |
| 869 |
pass |
| 870 |
|
| 871 |
request.addfinalizer(fin) |
| 872 |
|
| 873 |
def test_long_session_tracking_del(topology_st, request): |
| 874 |
"""Verify that a long session_tracking string |
| 875 |
is added (truncate) during a del |
| 876 |
|
| 877 |
:id: 283152b8-ba6b-4153-b2de-17070911bf18 |
| 878 |
:customerscenario: False |
| 879 |
:setup: Standalone instance, default backend |
| 880 |
:steps: |
| 881 |
1. Add a test entry |
| 882 |
2. Delete the test entry with a long session tracking |
| 883 |
3. Restart the instance to flush the log |
| 884 |
4. Check the exact same string is not present in the access log for the ADD |
| 885 |
5. Check the exact same string is present in the access log for the DEL (with '.') |
| 886 |
:expectedresults: |
| 887 |
1. Add should succeed |
| 888 |
2. DEL should succeed |
| 889 |
3. success |
| 890 |
4. Log should not contain a log with that session for the ADD |
| 891 |
5. Log should contain one log with that session for the DEL |
| 892 |
""" |
| 893 |
|
| 894 |
|
| 895 |
SESSION_TRACKING_IDENTIFIER_MAX = "DEL long ----->" |
| 896 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 897 |
st_ctrl = SessionTrackingControl( |
| 898 |
SESSION_SOURCE_IP, |
| 899 |
SESSION_SOURCE_NAME, |
| 900 |
SESSION_TRACKING_FORMAT_OID, |
| 901 |
SESSION_TRACKING_IDENTIFIER |
| 902 |
) |
| 903 |
TEST_DN = "cn=test_del," + DEFAULT_SUFFIX |
| 904 |
try: |
| 905 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 906 |
[ |
| 907 |
('objectClass', b'person'), |
| 908 |
('sn', b'test_del'), |
| 909 |
('cn', b'test_del'), |
| 910 |
('userPassword', b'test_del'), |
| 911 |
]) |
| 912 |
topology_st.standalone.delete_ext_s(TEST_DN, |
| 913 |
serverctrls=[st_ctrl]) |
| 914 |
except ldap.LDAPError as e: |
| 915 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 916 |
assert False |
| 917 |
|
| 918 |
topology_st.standalone.restart(timeout=10) |
| 919 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 920 |
assert len(access_log_lines) == 0 |
| 921 |
|
| 922 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=107.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 923 |
assert len(access_log_lines) == 1 |
| 924 |
|
| 925 |
def fin(): |
| 926 |
try: |
| 927 |
topology_st.standalone.delete_s(TEST_DN) |
| 928 |
except: |
| 929 |
pass |
| 930 |
|
| 931 |
request.addfinalizer(fin) |
| 932 |
|
| 933 |
def test_long_session_tracking_mod(topology_st, request): |
| 934 |
"""Verify that a long session_tracking string |
| 935 |
is added (truncate) during a MOD |
| 936 |
|
| 937 |
:id: 6bfcca4b-40b4-4288-9b77-cfa0d4f15c14 |
| 938 |
:customerscenario: False |
| 939 |
:setup: Standalone instance, default backend |
| 940 |
:steps: |
| 941 |
1. Add a test entry |
| 942 |
2. Modify the test entry with an long session tracking |
| 943 |
3. Restart the instance to flush the log |
| 944 |
4. Check the exact same string is not present in the access log for the ADD |
| 945 |
5. Check the exact same string is present in the access log for the MOD (with '.') |
| 946 |
:expectedresults: |
| 947 |
1. Add should succeed |
| 948 |
2. Mod should succeed |
| 949 |
3. success |
| 950 |
4. Log should not contain a log with that session for the ADD |
| 951 |
5. Log should contain one log with that session for the MOD |
| 952 |
""" |
| 953 |
|
| 954 |
|
| 955 |
SESSION_TRACKING_IDENTIFIER_MAX = "MOD long ----->" |
| 956 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 957 |
st_ctrl = SessionTrackingControl( |
| 958 |
SESSION_SOURCE_IP, |
| 959 |
SESSION_SOURCE_NAME, |
| 960 |
SESSION_TRACKING_FORMAT_OID, |
| 961 |
SESSION_TRACKING_IDENTIFIER |
| 962 |
) |
| 963 |
TEST_DN = "cn=test_mod," + DEFAULT_SUFFIX |
| 964 |
try: |
| 965 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 966 |
[ |
| 967 |
('objectClass', b'person'), |
| 968 |
('sn', b'test_del'), |
| 969 |
('cn', b'test_del'), |
| 970 |
('userPassword', b'test_del'), |
| 971 |
]) |
| 972 |
topology_st.standalone.modify_ext_s(TEST_DN, |
| 973 |
[(ldap.MOD_REPLACE, 'sn', b'new_sn')], |
| 974 |
serverctrls=[st_ctrl]) |
| 975 |
except ldap.LDAPError as e: |
| 976 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 977 |
assert False |
| 978 |
|
| 979 |
topology_st.standalone.restart(timeout=10) |
| 980 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 981 |
assert len(access_log_lines) == 0 |
| 982 |
|
| 983 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=103.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 984 |
assert len(access_log_lines) == 1 |
| 985 |
|
| 986 |
def fin(): |
| 987 |
try: |
| 988 |
topology_st.standalone.delete_s(TEST_DN) |
| 989 |
except: |
| 990 |
pass |
| 991 |
|
| 992 |
request.addfinalizer(fin) |
| 993 |
|
| 994 |
def test_long_session_tracking_compare(topology_st, request): |
| 995 |
"""Verify that a long session_tracking string |
| 996 |
is added (truncate) during a compare |
| 997 |
|
| 998 |
:id: 840ad60b-d2c5-4375-a50d-1553701d3c22 |
| 999 |
:customerscenario: False |
| 1000 |
:setup: Standalone instance, default backend |
| 1001 |
:steps: |
| 1002 |
1. Add a test entry |
| 1003 |
2. compare an attribute with an exact max length session tracking |
| 1004 |
3. Restart the instance to flush the log |
| 1005 |
4. Check the exact same string is not present in the access log for the ADD |
| 1006 |
5. Check the exact same string is present in the access log for the COMPARE (with '.') |
| 1007 |
:expectedresults: |
| 1008 |
1. Add should succeed |
| 1009 |
2. Compare should succeed |
| 1010 |
3. success |
| 1011 |
4. Log should not contain a log with that session for the ADD |
| 1012 |
5. Log should contain one log with that session for the COMPARE |
| 1013 |
""" |
| 1014 |
|
| 1015 |
|
| 1016 |
SESSION_TRACKING_IDENTIFIER_MAX = "COMPARE long ->" |
| 1017 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 1018 |
st_ctrl = SessionTrackingControl( |
| 1019 |
SESSION_SOURCE_IP, |
| 1020 |
SESSION_SOURCE_NAME, |
| 1021 |
SESSION_TRACKING_FORMAT_OID, |
| 1022 |
SESSION_TRACKING_IDENTIFIER |
| 1023 |
) |
| 1024 |
TEST_DN = "cn=test_compare," + DEFAULT_SUFFIX |
| 1025 |
try: |
| 1026 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1027 |
[ |
| 1028 |
('objectClass', b'person'), |
| 1029 |
('sn', b'test_compare'), |
| 1030 |
('cn', b'test_compare'), |
| 1031 |
('userPassword', b'test_compare'), |
| 1032 |
]) |
| 1033 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_compare', serverctrls=[st_ctrl]) |
| 1034 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_fail_compare', serverctrls=[st_ctrl]) |
| 1035 |
except ldap.LDAPError as e: |
| 1036 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 1037 |
assert False |
| 1038 |
|
| 1039 |
topology_st.standalone.restart(timeout=10) |
| 1040 |
|
| 1041 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1042 |
assert len(access_log_lines) == 0 |
| 1043 |
|
| 1044 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=6 tag=111.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1045 |
assert len(access_log_lines) == 1 |
| 1046 |
|
| 1047 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=5 tag=111.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1048 |
assert len(access_log_lines) == 1 |
| 1049 |
|
| 1050 |
def fin(): |
| 1051 |
try: |
| 1052 |
topology_st.standalone.delete_s(TEST_DN) |
| 1053 |
except: |
| 1054 |
pass |
| 1055 |
|
| 1056 |
request.addfinalizer(fin) |
| 1057 |
|
| 1058 |
def test_long_session_tracking_abandon(topology_st, request): |
| 1059 |
"""Verify that long session_tracking string |
| 1060 |
is added (truncate) during an abandon |
| 1061 |
|
| 1062 |
:id: bded1fbb-b123-42c5-8d28-9fcf9f19af94 |
| 1063 |
:customerscenario: False |
| 1064 |
:setup: Standalone instance, default backend |
| 1065 |
:steps: |
| 1066 |
1. Add 10 test entries |
| 1067 |
2. Launch Page Search with a window of 3 |
| 1068 |
3. Abandon the Page Search with long session tracking |
| 1069 |
4. Restart the instance to flush the log |
| 1070 |
5. Check the exact same string is not present in the access log for the ADD |
| 1071 |
6. Check the exact same string is present in the access log for the ABANDON (with '.') |
| 1072 |
:expectedresults: |
| 1073 |
1. Add should succeed |
| 1074 |
2. success |
| 1075 |
3. success |
| 1076 |
4. success |
| 1077 |
5. Log should not contain log with that session for the ADDs |
| 1078 |
6. Log should contain one log with that session for the abandon |
| 1079 |
""" |
| 1080 |
|
| 1081 |
SESSION_TRACKING_IDENTIFIER_MAX = "ABANDON long ->" |
| 1082 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 1083 |
st_ctrl = SessionTrackingControl( |
| 1084 |
SESSION_SOURCE_IP, |
| 1085 |
SESSION_SOURCE_NAME, |
| 1086 |
SESSION_TRACKING_FORMAT_OID, |
| 1087 |
SESSION_TRACKING_IDENTIFIER |
| 1088 |
) |
| 1089 |
|
| 1090 |
# provision more entries than the page search will fetch |
| 1091 |
entries = [] |
| 1092 |
for i in range(10): |
| 1093 |
TEST_DN = "cn=test_abandon_%d,%s" % (i, DEFAULT_SUFFIX) |
| 1094 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1095 |
[ |
| 1096 |
('objectClass', b'person'), |
| 1097 |
('sn', b'test_abandon'), |
| 1098 |
('cn', b'test_abandon_%d' % i), |
| 1099 |
('userPassword', b'test_abandon'), |
| 1100 |
]) |
| 1101 |
entries.append(TEST_DN) |
| 1102 |
|
| 1103 |
# run a page search (with the session) using a small window. So we can abandon it. |
| 1104 |
req_ctrl = SimplePagedResultsControl(True, size=3, cookie='') |
| 1105 |
msgid = topology_st.standalone.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, r'(objectclass=*)', ['cn'], serverctrls=[req_ctrl]) |
| 1106 |
time.sleep(1) |
| 1107 |
topology_st.standalone.abandon_ext(msgid, serverctrls=[st_ctrl]) |
| 1108 |
|
| 1109 |
|
| 1110 |
topology_st.standalone.restart(timeout=10) |
| 1111 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1112 |
assert len(access_log_lines) == 0 |
| 1113 |
|
| 1114 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*ABANDON.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1115 |
assert len(access_log_lines) == 1 |
| 1116 |
|
| 1117 |
def fin(): |
| 1118 |
for ent in entries: |
| 1119 |
try: |
| 1120 |
topology_st.standalone.delete_s(ent) |
| 1121 |
except: |
| 1122 |
pass |
| 1123 |
|
| 1124 |
request.addfinalizer(fin) |
| 1125 |
|
| 1126 |
def test_long_session_tracking_extop(topology_st, request): |
| 1127 |
"""Verify that long session_tracking string |
| 1128 |
is added (truncate) during an extended operation |
| 1129 |
|
| 1130 |
:id: a7aa65d2-eed8-4bdd-9786-2379997ff0b7 |
| 1131 |
:customerscenario: False |
| 1132 |
:setup: Standalone instance, default backend |
| 1133 |
:steps: |
| 1134 |
1. run whoami extop |
| 1135 |
2. Check the truncated long session string |
| 1136 |
is present in the access log for the EXTOP |
| 1137 |
:expectedresults: |
| 1138 |
1. success |
| 1139 |
2. Log should contain one log with that session for the EXTOP |
| 1140 |
""" |
| 1141 |
SESSION_TRACKING_IDENTIFIER_MAX = "Extop long --->" |
| 1142 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_MAX + "xxxxxxxx" |
| 1143 |
st_ctrl = SessionTrackingControl( |
| 1144 |
SESSION_SOURCE_IP, |
| 1145 |
SESSION_SOURCE_NAME, |
| 1146 |
SESSION_TRACKING_FORMAT_OID, |
| 1147 |
SESSION_TRACKING_IDENTIFIER |
| 1148 |
) |
| 1149 |
|
| 1150 |
extop = ExtendedRequest(requestName = '1.3.6.1.4.1.4203.1.11.3', requestValue=None) |
| 1151 |
(oid_response, res) = topology_st.standalone.extop_s(extop, serverctrls=[st_ctrl]) |
| 1152 |
|
| 1153 |
topology_st.standalone.restart(timeout=10) |
| 1154 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=120.* sid="%s...".*' % SESSION_TRACKING_IDENTIFIER_MAX) |
| 1155 |
assert len(access_log_lines) == 1 |
| 1156 |
|
| 1157 |
def fin(): |
| 1158 |
pass |
| 1159 |
|
| 1160 |
request.addfinalizer(fin) |
| 1161 |
|
| 1162 |
def test_escaped_session_tracking_srch(topology_st, request): |
| 1163 |
"""Verify that a session_tracking string containing escaped character |
| 1164 |
is added (not truncate) during a search |
| 1165 |
|
| 1166 |
:id: dce83631-7a3f-4af8-a79a-ee81df4b0595 |
| 1167 |
:customerscenario: False |
| 1168 |
:setup: Standalone instance, default backend |
| 1169 |
:steps: |
| 1170 |
1. Do a search with a session tracking string containing escaped character |
| 1171 |
2. Restart the instance to flush the log |
| 1172 |
3. Check the exact same string is present in the access log |
| 1173 |
:expectedresults: |
| 1174 |
1. Search should succeed |
| 1175 |
2. success |
| 1176 |
3. Log should contain one log with that session |
| 1177 |
""" |
| 1178 |
|
| 1179 |
|
| 1180 |
SESSION_TRACKING_IDENTIFIER_START = "SRCH" |
| 1181 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1182 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\06 " |
| 1183 |
SESSION_TRACKING_IDENTIFIER_END = "escape" |
| 1184 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1185 |
st_ctrl = SessionTrackingControl( |
| 1186 |
SESSION_SOURCE_IP, |
| 1187 |
SESSION_SOURCE_NAME, |
| 1188 |
SESSION_TRACKING_FORMAT_OID, |
| 1189 |
SESSION_TRACKING_IDENTIFIER |
| 1190 |
) |
| 1191 |
|
| 1192 |
topology_st.standalone.search_ext_s(DEFAULT_SUFFIX, |
| 1193 |
ldap.SCOPE_SUBTREE, |
| 1194 |
'(uid=*)', |
| 1195 |
serverctrls=[st_ctrl]) |
| 1196 |
topology_st.standalone.restart(timeout=10) |
| 1197 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1198 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=101.* sid="%s".*' % sid_escaped) |
| 1199 |
assert len(access_log_lines) == 1 |
| 1200 |
|
| 1201 |
def fin(): |
| 1202 |
pass |
| 1203 |
|
| 1204 |
request.addfinalizer(fin) |
| 1205 |
|
| 1206 |
def test_escaped_session_tracking_add(topology_st, request): |
| 1207 |
"""Verify that a session_tracking string containing escaped character |
| 1208 |
is added (not truncate) during a add |
| 1209 |
|
| 1210 |
:id: df40e5b3-20d9-4a85-a7ad-246e3ec25f4f |
| 1211 |
:customerscenario: False |
| 1212 |
:setup: Standalone instance, default backend |
| 1213 |
:steps: |
| 1214 |
1. Add a test entry with a session tracking containing escaped character |
| 1215 |
2. Restart the instance to flush the log |
| 1216 |
3. Check the exact same string is present in the access log |
| 1217 |
:expectedresults: |
| 1218 |
1. Add should succeed |
| 1219 |
2. success |
| 1220 |
3. Log should contain one log with that session |
| 1221 |
""" |
| 1222 |
|
| 1223 |
|
| 1224 |
SESSION_TRACKING_IDENTIFIER_START = "ADD" |
| 1225 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1226 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\07 " |
| 1227 |
SESSION_TRACKING_IDENTIFIER_END = "escape" |
| 1228 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1229 |
st_ctrl = SessionTrackingControl( |
| 1230 |
SESSION_SOURCE_IP, |
| 1231 |
SESSION_SOURCE_NAME, |
| 1232 |
SESSION_TRACKING_FORMAT_OID, |
| 1233 |
SESSION_TRACKING_IDENTIFIER |
| 1234 |
) |
| 1235 |
TEST_DN = "cn=test_add," + DEFAULT_SUFFIX |
| 1236 |
try: |
| 1237 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1238 |
[ |
| 1239 |
('objectClass', b'person'), |
| 1240 |
('sn', b'test_add'), |
| 1241 |
('cn', b'test_add'), |
| 1242 |
('userPassword', b'test_add'), |
| 1243 |
], |
| 1244 |
serverctrls=[st_ctrl]) |
| 1245 |
except ldap.LDAPError as e: |
| 1246 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 1247 |
assert False |
| 1248 |
|
| 1249 |
topology_st.standalone.restart(timeout=10) |
| 1250 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1251 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % sid_escaped) |
| 1252 |
assert len(access_log_lines) == 1 |
| 1253 |
|
| 1254 |
def fin(): |
| 1255 |
try: |
| 1256 |
topology_st.standalone.delete_s(TEST_DN) |
| 1257 |
except: |
| 1258 |
pass |
| 1259 |
|
| 1260 |
request.addfinalizer(fin) |
| 1261 |
|
| 1262 |
def test_escaped_session_tracking_del(topology_st, request): |
| 1263 |
"""Verify that a session_tracking string containing escaped character |
| 1264 |
is added (not truncate) during a DEL |
| 1265 |
|
| 1266 |
:id: 561c75fc-ae24-42ed-b062-9c994f71e3fc |
| 1267 |
:customerscenario: False |
| 1268 |
:setup: Standalone instance, default backend |
| 1269 |
:steps: |
| 1270 |
1. Add a test entry |
| 1271 |
2. Delete the test entry with a session tracking containing escaped character |
| 1272 |
3. Restart the instance to flush the log |
| 1273 |
4. Check the exact same string is not present in the access log for the ADD |
| 1274 |
5. Check the exact same string is present in the access log for the DEL |
| 1275 |
:expectedresults: |
| 1276 |
1. Add should succeed |
| 1277 |
2. DEL should succeed |
| 1278 |
3. success |
| 1279 |
4. Log should not contain a log with that session for the ADD |
| 1280 |
5. Log should contain one log with that session for the DEL |
| 1281 |
""" |
| 1282 |
|
| 1283 |
|
| 1284 |
SESSION_TRACKING_IDENTIFIER_START = "DEL" |
| 1285 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1286 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\14 " |
| 1287 |
SESSION_TRACKING_IDENTIFIER_END = "escape" |
| 1288 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1289 |
st_ctrl = SessionTrackingControl( |
| 1290 |
SESSION_SOURCE_IP, |
| 1291 |
SESSION_SOURCE_NAME, |
| 1292 |
SESSION_TRACKING_FORMAT_OID, |
| 1293 |
SESSION_TRACKING_IDENTIFIER |
| 1294 |
) |
| 1295 |
TEST_DN = "cn=test_del," + DEFAULT_SUFFIX |
| 1296 |
try: |
| 1297 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1298 |
[ |
| 1299 |
('objectClass', b'person'), |
| 1300 |
('sn', b'test_del'), |
| 1301 |
('cn', b'test_del'), |
| 1302 |
('userPassword', b'test_del'), |
| 1303 |
]) |
| 1304 |
topology_st.standalone.delete_ext_s(TEST_DN, |
| 1305 |
serverctrls=[st_ctrl]) |
| 1306 |
except ldap.LDAPError as e: |
| 1307 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 1308 |
assert False |
| 1309 |
|
| 1310 |
topology_st.standalone.restart(timeout=10) |
| 1311 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1312 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % sid_escaped) |
| 1313 |
assert len(access_log_lines) == 0 |
| 1314 |
|
| 1315 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=107.* sid="%s".*' % sid_escaped) |
| 1316 |
assert len(access_log_lines) == 1 |
| 1317 |
|
| 1318 |
def fin(): |
| 1319 |
try: |
| 1320 |
topology_st.standalone.delete_s(TEST_DN) |
| 1321 |
except: |
| 1322 |
pass |
| 1323 |
|
| 1324 |
request.addfinalizer(fin) |
| 1325 |
|
| 1326 |
def test_escaped_session_tracking_mod(topology_st, request): |
| 1327 |
"""Verify that a session_tracking string containing escaped character |
| 1328 |
is added (not truncate) during a MOD |
| 1329 |
|
| 1330 |
:id: ca2ca411-32b4-4a9f-845d-e596f08a849c |
| 1331 |
:customerscenario: False |
| 1332 |
:setup: Standalone instance, default backend |
| 1333 |
:steps: |
| 1334 |
1. Add a test entry |
| 1335 |
2. Modify the test entry with a session tracking containing escaped character |
| 1336 |
3. Restart the instance to flush the log |
| 1337 |
4. Check the exact same string is not present in the access log for the ADD |
| 1338 |
5. Check the exact same string is present in the access log for the MOD |
| 1339 |
:expectedresults: |
| 1340 |
1. Add should succeed |
| 1341 |
2. Mod should succeed |
| 1342 |
3. success |
| 1343 |
4. Log should not contain a log with that session for the ADD |
| 1344 |
5. Log should contain one log with that session for the MOD |
| 1345 |
""" |
| 1346 |
|
| 1347 |
|
| 1348 |
SESSION_TRACKING_IDENTIFIER_START = "MOD" |
| 1349 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1350 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\10 " |
| 1351 |
SESSION_TRACKING_IDENTIFIER_END = "escape" |
| 1352 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1353 |
st_ctrl = SessionTrackingControl( |
| 1354 |
SESSION_SOURCE_IP, |
| 1355 |
SESSION_SOURCE_NAME, |
| 1356 |
SESSION_TRACKING_FORMAT_OID, |
| 1357 |
SESSION_TRACKING_IDENTIFIER |
| 1358 |
) |
| 1359 |
TEST_DN = "cn=test_mod," + DEFAULT_SUFFIX |
| 1360 |
try: |
| 1361 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1362 |
[ |
| 1363 |
('objectClass', b'person'), |
| 1364 |
('sn', b'test_del'), |
| 1365 |
('cn', b'test_del'), |
| 1366 |
('userPassword', b'test_del'), |
| 1367 |
]) |
| 1368 |
topology_st.standalone.modify_ext_s(TEST_DN, |
| 1369 |
[(ldap.MOD_REPLACE, 'sn', b'new_sn')], |
| 1370 |
serverctrls=[st_ctrl]) |
| 1371 |
except ldap.LDAPError as e: |
| 1372 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 1373 |
assert False |
| 1374 |
|
| 1375 |
topology_st.standalone.restart(timeout=10) |
| 1376 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1377 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % sid_escaped) |
| 1378 |
assert len(access_log_lines) == 0 |
| 1379 |
|
| 1380 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=103.* sid="%s".*' % sid_escaped) |
| 1381 |
assert len(access_log_lines) == 1 |
| 1382 |
|
| 1383 |
def fin(): |
| 1384 |
try: |
| 1385 |
topology_st.standalone.delete_s(TEST_DN) |
| 1386 |
except: |
| 1387 |
pass |
| 1388 |
|
| 1389 |
request.addfinalizer(fin) |
| 1390 |
|
| 1391 |
def test_escaped_session_tracking_compare(topology_st, request): |
| 1392 |
"""Verify that a session_tracking string containing escaped character |
| 1393 |
is added (not truncate) during a COMPARE |
| 1394 |
|
| 1395 |
:id: 93c13457-5c51-4bec-8e8a-0c6320cd970b |
| 1396 |
:customerscenario: False |
| 1397 |
:setup: Standalone instance, default backend |
| 1398 |
:steps: |
| 1399 |
1. Add a test entry |
| 1400 |
2. compare an attribute with a session tracking containing escaped character |
| 1401 |
3. Restart the instance to flush the log |
| 1402 |
4. Check the exact same string is not present in the access log for the ADD |
| 1403 |
5. Check the exact same string is present in the access log for the COMPARE |
| 1404 |
:expectedresults: |
| 1405 |
1. Add should succeed |
| 1406 |
2. Compare should succeed |
| 1407 |
3. success |
| 1408 |
4. Log should not contain a log with that session for the ADD |
| 1409 |
5. Log should contain one log with that session for the COMPARE |
| 1410 |
""" |
| 1411 |
|
| 1412 |
|
| 1413 |
# be careful that the complete string is less than 15 chars |
| 1414 |
SESSION_TRACKING_IDENTIFIER_START = "COMPARE" |
| 1415 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1416 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\11 " |
| 1417 |
SESSION_TRACKING_IDENTIFIER_END = "esc" |
| 1418 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1419 |
st_ctrl = SessionTrackingControl( |
| 1420 |
SESSION_SOURCE_IP, |
| 1421 |
SESSION_SOURCE_NAME, |
| 1422 |
SESSION_TRACKING_FORMAT_OID, |
| 1423 |
SESSION_TRACKING_IDENTIFIER |
| 1424 |
) |
| 1425 |
TEST_DN = "cn=test_compare," + DEFAULT_SUFFIX |
| 1426 |
try: |
| 1427 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1428 |
[ |
| 1429 |
('objectClass', b'person'), |
| 1430 |
('sn', b'test_compare'), |
| 1431 |
('cn', b'test_compare'), |
| 1432 |
('userPassword', b'test_compare'), |
| 1433 |
]) |
| 1434 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_compare', serverctrls=[st_ctrl]) |
| 1435 |
topology_st.standalone.compare_ext_s(TEST_DN, 'sn', b'test_fail_compare', serverctrls=[st_ctrl]) |
| 1436 |
except ldap.LDAPError as e: |
| 1437 |
log.fatal('Failed to add user1 entry, error: ' + e.message['desc']) |
| 1438 |
assert False |
| 1439 |
|
| 1440 |
topology_st.standalone.restart(timeout=10) |
| 1441 |
|
| 1442 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1443 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % sid_escaped) |
| 1444 |
assert len(access_log_lines) == 0 |
| 1445 |
|
| 1446 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=6 tag=111.* sid="%s".*' % sid_escaped) |
| 1447 |
assert len(access_log_lines) == 1 |
| 1448 |
|
| 1449 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*err=5 tag=111.* sid="%s".*' % sid_escaped) |
| 1450 |
assert len(access_log_lines) == 1 |
| 1451 |
|
| 1452 |
def fin(): |
| 1453 |
try: |
| 1454 |
topology_st.standalone.delete_s(TEST_DN) |
| 1455 |
except: |
| 1456 |
pass |
| 1457 |
|
| 1458 |
request.addfinalizer(fin) |
| 1459 |
|
| 1460 |
|
| 1461 |
def test_escaped_session_tracking_abandon(topology_st, request): |
| 1462 |
"""Verify that a session_tracking string containing escaped character |
| 1463 |
is added (not truncate) during an abandon |
| 1464 |
|
| 1465 |
:id: 37a9d1db-ec19-4381-88f3-48eae477cb81 |
| 1466 |
:customerscenario: False |
| 1467 |
:setup: Standalone instance, default backend |
| 1468 |
:steps: |
| 1469 |
1. Add 10 test entries |
| 1470 |
2. Launch Page Search with a window of 3 |
| 1471 |
3. Abandon the Page Search with a session tracking containing escaped character |
| 1472 |
4. Restart the instance to flush the log |
| 1473 |
5. Check the exact same string is not present in the access log for the ADD |
| 1474 |
6. Check the exact same string is present in the access log for the ABANDON |
| 1475 |
:expectedresults: |
| 1476 |
1. Add should succeed |
| 1477 |
2. success |
| 1478 |
3. success |
| 1479 |
4. success |
| 1480 |
5. Log should not contain log with that session for the ADDs |
| 1481 |
6. Log should contain one log with that session for the abandon |
| 1482 |
""" |
| 1483 |
|
| 1484 |
# be careful that the complete string is less than 15 chars |
| 1485 |
SESSION_TRACKING_IDENTIFIER_START = "ABANDON" |
| 1486 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1487 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\12 " |
| 1488 |
SESSION_TRACKING_IDENTIFIER_END = "es" |
| 1489 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1490 |
st_ctrl = SessionTrackingControl( |
| 1491 |
SESSION_SOURCE_IP, |
| 1492 |
SESSION_SOURCE_NAME, |
| 1493 |
SESSION_TRACKING_FORMAT_OID, |
| 1494 |
SESSION_TRACKING_IDENTIFIER |
| 1495 |
) |
| 1496 |
|
| 1497 |
# provision more entries than the page search will fetch |
| 1498 |
entries = [] |
| 1499 |
for i in range(10): |
| 1500 |
TEST_DN = "cn=test_abandon_%d,%s" % (i, DEFAULT_SUFFIX) |
| 1501 |
ent = topology_st.standalone.add_ext_s(TEST_DN, |
| 1502 |
[ |
| 1503 |
('objectClass', b'person'), |
| 1504 |
('sn', b'test_abandon'), |
| 1505 |
('cn', b'test_abandon_%d' % i), |
| 1506 |
('userPassword', b'test_abandon'), |
| 1507 |
]) |
| 1508 |
entries.append(TEST_DN) |
| 1509 |
|
| 1510 |
# run a page search (with the session) using a small window. So we can abandon it. |
| 1511 |
req_ctrl = SimplePagedResultsControl(True, size=3, cookie='') |
| 1512 |
msgid = topology_st.standalone.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, r'(objectclass=*)', ['cn'], serverctrls=[req_ctrl]) |
| 1513 |
time.sleep(1) |
| 1514 |
topology_st.standalone.abandon_ext(msgid, serverctrls=[st_ctrl]) |
| 1515 |
|
| 1516 |
|
| 1517 |
topology_st.standalone.restart(timeout=10) |
| 1518 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1519 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=105.* sid="%s".*' % sid_escaped) |
| 1520 |
assert len(access_log_lines) == 0 |
| 1521 |
|
| 1522 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*ABANDON.* sid="%s".*' % sid_escaped) |
| 1523 |
assert len(access_log_lines) == 1 |
| 1524 |
|
| 1525 |
def fin(): |
| 1526 |
for ent in entries: |
| 1527 |
try: |
| 1528 |
topology_st.standalone.delete_s(ent) |
| 1529 |
except: |
| 1530 |
pass |
| 1531 |
|
| 1532 |
request.addfinalizer(fin) |
| 1533 |
|
| 1534 |
def test_escaped_session_tracking_extop(topology_st, request): |
| 1535 |
"""Verify that a session_tracking string containing escaped character |
| 1536 |
is added (not truncate) during an extended operation |
| 1537 |
|
| 1538 |
:id: fd3afce9-86c9-4d87-ab05-9d19f2d733c3 |
| 1539 |
:customerscenario: False |
| 1540 |
:setup: Standalone instance, default backend |
| 1541 |
:steps: |
| 1542 |
1. run whoami extop |
| 1543 |
2. Check the exact same string is present in the access log for the EXTOP |
| 1544 |
:expectedresults: |
| 1545 |
1. success |
| 1546 |
2. Log should contain one log with that session for the EXTOP |
| 1547 |
""" |
| 1548 |
|
| 1549 |
# be careful that the complete string is less than 15 chars |
| 1550 |
SESSION_TRACKING_IDENTIFIER_START = "EXTOP" |
| 1551 |
SESSION_TRACKING_IDENTIFIER_ORIGINAL = " " |
| 1552 |
SESSION_TRACKING_IDENTIFIER_ESCAPED = " \\\\13 " |
| 1553 |
SESSION_TRACKING_IDENTIFIER_END = "escap" |
| 1554 |
SESSION_TRACKING_IDENTIFIER = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ORIGINAL + SESSION_TRACKING_IDENTIFIER_END |
| 1555 |
st_ctrl = SessionTrackingControl( |
| 1556 |
SESSION_SOURCE_IP, |
| 1557 |
SESSION_SOURCE_NAME, |
| 1558 |
SESSION_TRACKING_FORMAT_OID, |
| 1559 |
SESSION_TRACKING_IDENTIFIER |
| 1560 |
) |
| 1561 |
|
| 1562 |
extop = ExtendedRequest(requestName = '1.3.6.1.4.1.4203.1.11.3', requestValue=None) |
| 1563 |
(oid_response, res) = topology_st.standalone.extop_s(extop, serverctrls=[st_ctrl]) |
| 1564 |
|
| 1565 |
topology_st.standalone.restart(timeout=10) |
| 1566 |
sid_escaped = SESSION_TRACKING_IDENTIFIER_START + SESSION_TRACKING_IDENTIFIER_ESCAPED + SESSION_TRACKING_IDENTIFIER_END |
| 1567 |
access_log_lines = topology_st.standalone.ds_access_log.match('.*tag=120.* sid="%s".*' % sid_escaped) |
| 1568 |
assert len(access_log_lines) == 1 |
| 1569 |
|
| 1570 |
def fin(): |
| 1571 |
pass |
| 1572 |
|
| 1573 |
request.addfinalizer(fin) |
| 1574 |
|
| 1575 |
def test_sid_replication(topo_m2, request): |
| 1576 |
"""Check that session ID are logged on |
| 1577 |
supplier side (errorLog) and consumer side (accessLog) |
| 1578 |
|
| 1579 |
:id: e716b04c-152b-4964-ae7a-b18fb4655cb9 |
| 1580 |
:setup: 2 Supplier Instances |
| 1581 |
:steps: |
| 1582 |
1. Initialize replication |
| 1583 |
2. Enable replication debug logging |
| 1584 |
3. Create and update a test user |
| 1585 |
4. Stop instances |
| 1586 |
5. Check that 'sid=' exist both on supplier/consumer sides |
| 1587 |
:expectedresults: |
| 1588 |
1. Success |
| 1589 |
2. Success |
| 1590 |
3. Success |
| 1591 |
4. Success |
| 1592 |
5. Success |
| 1593 |
""" |
| 1594 |
m1 = topo_m2.ms["supplier1"] |
| 1595 |
m2 = topo_m2.ms["supplier2"] |
| 1596 |
|
| 1597 |
m1.config.loglevel((ErrorLog.REPLICA,)) |
| 1598 |
m2.config.loglevel((ErrorLog.REPLICA,)) |
| 1599 |
|
| 1600 |
TEST_ENTRY_NAME = 'sid_test' |
| 1601 |
TEST_ENTRY_DN = 'uid={},{}'.format(TEST_ENTRY_NAME, DEFAULT_SUFFIX) |
| 1602 |
test_user = UserAccount(m1, TEST_ENTRY_DN) |
| 1603 |
test_user.create(properties={ |
| 1604 |
'uid': TEST_ENTRY_NAME, |
| 1605 |
'cn': TEST_ENTRY_NAME, |
| 1606 |
'sn': TEST_ENTRY_NAME, |
| 1607 |
'userPassword': TEST_ENTRY_NAME, |
| 1608 |
'uidNumber' : '1000', |
| 1609 |
'gidNumber' : '2000', |
| 1610 |
'homeDirectory' : '/home/sid_test', |
| 1611 |
}) |
| 1612 |
|
| 1613 |
# create a large value set so that it is sorted |
| 1614 |
for i in range(1,20): |
| 1615 |
test_user.add('description', 'value {}'.format(str(i))) |
| 1616 |
|
| 1617 |
time.sleep(2) |
| 1618 |
m1.stop() |
| 1619 |
m2.stop() |
| 1620 |
log_lines = m1.ds_access_log.match('.* sid=".*') |
| 1621 |
assert len(log_lines) > 0 |
| 1622 |
log_lines = m2.ds_error_log.match('.* - sid=".*') |
| 1623 |
assert len(log_lines) > 0 |
| 1624 |
m1.start() |
| 1625 |
m2.start() |
| 1626 |
|
| 1627 |
def fin(): |
| 1628 |
log.info('Deleting entry {}'.format(TEST_ENTRY_DN)) |
| 1629 |
test_user.delete() |
| 1630 |
m1.config.loglevel((ErrorLog.DEFAULT,), service='error') |
| 1631 |
m2.config.loglevel((ErrorLog.DEFAULT,), service='error') |
| 1632 |
|
| 1633 |
request.addfinalizer(fin) |
| 1634 |
|
| 1635 |
if __name__ == "__main__": |
| 1636 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1637 |
pytest.main("-s -v %s" % CURRENT_FILE) |