| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 |
import json |
| 9 |
import ldap |
| 10 |
import logging |
| 11 |
import os |
| 12 |
import pytest |
| 13 |
import re |
| 14 |
import shutil |
| 15 |
import subprocess |
| 16 |
import time |
| 17 |
from datetime import datetime, timedelta |
| 18 |
|
| 19 |
from lib389._constants import * |
| 20 |
from lib389.idm.account import Anonymous |
| 21 |
from lib389.idm.user import UserAccounts |
| 22 |
from lib389.utils import ensure_str |
| 23 |
from ldap.controls.vlv import VLVRequestControl |
| 24 |
from ldap.controls.sss import SSSRequestControl |
| 25 |
from ldap.controls import SimplePagedResultsControl |
| 26 |
from ldap.controls.psearch import PersistentSearchControl |
| 27 |
from lib389.backend import DatabaseConfig |
| 28 |
from lib389.dbgen import dbgen_users |
| 29 |
from lib389._mapped_object import DSLdapObjects |
| 30 |
from lib389.config import CertmapLegacy |
| 31 |
from lib389.nss_ssl import NssSsl |
| 32 |
from test389.topologies import create_topology |
| 33 |
|
| 34 |
pytestmark = pytest.mark.tier1 |
| 35 |
|
| 36 |
log = logging.getLogger(__name__) |
| 37 |
|
| 38 |
PREFIX = os.getenv("PREFIX", default="") |
| 39 |
|
| 40 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 41 |
|
| 42 |
@pytest.fixture(scope="class", params=["default", "json"]) |
| 43 |
def topo_shared(request): |
| 44 |
"""Create DS standalone instance""" |
| 45 |
log_format = request.param |
| 46 |
topology = create_topology({ReplicaRole.STANDALONE: 1}) |
| 47 |
topology.standalone.config.set('nsslapd-accesslog-logbuffering', "off") |
| 48 |
topology.standalone.config.set('nsslapd-accesslog-log-format', log_format) |
| 49 |
topology.standalone.config.set("nsslapd-accesslog-level", "256") |
| 50 |
|
| 51 |
def fin(): |
| 52 |
if not DEBUGGING and topology.standalone.exists(): |
| 53 |
topology.standalone.delete() |
| 54 |
request.addfinalizer(fin) |
| 55 |
|
| 56 |
return topology |
| 57 |
|
| 58 |
@pytest.fixture(scope="function", params=["default", "json"]) |
| 59 |
def topo_single_use(request): |
| 60 |
"""Create a fresh DS standalone instance per test function.""" |
| 61 |
log_format = request.param |
| 62 |
topology = create_topology({ReplicaRole.STANDALONE: 1}) |
| 63 |
topology.standalone.config.set('nsslapd-accesslog-logbuffering', "off") |
| 64 |
topology.standalone.config.set('nsslapd-accesslog-log-format', log_format) |
| 65 |
|
| 66 |
def fin(): |
| 67 |
if topology.standalone.exists(): |
| 68 |
topology.standalone.delete() |
| 69 |
request.addfinalizer(fin) |
| 70 |
|
| 71 |
return topology |
| 72 |
|
| 73 |
def adjust_expected_for_backend(self, expected: dict): |
| 74 |
""" |
| 75 |
Adjust expected logconv stats based on backend specific behavior. |
| 76 |
|
| 77 |
A BDB implementation triggers additional operations during internal |
| 78 |
actions, like restarts. This helper updates the expected stats to |
| 79 |
account for these backend specific extra operations. |
| 80 |
|
| 81 |
Args: |
| 82 |
expected (dict): Dictionary of expected logconv stats. |
| 83 |
|
| 84 |
Returns: |
| 85 |
dict: Updated expected stats reflecting backend behavior. |
| 86 |
""" |
| 87 |
if self.inst.dblib == "bdb": |
| 88 |
expected["operations"] = expected.get("operations", 0) + 1 |
| 89 |
expected["searches"] = expected.get("searches", 0) + 1 |
| 90 |
expected["results"] = expected.get("results", 0) + 1 |
| 91 |
|
| 92 |
return expected |
| 93 |
|
| 94 |
class TestLogconv: |
| 95 |
|
| 96 |
def init_instance(self, inst): |
| 97 |
"""Prepare common attributes for each test.""" |
| 98 |
self.inst = inst |
| 99 |
self.logconv_path = shutil.which("logconv.py") or None |
| 100 |
self.log_format = self.inst.config.get_attr_val_utf8("nsslapd-accesslog-log-format") |
| 101 |
self.access_log_path = self.get_access_log_path() |
| 102 |
self.debug_output = 'logconv-debug.log' |
| 103 |
|
| 104 |
def get_access_log_path(self): |
| 105 |
""" |
| 106 |
Get server access log file. |
| 107 |
""" |
| 108 |
path = self.inst.config.get_attr_val_utf8('nsslapd-accesslog') |
| 109 |
if not path: |
| 110 |
pytest.fail("Access log path not found: {path}") |
| 111 |
return None |
| 112 |
|
| 113 |
return path |
| 114 |
|
| 115 |
def truncate_logs(self): |
| 116 |
""" |
| 117 |
Truncate logs between test runs. |
| 118 |
""" |
| 119 |
if not self.access_log_path: |
| 120 |
pytest.fail(f"Access log not found. {self.access_log_path}") |
| 121 |
|
| 122 |
time.sleep(3) |
| 123 |
with open(self.access_log_path, "w") as f: |
| 124 |
f.truncate(0) |
| 125 |
|
| 126 |
def extract_logconv_stats(self, output: str): |
| 127 |
""" |
| 128 |
Parse the default logconv output and extract key counts. |
| 129 |
|
| 130 |
Uses regex patterns to match lines in the logconv output. |
| 131 |
|
| 132 |
Args: |
| 133 |
output (str): The raw output from logconv. |
| 134 |
""" |
| 135 |
patterns = { |
| 136 |
# Server stats |
| 137 |
"restarts": r"^Restarts:\s+(\d+)", |
| 138 |
|
| 139 |
# Connections |
| 140 |
"concurrent_conns": r"^Peak Concurrent connections:\s+(\d+)", |
| 141 |
"total_connections": r"^Total connections:\s+(\d+)", |
| 142 |
"ldap_conns": r"- LDAP connections:\s+(\d+)", |
| 143 |
"ldapi_conns": r"- LDAPI connections:\s+(\d+)", |
| 144 |
"ldaps_conns": r"- LDAPS connections:\s+(\d+)", |
| 145 |
"starttls_conns": r"- StartTLS Extended Ops:\s+(\d+)", |
| 146 |
|
| 147 |
# Operations |
| 148 |
"operations": r"^Total Operations:\s+(\d+)", |
| 149 |
"results": r"^Total Results:\s+(\d+)", |
| 150 |
"searches": r"^Searches:\s+(\d+)", |
| 151 |
"mods": r"^Modifications:\s+(\d+)", |
| 152 |
"adds": r"^Adds:\s+(\d+)", |
| 153 |
"deletes": r"^Deletes:\s+(\d+)", |
| 154 |
"modrdns": r"^Mod RDNs:\s+(\d+)", |
| 155 |
"compares": r"Compares:\s+(\d+)", |
| 156 |
"binds": r"^Binds:\s+(\d+)", |
| 157 |
"unbinds": r"^Unbinds:\s+(\d+)", |
| 158 |
"autobinds": r"AUTOBINDs\(LDAPI\):\s+(\d+)", |
| 159 |
"sasl_binds": r"SASL Binds:\s+(\d+)", |
| 160 |
"anon_binds": r"Anonymous Binds:\s+(\d+)", |
| 161 |
"ssl_client_binds": r"SSL Client Binds:\s+(\d+)", |
| 162 |
"ssl_client_bind_failed": r"Failed SSL Client Binds:\s+(\d+)", |
| 163 |
|
| 164 |
# Advanced operations |
| 165 |
"persistent_searches": r"^Persistent Searches:\s+(\d+)", |
| 166 |
"extended_ops": r"^Extended Operations:\s+(\d+)", |
| 167 |
"internal_ops": r"^Internal Operations:\s+(\d+)", |
| 168 |
"abandoned": r"^Abandoned Requests:\s+(\d+)", |
| 169 |
"proxied_auth_ops": r"^Proxied Auth Operations:\s+(\d+)", |
| 170 |
"vlv_operations": r"^VLV Operations:\s+(\d+)", |
| 171 |
"vlv_unindexed_searches": r"VLV Unindexed Searches:\s+(\d+)", |
| 172 |
"sort_operations": r"^SORT Operations:\s+(\d+)", |
| 173 |
"paged_searches": r"^Paged Searches:\s+(\d+)", |
| 174 |
|
| 175 |
# Errors and filter issues |
| 176 |
"invalid_attribute_filters": r"^Invalid Attribute Filters:\s+(\d+)", |
| 177 |
"broken_pipes": r"^Broken Pipes:\s+(\d+)", |
| 178 |
"connection_reset": r"^Connection Reset By Peer:\s+(\d+)", |
| 179 |
"resource_unavailable": r"^Resource Unavailable:\s+(\d+)", |
| 180 |
"max_ber_exceeded": r"^Max BER Size Exceeded:\s+(\d+)", |
| 181 |
|
| 182 |
# File descriptors |
| 183 |
"fds_taken": r"^FDs Taken:\s+(\d+)", |
| 184 |
"fds_returned": r"^FDs Returned:\s+(\d+)", |
| 185 |
"highest_fd_taken": r"^Highest FD Taken:\s+(\d+)", |
| 186 |
|
| 187 |
# Special cases |
| 188 |
"entire_search_base_queries": r"Entire Search Base Queries:\s+(\d+)", |
| 189 |
"unindexed_searches": r"^Unindexed Searches:\s+(\d+)", |
| 190 |
"unindexed_components": r"^Unindexed Components:\s+(\d+)", |
| 191 |
"multi_factor_auth": r"^Multi-factor Authentications:\s+(\d+)", |
| 192 |
"async_ops": r"^Asynchronous Operations:\s+(\d+)", |
| 193 |
"blocked_ops": r"^Blocked Operations:\s+(\d+)", |
| 194 |
"smart_referrals": r"^Smart Referrals Received:\s+(\d+)", |
| 195 |
} |
| 196 |
|
| 197 |
logconv_stats = {} |
| 198 |
for key, pattern in patterns.items(): |
| 199 |
match = re.search(pattern, output, re.IGNORECASE | re.MULTILINE) |
| 200 |
if match: |
| 201 |
value = match.group(1) |
| 202 |
try: |
| 203 |
logconv_stats[key] = float(value) if '.' in value else int(value) |
| 204 |
except (ValueError) as e: |
| 205 |
pytest.fail(f"Failed to parse value for {key}") |
| 206 |
|
| 207 |
return logconv_stats |
| 208 |
|
| 209 |
def run_logconv(self, debug_output=True): |
| 210 |
""" |
| 211 |
Run logconv on the access log and return its output. |
| 212 |
|
| 213 |
Args: |
| 214 |
debug_output (bool): If True, writes logconv output to a debug file. |
| 215 |
""" |
| 216 |
|
| 217 |
if not self.logconv_path: |
| 218 |
raise FileNotFoundError("logconv.py not found.") |
| 219 |
|
| 220 |
if not self.access_log_path: |
| 221 |
raise FileNotFoundError("access log not found.") |
| 222 |
|
| 223 |
try: |
| 224 |
result = subprocess.run( |
| 225 |
[self.logconv_path, self.access_log_path], |
| 226 |
capture_output=True, |
| 227 |
text=True |
| 228 |
) |
| 229 |
except Exception as e: |
| 230 |
raise RuntimeError(f"Failed to run logconv.py: {e}") |
| 231 |
|
| 232 |
if result.returncode != 0: |
| 233 |
raise RuntimeError(f"logconv.py exited with error: {result.stderr}") |
| 234 |
|
| 235 |
logconv_stats = result.stdout |
| 236 |
|
| 237 |
if debug_output: |
| 238 |
with open(self.debug_output, 'w') as f: |
| 239 |
f.write(logconv_stats) |
| 240 |
os.chmod(self.debug_output, 0o644) |
| 241 |
|
| 242 |
return logconv_stats |
| 243 |
|
| 244 |
def validate_logconv_stats(self, expected: dict, logconv_stats: dict, test_name=None): |
| 245 |
""" |
| 246 |
The comparison is loose, it passes once the actual counts are greater than or equal |
| 247 |
to the expected count. |
| 248 |
|
| 249 |
Args: |
| 250 |
expected: dict of expected exact counts |
| 251 |
logconv_stats: dict of key value stats from logconv |
| 252 |
test_name: string for logging |
| 253 |
""" |
| 254 |
IGNORE_KEYS = {"highest_fd_taken", "concurrent_conns"} |
| 255 |
|
| 256 |
errors = [] |
| 257 |
for key, existing_val in logconv_stats.items(): |
| 258 |
if key in IGNORE_KEYS: |
| 259 |
continue |
| 260 |
|
| 261 |
expected_val = expected.get(key, 0) |
| 262 |
if existing_val != expected_val: |
| 263 |
errors.append(f"{test_name} - {key}: expected {expected_val}, got {existing_val}") |
| 264 |
|
| 265 |
if errors: |
| 266 |
log.error("\n".join(errors)) |
| 267 |
return False |
| 268 |
|
| 269 |
return True |
| 270 |
|
| 271 |
def test_add(self, topo_shared): |
| 272 |
"""Validate add operation stats reported by logconv. |
| 273 |
|
| 274 |
:id: 7747b0e5-9dac-471a-bfb1-7b4dded6afa0 |
| 275 |
:setup: Standalone Instance |
| 276 |
:steps: |
| 277 |
1. Truncate access log |
| 278 |
2. Create 3 users |
| 279 |
3. Delete 3 user |
| 280 |
4. Run logconv |
| 281 |
5. Compare actual stats with expected |
| 282 |
:expectedresults: |
| 283 |
1. Success |
| 284 |
2. Success |
| 285 |
3. Success |
| 286 |
4. Success |
| 287 |
5. Actual stats match expected |
| 288 |
""" |
| 289 |
self.init_instance(topo_shared.standalone) |
| 290 |
self.truncate_logs() |
| 291 |
|
| 292 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 293 |
try: |
| 294 |
for idx in range(3): |
| 295 |
users.create_test_user(uid=str(idx), gid=str(idx)) |
| 296 |
except ldap.ALREADY_EXISTS as e: |
| 297 |
log.warning(f"_test_add_del - User already exists: {e}") |
| 298 |
|
| 299 |
for dn in users.list(): |
| 300 |
try: |
| 301 |
dn.delete() |
| 302 |
except Exception as e: |
| 303 |
log.warning(f"Failed to delete user: {e}") |
| 304 |
|
| 305 |
expected = { |
| 306 |
"adds": 3, |
| 307 |
"deletes": 3, |
| 308 |
"searches": 13, |
| 309 |
"operations": 19, |
| 310 |
"results": 19 |
| 311 |
} |
| 312 |
|
| 313 |
output = self.run_logconv() |
| 314 |
logconv_stats = self.extract_logconv_stats(output) |
| 315 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_add") |
| 316 |
|
| 317 |
def test_modify(self, topo_shared): |
| 318 |
"""Validate modify operation stats reported by logconv. |
| 319 |
|
| 320 |
:id: d5c37b3f-be79-47da-8ce3-051724f21e09 |
| 321 |
:setup: Standalone Instance |
| 322 |
:steps: |
| 323 |
1. Truncate access log |
| 324 |
2. Create a user |
| 325 |
3. Modify the userPassword attribute |
| 326 |
4. Delete the user |
| 327 |
5. Run logconv and compare stats |
| 328 |
:expectedresults: |
| 329 |
1. Success |
| 330 |
2. Success |
| 331 |
3. Success |
| 332 |
4. Success |
| 333 |
5. Actual stats match expected |
| 334 |
""" |
| 335 |
self.init_instance(topo_shared.standalone) |
| 336 |
self.truncate_logs() |
| 337 |
|
| 338 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 339 |
user = users.create_test_user(uid=1, gid=1) |
| 340 |
user.set("userPassword", "newpass") |
| 341 |
user.delete() |
| 342 |
|
| 343 |
expected = { |
| 344 |
"adds": 1, |
| 345 |
"mods": 1, |
| 346 |
"deletes": 1, |
| 347 |
"searches": 2, |
| 348 |
"operations": 5, |
| 349 |
"results": 5 |
| 350 |
} |
| 351 |
|
| 352 |
output = self.run_logconv() |
| 353 |
logconv_stats = self.extract_logconv_stats(output) |
| 354 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_modify") |
| 355 |
|
| 356 |
def test_modrdn(self, topo_shared): |
| 357 |
"""Validate MODRDN operation stats reported by logconv. |
| 358 |
|
| 359 |
:id: ded94158-d92a-4696-9d49-2fb5437cae26 |
| 360 |
:setup: Standalone Instance |
| 361 |
:steps: |
| 362 |
1. Truncate access log |
| 363 |
2. Create a user |
| 364 |
3. Rename the user's DN |
| 365 |
4. Delete the user |
| 366 |
5. Run logconv and compare stats |
| 367 |
:expectedresults: |
| 368 |
1. Success |
| 369 |
2. Success |
| 370 |
3. Success |
| 371 |
4. Success |
| 372 |
5. Actual stats match expected |
| 373 |
""" |
| 374 |
self.init_instance(topo_shared.standalone) |
| 375 |
self.truncate_logs() |
| 376 |
|
| 377 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 378 |
user = users.create_test_user(uid=1, gid=1) |
| 379 |
user.rename('uid=user_modrdn_renamed') |
| 380 |
user.delete() |
| 381 |
|
| 382 |
expected = { |
| 383 |
"adds": 1, |
| 384 |
"deletes": 1, |
| 385 |
"modrdns": 1, |
| 386 |
"searches": 3, |
| 387 |
"operations": 6, |
| 388 |
"results": 6 |
| 389 |
} |
| 390 |
|
| 391 |
output = self.run_logconv() |
| 392 |
logconv_stats = self.extract_logconv_stats(output) |
| 393 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_modrdn") |
| 394 |
|
| 395 |
|
| 396 |
def test_compare(self, topo_shared): |
| 397 |
"""Validate compare operation stats reported by logconv. |
| 398 |
|
| 399 |
:id: 0c874c9a-21bb-41a9-a6dd-e4ae77a24bfa |
| 400 |
:setup: Standalone Instance |
| 401 |
:steps: |
| 402 |
1. Truncate access log |
| 403 |
2. Create a user |
| 404 |
3. Perform compare on 'cn' attribute |
| 405 |
4. Delete the user |
| 406 |
5. Run logconv and compare stats |
| 407 |
:expectedresults: |
| 408 |
1. Success |
| 409 |
2. Success |
| 410 |
3. Success |
| 411 |
4. Success |
| 412 |
5. Actual stats match expected |
| 413 |
""" |
| 414 |
self.init_instance(topo_shared.standalone) |
| 415 |
self.truncate_logs() |
| 416 |
|
| 417 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 418 |
user = users.create_test_user(uid=1, gid=1) |
| 419 |
self.inst.compare_ext_s(user.dn, 'cn', b'compare') |
| 420 |
user.delete() |
| 421 |
|
| 422 |
expected = { |
| 423 |
"adds": 1, |
| 424 |
"deletes": 1, |
| 425 |
"compares": 1, |
| 426 |
"searches": 2, |
| 427 |
"operations": 5, |
| 428 |
"results": 5 |
| 429 |
} |
| 430 |
|
| 431 |
output = self.run_logconv() |
| 432 |
logconv_stats = self.extract_logconv_stats(output) |
| 433 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_compare") |
| 434 |
|
| 435 |
def test_search(self, topo_shared): |
| 436 |
"""Validate basic search operation stats reported by logconv. |
| 437 |
|
| 438 |
:id: e81e2b0b-0c67-4ba0-8dff-2371a3f91546 |
| 439 |
:setup: Standalone Instance |
| 440 |
:steps: |
| 441 |
1. Truncate access log |
| 442 |
2. Perform subtree search for non existent uid |
| 443 |
3. Run logconv and compare stats |
| 444 |
:expectedresults: |
| 445 |
1. Success |
| 446 |
2. Success |
| 447 |
3. Actual stats match expected |
| 448 |
""" |
| 449 |
self.init_instance(topo_shared.standalone) |
| 450 |
self.truncate_logs() |
| 451 |
|
| 452 |
try: |
| 453 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=findmeifucan)') |
| 454 |
except ldap.LDAPError as e: |
| 455 |
log.error('Search failed on {}'.format(DEFAULT_SUFFIX)) |
| 456 |
raise e |
| 457 |
|
| 458 |
expected = { |
| 459 |
"searches": 1, |
| 460 |
"operations": 1, |
| 461 |
"results": 1 |
| 462 |
} |
| 463 |
|
| 464 |
output = self.run_logconv() |
| 465 |
logconv_stats = self.extract_logconv_stats(output) |
| 466 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_search") |
| 467 |
|
| 468 |
def test_internal_ops(self, topo_shared): |
| 469 |
"""Validate internal operation stats reported by logconv. |
| 470 |
|
| 471 |
:id: 631ba514-349d-49f6-961e-a6fca3071cf3 |
| 472 |
:setup: Standalone Instance |
| 473 |
:steps: |
| 474 |
1. Truncate access log |
| 475 |
2. Modify access log config, resulting in internal ops |
| 476 |
3. Run logconv and compare stats |
| 477 |
:expectedresults: |
| 478 |
1. Success |
| 479 |
2. Success |
| 480 |
3. Actual stats match expected |
| 481 |
""" |
| 482 |
self.init_instance(topo_shared.standalone) |
| 483 |
self.truncate_logs() |
| 484 |
|
| 485 |
default_log_level = self.inst.config.get_attr_val_utf8(LOG_ACCESS_LEVEL) |
| 486 |
access_log_level = '4' |
| 487 |
self.inst.config.set(LOG_ACCESS_LEVEL, access_log_level) |
| 488 |
self.inst.config.set('nsslapd-plugin-logging', 'on') |
| 489 |
self.inst.config.set(LOG_ACCESS_LEVEL, default_log_level) |
| 490 |
self.inst.config.set('nsslapd-plugin-logging', 'off') |
| 491 |
|
| 492 |
expected = { |
| 493 |
"internal_ops": 2, |
| 494 |
"mods": 2, |
| 495 |
"searches": 3, |
| 496 |
"operations": 5, |
| 497 |
"results": 5, |
| 498 |
} |
| 499 |
|
| 500 |
output = self.run_logconv() |
| 501 |
logconv_stats = self.extract_logconv_stats(output) |
| 502 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_internal_ops") |
| 503 |
|
| 504 |
def test_base_search(self, topo_shared): |
| 505 |
"""Validate base search operation stats reported by logconv. |
| 506 |
|
| 507 |
:id: d7557ef2-582c-42bb-a9ee-ded0680ba707 |
| 508 |
:setup: Standalone Instance |
| 509 |
:steps: |
| 510 |
1. Truncate access log |
| 511 |
2. Run a base search |
| 512 |
3. Run logconv and compare stats |
| 513 |
:expectedresults: |
| 514 |
1. Success |
| 515 |
2. Success |
| 516 |
3. Actual stats match expected |
| 517 |
""" |
| 518 |
self.init_instance(topo_shared.standalone) |
| 519 |
self.truncate_logs() |
| 520 |
|
| 521 |
try: |
| 522 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(objectclass=top)', ['dn']) |
| 523 |
except ldap.LDAPError as e: |
| 524 |
log.error('Search failed on {}'.format(DEFAULT_SUFFIX)) |
| 525 |
raise e |
| 526 |
|
| 527 |
expected = { |
| 528 |
"searches": 1, |
| 529 |
"operations": 1, |
| 530 |
"entire_search_base_queries": 1, |
| 531 |
"results": 1 |
| 532 |
} |
| 533 |
|
| 534 |
output = self.run_logconv() |
| 535 |
logconv_stats = self.extract_logconv_stats(output) |
| 536 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_base_search") |
| 537 |
|
| 538 |
def test_paged_search(self, topo_shared): |
| 539 |
"""Validate paged search operation stats reported by logconv. |
| 540 |
|
| 541 |
:id: 729cb831-bcbe-4f88-8f42-12be5c48b5e6 |
| 542 |
:setup: Standalone Instance |
| 543 |
:steps: |
| 544 |
1. Truncate access log |
| 545 |
2. Run a paged search |
| 546 |
3. Run logconv and compare stats |
| 547 |
:expectedresults: |
| 548 |
1. Success |
| 549 |
2. Success |
| 550 |
3. Actual stats match expected |
| 551 |
""" |
| 552 |
self.init_instance(topo_shared.standalone) |
| 553 |
self.truncate_logs() |
| 554 |
|
| 555 |
req_ctrl = SimplePagedResultsControl(True, size=3, cookie='') |
| 556 |
try: |
| 557 |
self.inst.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "sn=user_*", ['cn'], serverctrls=[req_ctrl]) |
| 558 |
except ldap.LDAPError as e: |
| 559 |
log.error('Search failed on {}'.format(DEFAULT_SUFFIX)) |
| 560 |
raise e |
| 561 |
|
| 562 |
# Need to wait a little here |
| 563 |
time.sleep(2) |
| 564 |
|
| 565 |
expected = { |
| 566 |
"searches": 1, |
| 567 |
"operations": 1, |
| 568 |
"paged_searches": 1, |
| 569 |
"results": 1 |
| 570 |
} |
| 571 |
|
| 572 |
output = self.run_logconv() |
| 573 |
logconv_stats = self.extract_logconv_stats(output) |
| 574 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_paged_search") |
| 575 |
|
| 576 |
def test_persistent_search(self, topo_shared): |
| 577 |
"""Validate persistent search operation stats reported by logconv. |
| 578 |
|
| 579 |
:id: a0552c17-d70a-4fe2-b4af-9292d4862da6 |
| 580 |
:setup: Standalone Instance |
| 581 |
:steps: |
| 582 |
1. Truncate access log |
| 583 |
2. Run a persistent search |
| 584 |
3. Run logconv and compare stats |
| 585 |
:expectedresults: |
| 586 |
1. Success |
| 587 |
2. Success |
| 588 |
3. Actual stats match expected |
| 589 |
""" |
| 590 |
self.init_instance(topo_shared.standalone) |
| 591 |
self.truncate_logs() |
| 592 |
|
| 593 |
psc = PersistentSearchControl() |
| 594 |
|
| 595 |
msgid = self.inst.search_ext( |
| 596 |
base=DEFAULT_SUFFIX, |
| 597 |
scope=ldap.SCOPE_ONELEVEL, |
| 598 |
filterstr='(objectClass=person)', |
| 599 |
attrlist=['uid'], |
| 600 |
serverctrls=[psc] |
| 601 |
) |
| 602 |
|
| 603 |
expected = { |
| 604 |
"searches": 1, |
| 605 |
"persistent_searches": 1, |
| 606 |
"operations": 1, |
| 607 |
} |
| 608 |
|
| 609 |
time.sleep(2) |
| 610 |
output = self.run_logconv() |
| 611 |
logconv_stats = self.extract_logconv_stats(output) |
| 612 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_persistent_search") |
| 613 |
|
| 614 |
|
| 615 |
def test_simple_bind(self, topo_shared): |
| 616 |
"""Validate simple bind operation stats reported by logconv. |
| 617 |
|
| 618 |
:id: 20d5244a-3cda-434f-9957-062aaa88e66f |
| 619 |
:setup: Standalone Instance |
| 620 |
:steps: |
| 621 |
1. Truncate access log |
| 622 |
2. Create a user and set password |
| 623 |
3. Perform a simple bind and unbind |
| 624 |
4. Delete user |
| 625 |
5. Run logconv and compare stats |
| 626 |
:expectedresults: |
| 627 |
1. Success |
| 628 |
2. Success |
| 629 |
3. Success |
| 630 |
4. Success |
| 631 |
5. Actual stats match expected |
| 632 |
""" |
| 633 |
self.init_instance(topo_shared.standalone) |
| 634 |
self.truncate_logs() |
| 635 |
|
| 636 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 637 |
user = users.create_test_user(uid=1, gid=1) |
| 638 |
user.set("userPassword", "password") |
| 639 |
|
| 640 |
conn = ldap.initialize("ldap://%s:%s" % (HOST_STANDALONE, PORT_STANDALONE)) |
| 641 |
conn.simple_bind_s(user.dn, "password") |
| 642 |
conn.unbind_s() |
| 643 |
user.delete() |
| 644 |
|
| 645 |
expected = { |
| 646 |
"adds": 1, |
| 647 |
"mods": 1, |
| 648 |
"deletes": 1, |
| 649 |
"binds": 1, |
| 650 |
"unbinds": 1, |
| 651 |
"searches": 2, |
| 652 |
"operations": 6, |
| 653 |
"results": 6, |
| 654 |
"total_connections": 1, |
| 655 |
"concurrent_conns": 1, |
| 656 |
"ldap_conns": 1, |
| 657 |
"fds_taken": 1, |
| 658 |
"fds_returned": 1 |
| 659 |
} |
| 660 |
|
| 661 |
output = self.run_logconv() |
| 662 |
logconv_stats = self.extract_logconv_stats(output) |
| 663 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_simple_bind") |
| 664 |
|
| 665 |
def test_anon_bind(self, topo_shared): |
| 666 |
"""Validate anonymous bind operation stats reported by logconv. |
| 667 |
|
| 668 |
:id: 893b8388-4a6b-4434-89ce-f93e518eff9d |
| 669 |
:setup: Standalone Instance |
| 670 |
:steps: |
| 671 |
1. Truncate access log |
| 672 |
2. Perform an anonymous bind and unbind |
| 673 |
3. Run logconv and compare stats |
| 674 |
:expectedresults: |
| 675 |
1. Success |
| 676 |
2. Success |
| 677 |
3. Actual stats match expected |
| 678 |
""" |
| 679 |
self.init_instance(topo_shared.standalone) |
| 680 |
self.truncate_logs() |
| 681 |
|
| 682 |
conn = Anonymous(self.inst).bind() |
| 683 |
conn.unbind() |
| 684 |
|
| 685 |
expected = { |
| 686 |
"binds": 1, |
| 687 |
"unbinds": 1, |
| 688 |
"anon_binds": 1, |
| 689 |
"searches": 1, |
| 690 |
"operations": 2, |
| 691 |
"results": 2, |
| 692 |
"ldap_conns": 1, |
| 693 |
"concurrent_conns": 1, |
| 694 |
"total_connections": 1, |
| 695 |
"fds_taken": 1, |
| 696 |
"fds_returned": 1 |
| 697 |
} |
| 698 |
|
| 699 |
time.sleep(2) |
| 700 |
output = self.run_logconv() |
| 701 |
logconv_stats = self.extract_logconv_stats(output) |
| 702 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_anon_bind") |
| 703 |
|
| 704 |
def test_ldapi(self, topo_shared): |
| 705 |
"""Validate ldapi operation stats reported by logconv. |
| 706 |
|
| 707 |
Note: |
| 708 |
adjust_expected_for_backend() is used to account for backend specific |
| 709 |
extra operations. |
| 710 |
|
| 711 |
:id: 169545bc-cd1e-477a-bd73-3d593cb1ff98 |
| 712 |
:setup: Standalone Instance |
| 713 |
:steps: |
| 714 |
1. Truncate access log |
| 715 |
2. Configure ldapi |
| 716 |
3. Restart instance for config to take effect |
| 717 |
4. Run an ldapi search |
| 718 |
5. Run logconv and compare stats |
| 719 |
:expectedresults: |
| 720 |
1. Success |
| 721 |
2. Success |
| 722 |
3. Success |
| 723 |
4. Success |
| 724 |
5. Actual stats match expected |
| 725 |
""" |
| 726 |
self.init_instance(topo_shared.standalone) |
| 727 |
self.truncate_logs() |
| 728 |
|
| 729 |
self.inst.config.set('nsslapd-ldapilisten', 'on') |
| 730 |
self.inst.config.set('nsslapd-ldapiautobind', 'on') |
| 731 |
self.inst.config.set('nsslapd-ldapifilepath', f'{PREFIX}/var/run/slapd-{self.inst.serverid}.socket') |
| 732 |
|
| 733 |
expected = { |
| 734 |
"mods": 3, |
| 735 |
"autobinds": 1, |
| 736 |
"sasl_binds": 1, |
| 737 |
"binds": 3, |
| 738 |
"unbinds": 1, |
| 739 |
"searches": 2, |
| 740 |
"operations": 8, |
| 741 |
"results": 7, |
| 742 |
"entire_search_base_queries": 1, |
| 743 |
"unindexed_components": 1, |
| 744 |
"ldap_conns": 1, |
| 745 |
"ldapi_conns": 1, |
| 746 |
"concurrent_conns": 1, |
| 747 |
"total_connections": 2, |
| 748 |
"fds_taken": 2, |
| 749 |
"fds_returned": 2, |
| 750 |
"restarts": 1 |
| 751 |
} |
| 752 |
self.inst.restart() |
| 753 |
# Adjust expected for BDB restart |
| 754 |
expected = adjust_expected_for_backend(self, expected) |
| 755 |
|
| 756 |
ldapi_socket = self.inst.config.get_attr_val_utf8('nsslapd-ldapifilepath').replace('/', '%2F') |
| 757 |
cmd = [ |
| 758 |
"ldapsearch", |
| 759 |
"-H", f"ldapi://{ldapi_socket}", |
| 760 |
"-Y", "EXTERNAL", |
| 761 |
"-b", "dc=example,dc=com" |
| 762 |
] |
| 763 |
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 764 |
|
| 765 |
time.sleep(2) |
| 766 |
output = self.run_logconv() |
| 767 |
logconv_stats = self.extract_logconv_stats(output) |
| 768 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_ldapi") |
| 769 |
|
| 770 |
def test_restart(self, topo_shared): |
| 771 |
"""Validate restart stats reported by logconv. |
| 772 |
|
| 773 |
Note: |
| 774 |
adjust_expected_for_backend() is used to account for backend specific |
| 775 |
extra operations. |
| 776 |
|
| 777 |
:id: 1c98b6da-d37b-48f5-ae36-72c62ddccdb1 |
| 778 |
:setup: Standalone Instance |
| 779 |
:steps: |
| 780 |
1. Truncate access log |
| 781 |
2. Restart instance twice |
| 782 |
3. Run logconv and compare stats |
| 783 |
:expectedresults: |
| 784 |
1. Success |
| 785 |
2. Success |
| 786 |
3. Actual stats match expected |
| 787 |
""" |
| 788 |
self.init_instance(topo_shared.standalone) |
| 789 |
self.truncate_logs() |
| 790 |
|
| 791 |
expected = { |
| 792 |
"binds": 2, |
| 793 |
"operations": 2, |
| 794 |
"results": 2, |
| 795 |
"ldap_conns": 2, |
| 796 |
"total_connections": 2, |
| 797 |
"fds_taken": 2, |
| 798 |
"fds_returned": 2, |
| 799 |
"restarts": 2 |
| 800 |
} |
| 801 |
|
| 802 |
self.inst.restart() |
| 803 |
self.inst.restart() |
| 804 |
# Adjust expected for BDB restarts |
| 805 |
expected = adjust_expected_for_backend(self, expected) |
| 806 |
expected = adjust_expected_for_backend(self, expected) |
| 807 |
|
| 808 |
output = self.run_logconv() |
| 809 |
logconv_stats = self.extract_logconv_stats(output) |
| 810 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_restart") |
| 811 |
|
| 812 |
def test_invalid_filter(self, topo_shared): |
| 813 |
"""Validate invalid filter search stats reported by logconv. |
| 814 |
|
| 815 |
:id: c2d9c082-eaf5-4eba-a977-c28d3f02d51f |
| 816 |
:setup: Standalone Instance |
| 817 |
:steps: |
| 818 |
1. Truncate access log |
| 819 |
2. Run a search with a filter that doesnt exist |
| 820 |
3. Run logconv and compare stats |
| 821 |
:expectedresults: |
| 822 |
1. Success |
| 823 |
2. SUccess |
| 824 |
3. Actual stats match expected |
| 825 |
""" |
| 826 |
self.init_instance(topo_shared.standalone) |
| 827 |
self.truncate_logs() |
| 828 |
|
| 829 |
self.inst.search_ext_s( |
| 830 |
base=DEFAULT_SUFFIX, |
| 831 |
scope=ldap.SCOPE_SUBTREE, |
| 832 |
filterstr='(idontexist=*)', |
| 833 |
) |
| 834 |
|
| 835 |
expected = { |
| 836 |
"invalid_attribute_filters": 1, |
| 837 |
"searches": 1, |
| 838 |
"operations": 1, |
| 839 |
"results": 1 |
| 840 |
} |
| 841 |
|
| 842 |
output = self.run_logconv() |
| 843 |
logconv_stats = self.extract_logconv_stats(output) |
| 844 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_invalid_filter") |
| 845 |
|
| 846 |
def test_partially_unindexed_vlv_sort(self, topo_shared): |
| 847 |
"""Validate an unindexed VLV search + sort stats reported by logconv. |
| 848 |
|
| 849 |
:id: 88af0fcc-d351-4ad2-8be9-8adcb0bd6bf0 |
| 850 |
:setup: Standalone Instance |
| 851 |
:steps: |
| 852 |
1. Truncate access log |
| 853 |
2. Configure VLV and SSS request controls |
| 854 |
3. Run an unindexed search |
| 855 |
4. Run logconv and compare stats |
| 856 |
:expectedresults: |
| 857 |
1. Success |
| 858 |
2. SUccess |
| 859 |
3. SUccess |
| 860 |
4. Actual stats match expected |
| 861 |
""" |
| 862 |
self.init_instance(topo_shared.standalone) |
| 863 |
self.truncate_logs() |
| 864 |
|
| 865 |
vlv_control = VLVRequestControl( |
| 866 |
criticality=True, |
| 867 |
before_count="1", |
| 868 |
after_count="3", |
| 869 |
offset="5", |
| 870 |
content_count=0, |
| 871 |
greater_than_or_equal=None, |
| 872 |
context_id=None |
| 873 |
) |
| 874 |
sss_control = SSSRequestControl(criticality=True, ordering_rules=['givenName']) |
| 875 |
|
| 876 |
self.inst.search_ext_s( |
| 877 |
base=DEFAULT_SUFFIX, |
| 878 |
scope=ldap.SCOPE_SUBTREE, |
| 879 |
filterstr='(givenName=*)', |
| 880 |
serverctrls=[vlv_control, sss_control] |
| 881 |
) |
| 882 |
|
| 883 |
expected = { |
| 884 |
"vlv_operations": 1, |
| 885 |
"sort_operations": 1, |
| 886 |
"searches": 1, |
| 887 |
"unindexed_components": 0, |
| 888 |
"operations": 2, |
| 889 |
"results": 1 |
| 890 |
} |
| 891 |
|
| 892 |
output = self.run_logconv() |
| 893 |
logconv_stats = self.extract_logconv_stats(output) |
| 894 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_partially_unindexed_vlv_sort") |
| 895 |
|
| 896 |
def test_fully_unindexed_search(self, topo_shared): |
| 897 |
"""Validate an unindexed VLV search stats reported by logconv. |
| 898 |
|
| 899 |
:id: 93d5a42e-ed78-4257-ba8c-f54a14d95b94 |
| 900 |
:setup: Standalone Instance |
| 901 |
:steps: |
| 902 |
1. Truncate access log |
| 903 |
2. Lower idlistscanlimit to force unindexed search |
| 904 |
3. Create 10 test users |
| 905 |
4. Perform a search triggering unindexed search |
| 906 |
5. Restore idlistscanlimit and delete users |
| 907 |
6. Run logconv and compare stats |
| 908 |
:expectedresults: |
| 909 |
1. Success |
| 910 |
2. Success |
| 911 |
3. Success |
| 912 |
4. Success |
| 913 |
5. Success |
| 914 |
6. Actual stats match expected |
| 915 |
""" |
| 916 |
self.init_instance(topo_shared.standalone) |
| 917 |
self.truncate_logs() |
| 918 |
|
| 919 |
# Force an unindexed search |
| 920 |
db_cfg = DatabaseConfig(self.inst) |
| 921 |
default_idlistscanlimit = db_cfg.get_attr_vals_utf8('nsslapd-idlistscanlimit') |
| 922 |
db_cfg.set([('nsslapd-idlistscanlimit', '100')]) |
| 923 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 924 |
for i in range(10): |
| 925 |
users.create_test_user(uid=i) |
| 926 |
raw_objects = DSLdapObjects(self.inst, basedn=DEFAULT_SUFFIX) |
| 927 |
raw_objects.filter("(description=test*)") |
| 928 |
db_cfg.set([('nsslapd-idlistscanlimit', default_idlistscanlimit)]) |
| 929 |
|
| 930 |
for dn in users.list(): |
| 931 |
try: |
| 932 |
dn.delete() |
| 933 |
except Exception as e: |
| 934 |
log.warning(f"Failed to delete user: {e}") |
| 935 |
|
| 936 |
expected = { |
| 937 |
"mods": 2, |
| 938 |
"adds": 10, |
| 939 |
"deletes": 10, |
| 940 |
"searches": 44, |
| 941 |
"unindexed_components": 1, |
| 942 |
"operations": 66, |
| 943 |
"results": 66, |
| 944 |
} |
| 945 |
|
| 946 |
output = self.run_logconv() |
| 947 |
logconv_stats = self.extract_logconv_stats(output) |
| 948 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_fully_unindexed_search") |
| 949 |
|
| 950 |
def test_starttls(self, topo_shared): |
| 951 |
"""Validate an starttls operation stats reported by logconv. |
| 952 |
|
| 953 |
:id: 3e76cd43-0a20-4a7b-854c-5292571be8a6 |
| 954 |
:setup: Standalone Instance |
| 955 |
:steps: |
| 956 |
1. Truncate access log |
| 957 |
2. Run a search with starttls flag enabled |
| 958 |
3. Run logconv and compare stats |
| 959 |
:expectedresults: |
| 960 |
1. Success |
| 961 |
2. Success |
| 962 |
3. Actual stats match expected |
| 963 |
""" |
| 964 |
self.init_instance(topo_shared.standalone) |
| 965 |
self.truncate_logs() |
| 966 |
|
| 967 |
cmd = [ |
| 968 |
"ldapsearch", |
| 969 |
"-x", |
| 970 |
"-H", f"ldap://localhost:{self.inst.port}", |
| 971 |
"-Z", |
| 972 |
"-D", "cn=Directory Manager", |
| 973 |
"-w", "password", |
| 974 |
"-b", DEFAULT_SUFFIX, |
| 975 |
"(objectclass=*)" |
| 976 |
] |
| 977 |
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 978 |
|
| 979 |
expected = { |
| 980 |
"binds": 1, |
| 981 |
"unbinds": 1, |
| 982 |
"searches": 1, |
| 983 |
"entire_search_base_queries": 1, |
| 984 |
"unindexed_components": 1, |
| 985 |
"starttls_conns": 1, |
| 986 |
"extended_ops": 1, |
| 987 |
"operations": 3, |
| 988 |
"results": 3, |
| 989 |
"ldap_conns": 1, |
| 990 |
"total_connections": 1, |
| 991 |
"fds_taken": 1, |
| 992 |
"fds_returned": 1, |
| 993 |
} |
| 994 |
|
| 995 |
time.sleep(4) |
| 996 |
output = self.run_logconv() |
| 997 |
logconv_stats = self.extract_logconv_stats(output) |
| 998 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_starttls") |
| 999 |
|
| 1000 |
def test_missing_access_log(self, topo_shared): |
| 1001 |
"""Validate behavior when access log path is invalid. |
| 1002 |
|
| 1003 |
:id: 2ea0230b-6a12-4a41-ac7f-6c42862c9095 |
| 1004 |
:setup: Standalone Instance |
| 1005 |
:steps: |
| 1006 |
1. Set access log path to an invalid location |
| 1007 |
2. Run logconv |
| 1008 |
:expectedresults: |
| 1009 |
1. Success |
| 1010 |
2. RuntimeError is raised |
| 1011 |
""" |
| 1012 |
self.init_instance(topo_shared.standalone) |
| 1013 |
orig_access_log_path = self.access_log_path |
| 1014 |
self.access_log_path = "somewhereovertherainbow" |
| 1015 |
try: |
| 1016 |
with pytest.raises(RuntimeError): |
| 1017 |
self.run_logconv() |
| 1018 |
|
| 1019 |
finally: |
| 1020 |
self.access_log_path = orig_access_log_path |
| 1021 |
|
| 1022 |
def test_invalid_access_log_format(self, topo_shared): |
| 1023 |
"""Validate logconv handles malformed or mixed format logs. |
| 1024 |
|
| 1025 |
:id: a7fae8d1-0400-44f6-ba61-fbd04c0f0bca |
| 1026 |
:setup: Standalone Instance |
| 1027 |
:steps: |
| 1028 |
1. Truncate access log |
| 1029 |
2. Inject invalid and mixed format entries |
| 1030 |
3. Run logconv and compare stats |
| 1031 |
:expectedresults: |
| 1032 |
1. Success |
| 1033 |
2. SUccess |
| 1034 |
3. Actual stats match expected |
| 1035 |
""" |
| 1036 |
self.init_instance(topo_shared.standalone) |
| 1037 |
self.truncate_logs() |
| 1038 |
|
| 1039 |
lines = [ |
| 1040 |
"[what do you mean im not an access log]\n", |
| 1041 |
"!!!@@@###$$$%%%^^^&&&***((()))\n", |
| 1042 |
"1234567890abcdefg!@#$%^&*()_+\n", |
| 1043 |
"???????/////\\\\\\\\\\|||||;;;;;\n", |
| 1044 |
"2025-07-28 20:53:16.818100+00:00 Something weird happened here\n", |
| 1045 |
"ERROR [2025-07-28] Unexpected token < in JSON at position 0\n", |
| 1046 |
"NULL NULL NULL NULL NULL NULL\n", |
| 1047 |
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\n", |
| 1048 |
"[28/Jul/2025:23:35:34.122912055 +0000] conn=1 op=7 SRCH base=\"dc=example,dc=com\" scope=2 filter=\"(idontexist=*)\" attrs=ALL\n", |
| 1049 |
"[28/Jul/2025:23:35:34.188751644 +0000] conn=1 op=7 RESULT err=0 tag=101 nentries=0 wtime=0.000131574 optime=0.065835295 etime=0.065964499 notes=F details=\"Filter Element Missing From Schema\" - Invalid attribute in filter - results may not be complete.\n", |
| 1050 |
"{\"local_time\":\"2025-07-28T23:41:31.354305288 +0000\",\"operation\":\"SEARCH\",\"key\":\"1753746090-1\",\"conn_id\":1,\"op_id\":7,\"base_dn\":\"dc=example,dc=com\",\"scope\":2,\"filter\":\"(idontexist=*)\"}\n", |
| 1051 |
"{\"local_time\":\"2025-07-28T23:41:31.435371287 +0000\",\"operation\":\"RESULT\",\"key\":\"1753746090-1\",\"conn_id\":1,\"op_id\":7,\"msg\":\" - Invalid attribute in filter - results may not be complete.\",\"tag\":101,\"err\":0,\"nentries\":0,\"wtime\":\"0.000200687\",\"optime\":\"0.081066609\",\"etime\":\"0.081264698\",\"client_ip\":\"127.0.0.1\",\"notes\":[{\"note\":\"F\",\"description\":\"Filter Element Missing From Schema\",\"filter\":\"(idontexist=*)\"}]}\n", |
| 1052 |
"{\"local_time\":\"2025-07-28T23:55:11.618760703 +0000\",\"operation\":\"ADD\",\"key\":\"1753746910-1\",\"conn_id\":1,\"op_id\":9,\"target_dn\":\"uid=test_user_1,ou=People,dc=example,dc=com\"}\n", |
| 1053 |
"{\"local_time\":\"2025-07-28T23:55:11.805266683 +0000\",\"operation\":\"RESULT\",\"key\":\"1753746910-1\",\"conn_id\":1,\"op_id\":9,\"msg\":\"\",\"tag\":105,\"err\":0,\"nentries\":0,\"wtime\":\"0.000128994\",\"optime\":\"0.186508623\",\"etime\":\"0.186634117\",\"client_ip\":\"127.0.0.1\"}\n", |
| 1054 |
"{\"local_time\":\"2025-07-28T23:55:11.805818046 +0000\",\"operation\":\"MODRDN\",\"key\":\"1753746910-1\",\"conn_id\":1,\"op_id\":10,\"target_dn\":\"uid=test_user_1,ou=People,dc=example,dc=com\",\"newrdn\":\"uid=user_modrdn_renamed\",\"deleteoldrdn\":true}\n", |
| 1055 |
"{\"local_time\":\"2025-07-28T23:55:12.049130196 +0000\",\"operation\":\"RESULT\",\"key\":\"1753746910-1\",\"conn_id\":1,\"op_id\":10,\"msg\":\"\",\"tag\":109,\"err\":0,\"nentries\":0,\"wtime\":\"0.000127592\",\"optime\":\"0.243312815\",\"etime\":\"0.243438839\",\"client_ip\":\"127.0.0.1\"}\n" |
| 1056 |
] |
| 1057 |
|
| 1058 |
with open(self.access_log_path, "w") as f: |
| 1059 |
for line in lines: |
| 1060 |
f.write(line) |
| 1061 |
|
| 1062 |
expected = { |
| 1063 |
"searches": 2, |
| 1064 |
"adds": 1, |
| 1065 |
"modrdns": 1, |
| 1066 |
"operations": 4, |
| 1067 |
"results": 4, |
| 1068 |
"invalid_attribute_filters": 2 |
| 1069 |
} |
| 1070 |
|
| 1071 |
output = self.run_logconv() |
| 1072 |
logconv_stats = self.extract_logconv_stats(output) |
| 1073 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_invalid_access_log_format") |
| 1074 |
|
| 1075 |
def test_ldaps(self, topo_single_use): |
| 1076 |
"""Validate LDAPS and certificate-based bind stats reported by logconv. |
| 1077 |
|
| 1078 |
Note: |
| 1079 |
adjust_expected_for_backend() is used to account for backend specific |
| 1080 |
extra operations. |
| 1081 |
|
| 1082 |
:id: e14e5b57-87fe-4b72-b787-b987a62b8ee9 |
| 1083 |
:setup: Standalone Instance with TLS enabled |
| 1084 |
:steps: |
| 1085 |
1. Truncate access log |
| 1086 |
2. Enable TLS and configure certificate-based binds |
| 1087 |
3. Perform SASL EXTERNAL bind with correct and incorrect certs |
| 1088 |
4. Run logconv and compare stats |
| 1089 |
:expectedresults: |
| 1090 |
1. Success |
| 1091 |
2. Success |
| 1092 |
3. Success |
| 1093 |
4. Actual stats match expected |
| 1094 |
""" |
| 1095 |
self.init_instance(topo_single_use.standalone) |
| 1096 |
self.truncate_logs() |
| 1097 |
|
| 1098 |
RDN_TEST_USER = 'testuser' |
| 1099 |
RDN_TEST_USER_WRONG = 'testuser_wrong' |
| 1100 |
|
| 1101 |
expected = { |
| 1102 |
"mods": 2, |
| 1103 |
"adds": 1, |
| 1104 |
"binds": 4, |
| 1105 |
"sasl_binds": 2, |
| 1106 |
"searches": 6, |
| 1107 |
"operations": 13, |
| 1108 |
"results": 13, |
| 1109 |
"unbinds": 1, |
| 1110 |
"ldaps_conns": 4, |
| 1111 |
"ssl_client_binds": 1, |
| 1112 |
"ssl_client_bind_failed": 1, |
| 1113 |
"total_connections": 4, |
| 1114 |
"fds_taken": 4, |
| 1115 |
"fds_returned": 4, |
| 1116 |
"restarts": 3 |
| 1117 |
} |
| 1118 |
self.inst.enable_tls() |
| 1119 |
# Adjust expected for BDB, enable_tls() implicit restart |
| 1120 |
expected = adjust_expected_for_backend(self, expected) |
| 1121 |
|
| 1122 |
users = UserAccounts(self.inst, DEFAULT_SUFFIX) |
| 1123 |
user = users.create(properties={ |
| 1124 |
'uid': RDN_TEST_USER, |
| 1125 |
'cn': RDN_TEST_USER, |
| 1126 |
'sn': RDN_TEST_USER, |
| 1127 |
'uidNumber': '1000', |
| 1128 |
'gidNumber': '2000', |
| 1129 |
'homeDirectory': f'/home/{RDN_TEST_USER}' |
| 1130 |
}) |
| 1131 |
|
| 1132 |
ssca_dir = self.inst.get_ssca_dir() |
| 1133 |
ssca = NssSsl(dbpath=ssca_dir) |
| 1134 |
ssca.create_rsa_user(RDN_TEST_USER) |
| 1135 |
ssca.create_rsa_user(RDN_TEST_USER_WRONG) |
| 1136 |
|
| 1137 |
# Get the details of where the key and crt are. |
| 1138 |
tls_locs = ssca.get_rsa_user(RDN_TEST_USER) |
| 1139 |
tls_locs_wrong = ssca.get_rsa_user(RDN_TEST_USER_WRONG) |
| 1140 |
|
| 1141 |
user.enroll_certificate(tls_locs['crt_der_path']) |
| 1142 |
|
| 1143 |
# Turn on the certmap. |
| 1144 |
cm = CertmapLegacy(self.inst) |
| 1145 |
certmaps = cm.list() |
| 1146 |
certmaps['default']['DNComps'] = '' |
| 1147 |
certmaps['default']['FilterComps'] = ['cn'] |
| 1148 |
certmaps['default']['VerifyCert'] = 'off' |
| 1149 |
cm.set(certmaps) |
| 1150 |
|
| 1151 |
# Check that EXTERNAL is listed in supported mechns. |
| 1152 |
assert (self.inst.rootdse.supports_sasl_external()) |
| 1153 |
|
| 1154 |
# Restart to allow certmaps to be re-read: Note, we CAN NOT use post_open |
| 1155 |
# here, it breaks on auth. see lib389/__init__.py |
| 1156 |
self.inst.restart(post_open=False) |
| 1157 |
# Adjust expected for BDB restart |
| 1158 |
expected = adjust_expected_for_backend(self, expected) |
| 1159 |
|
| 1160 |
# Attempt a bind with TLS external |
| 1161 |
self.inst.open(saslmethod='EXTERNAL', connOnly=True, certdir=ssca_dir, |
| 1162 |
userkey=tls_locs['key'], usercert=tls_locs['crt']) |
| 1163 |
|
| 1164 |
self.inst.restart() |
| 1165 |
# Adjust expected for BDB restart |
| 1166 |
expected = adjust_expected_for_backend(self, expected) |
| 1167 |
|
| 1168 |
# Check for failed certmap error |
| 1169 |
with pytest.raises(ldap.INVALID_CREDENTIALS): |
| 1170 |
self.inst.open(saslmethod='EXTERNAL', connOnly=True, certdir=ssca_dir, |
| 1171 |
userkey=tls_locs_wrong['key'], usercert=tls_locs_wrong['crt']) |
| 1172 |
|
| 1173 |
|
| 1174 |
output = self.run_logconv() |
| 1175 |
logconv_stats = self.extract_logconv_stats(output) |
| 1176 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_ldaps") |
| 1177 |
|
| 1178 |
def test_time_filter_valid_range(self, topo_shared): |
| 1179 |
"""Validate logconv with valid start and end time filters. |
| 1180 |
|
| 1181 |
:id: 6c7b9a1e-4f3c-4d8e-8a9b-7c6d5e4f3a2b |
| 1182 |
:setup: Standalone Instance |
| 1183 |
:steps: |
| 1184 |
1. Disable access log buffering |
| 1185 |
2. Perform a search operation to generate access log entries |
| 1186 |
3. Execute logconv with start time 2 minutes in past |
| 1187 |
4. Execute logconv with end time 2 minutes in future |
| 1188 |
5. Verify logconv executes successfully |
| 1189 |
:expectedresults: |
| 1190 |
1. Access log buffering disabled successfully |
| 1191 |
2. Search operation completed and logs generated |
| 1192 |
3. Start time formatted correctly |
| 1193 |
4. End time formatted correctly |
| 1194 |
5. logconv returns exit code 0 |
| 1195 |
""" |
| 1196 |
self.init_instance(topo_shared.standalone) |
| 1197 |
log.info("Disable access log buffering") |
| 1198 |
self.inst.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 1199 |
|
| 1200 |
log.info("Perform search operation to generate access log entries") |
| 1201 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)") |
| 1202 |
|
| 1203 |
log.info("Wait for access log entries to be written") |
| 1204 |
time.sleep(1) |
| 1205 |
|
| 1206 |
log.info("Calculate start time 2 minutes in the past") |
| 1207 |
start_time = datetime.now() - timedelta(minutes=2) |
| 1208 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S %z]") |
| 1209 |
if formatted_start_time.endswith(' ]'): |
| 1210 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S +0000]") |
| 1211 |
|
| 1212 |
log.info("Calculate end time 2 minutes in the future") |
| 1213 |
end_time = datetime.now() + timedelta(minutes=2) |
| 1214 |
formatted_end_time = end_time.strftime("[%d/%b/%Y:%H:%M:%S %z]") |
| 1215 |
if formatted_end_time.endswith(' ]'): |
| 1216 |
formatted_end_time = end_time.strftime("[%d/%b/%Y:%H:%M:%S +0000]") |
| 1217 |
|
| 1218 |
log.info("Execute logconv with start and end time filters") |
| 1219 |
cmd = [ |
| 1220 |
self.logconv_path, |
| 1221 |
'-S', formatted_start_time, |
| 1222 |
'-E', formatted_end_time, |
| 1223 |
self.access_log_path |
| 1224 |
] |
| 1225 |
result = subprocess.run(cmd, capture_output=True, text=True) |
| 1226 |
|
| 1227 |
log.info("Verify logconv executed successfully") |
| 1228 |
assert result.returncode == 0 |
| 1229 |
|
| 1230 |
def test_time_filter_invalid_range(self, topo_shared): |
| 1231 |
"""Validate logconv with invalid time range where start time is after end time. |
| 1232 |
|
| 1233 |
:id: 8d9e1f2a-5b6c-4e7d-9f0a-8c7b6d5e4f3c |
| 1234 |
:setup: Standalone Instance |
| 1235 |
:steps: |
| 1236 |
1. Disable access log buffering |
| 1237 |
2. Perform a search operation to generate access log entries |
| 1238 |
3. Execute logconv with start time 2 minutes in future |
| 1239 |
4. Execute logconv with end time 2 minutes in past |
| 1240 |
5. Verify logconv returns error |
| 1241 |
:expectedresults: |
| 1242 |
1. Access log buffering disabled successfully |
| 1243 |
2. Search operation completed and logs generated |
| 1244 |
3. Start time formatted correctly |
| 1245 |
4. End time formatted correctly |
| 1246 |
5. logconv returns exit code 1 |
| 1247 |
""" |
| 1248 |
self.init_instance(topo_shared.standalone) |
| 1249 |
log.info("Disable access log buffering") |
| 1250 |
self.inst.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 1251 |
|
| 1252 |
log.info("Perform search operation to generate access log entries") |
| 1253 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)") |
| 1254 |
|
| 1255 |
log.info("Wait for access log entries to be written") |
| 1256 |
time.sleep(1) |
| 1257 |
|
| 1258 |
log.info("Calculate start time 2 minutes in the future") |
| 1259 |
start_time = datetime.now() + timedelta(minutes=2) |
| 1260 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S %z]") |
| 1261 |
if formatted_start_time.endswith(' ]'): |
| 1262 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S +0000]") |
| 1263 |
|
| 1264 |
log.info("Calculate end time 2 minutes in the past") |
| 1265 |
end_time = datetime.now() - timedelta(minutes=2) |
| 1266 |
formatted_end_time = end_time.strftime("[%d/%b/%Y:%H:%M:%S %z]") |
| 1267 |
if formatted_end_time.endswith(' ]'): |
| 1268 |
formatted_end_time = end_time.strftime("[%d/%b/%Y:%H:%M:%S +0000]") |
| 1269 |
|
| 1270 |
log.info("Execute logconv with invalid time range") |
| 1271 |
cmd = [ |
| 1272 |
self.logconv_path, |
| 1273 |
'-S', formatted_start_time, |
| 1274 |
'-E', formatted_end_time, |
| 1275 |
self.access_log_path |
| 1276 |
] |
| 1277 |
result = subprocess.run(cmd, capture_output=True, text=True) |
| 1278 |
|
| 1279 |
log.info("Verify logconv returned error for invalid time range") |
| 1280 |
assert result.returncode == 1 |
| 1281 |
|
| 1282 |
def test_time_filter_invalid_format(self, topo_shared): |
| 1283 |
"""Validate logconv with invalid timestamp format. |
| 1284 |
|
| 1285 |
:id: 9e0f1a2b-6c7d-5e8f-0a1b-9d8c7e6f5a4d |
| 1286 |
:setup: Standalone Instance |
| 1287 |
:steps: |
| 1288 |
1. Disable access log buffering |
| 1289 |
2. Perform a search operation to generate access log entries |
| 1290 |
3. Execute logconv with invalid start time string |
| 1291 |
4. Execute logconv with invalid end time string |
| 1292 |
5. Verify logconv returns error |
| 1293 |
:expectedresults: |
| 1294 |
1. Access log buffering disabled successfully |
| 1295 |
2. Search operation completed and logs generated |
| 1296 |
3. Invalid start time provided |
| 1297 |
4. Invalid end time provided |
| 1298 |
5. logconv returns exit code 1 |
| 1299 |
""" |
| 1300 |
self.init_instance(topo_shared.standalone) |
| 1301 |
log.info("Disable access log buffering") |
| 1302 |
self.inst.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 1303 |
|
| 1304 |
log.info("Perform search operation to generate access log entries") |
| 1305 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)") |
| 1306 |
|
| 1307 |
log.info("Wait for access log entries to be written") |
| 1308 |
time.sleep(1) |
| 1309 |
|
| 1310 |
log.info("Set invalid timestamp values") |
| 1311 |
invalid_start_time = "invalid" |
| 1312 |
invalid_end_time = "invalid" |
| 1313 |
|
| 1314 |
log.info("Execute logconv with invalid timestamp format") |
| 1315 |
cmd = [ |
| 1316 |
self.logconv_path, |
| 1317 |
'-S', invalid_start_time, |
| 1318 |
'-E', invalid_end_time, |
| 1319 |
self.access_log_path |
| 1320 |
] |
| 1321 |
result = subprocess.run(cmd, capture_output=True, text=True) |
| 1322 |
|
| 1323 |
log.info("Verify logconv returned error for invalid timestamp format") |
| 1324 |
assert result.returncode == 1 |
| 1325 |
|
| 1326 |
def test_time_filter_without_log_path(self, topo_shared): |
| 1327 |
"""Validate logconv with time filter but without access log path. |
| 1328 |
|
| 1329 |
:id: 0f1a2b3c-7d8e-6f9a-1b2c-0e9d8f7a6b5c |
| 1330 |
:setup: Standalone Instance |
| 1331 |
:steps: |
| 1332 |
1. Disable access log buffering |
| 1333 |
2. Perform a search operation to generate access log entries |
| 1334 |
3. Execute logconv with start time but no access log path |
| 1335 |
4. Verify logconv returns error |
| 1336 |
:expectedresults: |
| 1337 |
1. Access log buffering disabled successfully |
| 1338 |
2. Search operation completed and logs generated |
| 1339 |
3. Start time formatted correctly |
| 1340 |
4. logconv returns exit code 1 |
| 1341 |
""" |
| 1342 |
self.init_instance(topo_shared.standalone) |
| 1343 |
log.info("Disable access log buffering") |
| 1344 |
self.inst.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 1345 |
|
| 1346 |
log.info("Perform search operation to generate access log entries") |
| 1347 |
self.inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)") |
| 1348 |
|
| 1349 |
log.info("Wait for access log entries to be written") |
| 1350 |
time.sleep(1) |
| 1351 |
|
| 1352 |
log.info("Calculate start time 2 minutes in the past") |
| 1353 |
start_time = datetime.now() - timedelta(minutes=2) |
| 1354 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S %z]") |
| 1355 |
if formatted_start_time.endswith(' ]'): |
| 1356 |
formatted_start_time = start_time.strftime("[%d/%b/%Y:%H:%M:%S +0000]") |
| 1357 |
|
| 1358 |
log.info("Execute logconv with start time but no access log path") |
| 1359 |
cmd = [self.logconv_path, '-S', formatted_start_time] |
| 1360 |
result = subprocess.run(cmd, capture_output=True, text=True) |
| 1361 |
|
| 1362 |
log.info("Verify logconv returned error when access log path not provided") |
| 1363 |
assert result.returncode == 1 |
| 1364 |
|
| 1365 |
def test_pool_stats(self, topo_shared): |
| 1366 |
"""Validate logconv parses RESULT lines carrying wbusy/wqdepth |
| 1367 |
tokens without dropping trailing fields. |
| 1368 |
|
| 1369 |
:id: 2bb14b97-1b61-426b-b9b3-39909d9699c8 |
| 1370 |
:setup: Standalone Instance |
| 1371 |
:steps: |
| 1372 |
1. Truncate access log |
| 1373 |
2. Inject RESULT lines with varying pool/trailing combinations |
| 1374 |
3. Run logconv and compare stats |
| 1375 |
:expectedresults: |
| 1376 |
1. Success |
| 1377 |
2. Success |
| 1378 |
3. Actual stats match expected |
| 1379 |
""" |
| 1380 |
self.init_instance(topo_shared.standalone) |
| 1381 |
self.truncate_logs() |
| 1382 |
|
| 1383 |
lines = [ |
| 1384 |
'[17/Apr/2026:00:00:00.000000000 +0000] conn=1 fd=64 slot=64 connection from 127.0.0.1 to 127.0.0.1\n', |
| 1385 |
'[17/Apr/2026:00:00:00.050000000 +0000] conn=1 op=0 BIND dn="cn=Directory Manager" method=128 version=3\n', |
| 1386 |
'[17/Apr/2026:00:00:00.060000000 +0000] conn=1 op=0 RESULT err=0 tag=97 nentries=0 wtime=0.0001 optime=0.001 etime=0.0011 wbusy=2/16 wqdepth=0\n', |
| 1387 |
'[17/Apr/2026:00:00:00.100000000 +0000] conn=1 op=1 SRCH base="dc=example,dc=com" scope=2 filter="(idontexist=*)" attrs=ALL\n', |
| 1388 |
'[17/Apr/2026:00:00:00.200000000 +0000] conn=1 op=1 RESULT err=0 tag=101 nentries=0 wtime=0.0001 optime=0.001 etime=0.0011 wbusy=8/16 wqdepth=3 notes=A\n', |
| 1389 |
'[17/Apr/2026:00:00:00.300000000 +0000] conn=1 op=2 SRCH base="dc=example,dc=com" scope=2 filter="(cn=*)" attrs=ALL\n', |
| 1390 |
'[17/Apr/2026:00:00:00.400000000 +0000] conn=1 op=2 RESULT err=0 tag=101 nentries=3 wtime=0.0001 optime=0.001 etime=0.0011 wbusy=14/16 wqdepth=7\n', |
| 1391 |
'[17/Apr/2026:00:00:00.500000000 +0000] conn=1 op=3 SRCH base="dc=example,dc=com" scope=2 filter="(description=*)" attrs=ALL\n', |
| 1392 |
'[17/Apr/2026:00:00:00.600000000 +0000] conn=1 op=3 RESULT err=0 tag=101 nentries=0 wtime=0.0001 optime=0.001 etime=0.0011 notes=A\n', |
| 1393 |
] |
| 1394 |
|
| 1395 |
with open(self.access_log_path, "w") as f: |
| 1396 |
for line in lines: |
| 1397 |
f.write(line) |
| 1398 |
|
| 1399 |
expected = { |
| 1400 |
"binds": 1, |
| 1401 |
"searches": 3, |
| 1402 |
"operations": 4, |
| 1403 |
"results": 4, |
| 1404 |
"unindexed_searches": 2, |
| 1405 |
"restarts": 1, |
| 1406 |
"total_connections": 1, |
| 1407 |
"ldap_conns": 1, |
| 1408 |
"fds_taken": 1, |
| 1409 |
} |
| 1410 |
|
| 1411 |
output = self.run_logconv() |
| 1412 |
logconv_stats = self.extract_logconv_stats(output) |
| 1413 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_pool_stats") |
| 1414 |
|
| 1415 |
def test_note_codes(self, topo_shared): |
| 1416 |
"""Validate logconv handles every note code the server can emit |
| 1417 |
(A, U, F, P, M, N, B) without crashing. |
| 1418 |
|
| 1419 |
:id: cc3631a3-91ef-4085-9b7d-a445dc5d234e |
| 1420 |
:setup: Standalone Instance |
| 1421 |
:steps: |
| 1422 |
1. Truncate access log |
| 1423 |
2. Inject SRCH/RESULT pairs (legacy or JSON depending on log format) |
| 1424 |
covering each known note code and one unknown |
| 1425 |
3. Run logconv without -V and compare summary counters |
| 1426 |
4. Run logconv with -V and assert each known code produces a |
| 1427 |
detail block; the unknown code must not |
| 1428 |
:expectedresults: |
| 1429 |
1. Success |
| 1430 |
2. Success |
| 1431 |
3. logconv exits 0 and summary counters match expected |
| 1432 |
4. Verbose output contains headers for A/U/F/M/N/B only |
| 1433 |
""" |
| 1434 |
self.init_instance(topo_shared.standalone) |
| 1435 |
self.truncate_logs() |
| 1436 |
|
| 1437 |
note_specs = [ |
| 1438 |
("A", "Unindexed Search"), |
| 1439 |
("U", "Unindexed Component"), |
| 1440 |
("F", "Invalid Attribute Filter"), |
| 1441 |
("P", None), |
| 1442 |
("M", "Multi-factor Authentication"), |
| 1443 |
("N", "Asynchronous Operation"), |
| 1444 |
("B", "Blocked Operation"), |
| 1445 |
("Z", None), # Future/unknown note — must be skipped gracefully. |
| 1446 |
] |
| 1447 |
|
| 1448 |
lines = [] |
| 1449 |
base_dn = "dc=example,dc=com" |
| 1450 |
search_filter = "(cn=*)" |
| 1451 |
conn_id = 1 |
| 1452 |
for idx, (code, _title) in enumerate(note_specs, start=1): |
| 1453 |
srch_ts = f"00:00:{idx:02d}.100000000" |
| 1454 |
res_ts = f"00:00:{idx:02d}.200000000" |
| 1455 |
if self.log_format == "json": |
| 1456 |
lines.append(json.dumps({ |
| 1457 |
"local_time": f"2026-04-17T{srch_ts} +0000", |
| 1458 |
"operation": "SEARCH", |
| 1459 |
"key": f"1000-{conn_id}", |
| 1460 |
"conn_id": conn_id, |
| 1461 |
"op_id": idx, |
| 1462 |
"base_dn": base_dn, |
| 1463 |
"scope": 2, |
| 1464 |
"filter": search_filter, |
| 1465 |
"attrs": [], |
| 1466 |
}) + "\n") |
| 1467 |
lines.append(json.dumps({ |
| 1468 |
"local_time": f"2026-04-17T{res_ts} +0000", |
| 1469 |
"operation": "RESULT", |
| 1470 |
"key": f"1000-{conn_id}", |
| 1471 |
"conn_id": conn_id, |
| 1472 |
"op_id": idx, |
| 1473 |
"tag": 101, |
| 1474 |
"err": 0, |
| 1475 |
"nentries": 1, |
| 1476 |
"etime": "0.001", |
| 1477 |
"client_ip": "127.0.0.1", |
| 1478 |
"bind_dn": "", |
| 1479 |
"notes": [{ |
| 1480 |
"note": code, |
| 1481 |
"description": "", |
| 1482 |
"base_dn": base_dn, |
| 1483 |
"filter": search_filter, |
| 1484 |
"scope": 2, |
| 1485 |
}], |
| 1486 |
}) + "\n") |
| 1487 |
else: |
| 1488 |
lines.append( |
| 1489 |
f'[17/Apr/2026:{srch_ts} +0000] conn={conn_id} op={idx} ' |
| 1490 |
f'SRCH base="{base_dn}" scope=2 filter="{search_filter}" attrs=ALL\n' |
| 1491 |
) |
| 1492 |
lines.append( |
| 1493 |
f'[17/Apr/2026:{res_ts} +0000] conn={conn_id} op={idx} ' |
| 1494 |
f'RESULT err=0 tag=101 nentries=1 etime=0.001 notes={code}\n' |
| 1495 |
) |
| 1496 |
|
| 1497 |
with open(self.access_log_path, "w") as f: |
| 1498 |
f.writelines(lines) |
| 1499 |
|
| 1500 |
num_codes = len(note_specs) |
| 1501 |
expected = { |
| 1502 |
"searches": num_codes, |
| 1503 |
"operations": num_codes, |
| 1504 |
"results": num_codes, |
| 1505 |
"unindexed_searches": 1, |
| 1506 |
"unindexed_components": 1, |
| 1507 |
"invalid_attribute_filters": 1, |
| 1508 |
"paged_searches": 1, |
| 1509 |
"multi_factor_auth": 1, |
| 1510 |
"async_ops": 1, |
| 1511 |
"blocked_ops": 1, |
| 1512 |
} |
| 1513 |
|
| 1514 |
output = self.run_logconv() |
| 1515 |
logconv_stats = self.extract_logconv_stats(output) |
| 1516 |
assert self.validate_logconv_stats(expected, logconv_stats, "test_note_codes") |
| 1517 |
|
| 1518 |
log.info("Re-run logconv with -V to exercise the per-note detail blocks") |
| 1519 |
verbose = subprocess.run( |
| 1520 |
[self.logconv_path, "-V", self.access_log_path], |
| 1521 |
capture_output=True, text=True, |
| 1522 |
) |
| 1523 |
assert verbose.returncode == 0, f"logconv -V failed: {verbose.stderr}" |
| 1524 |
|
| 1525 |
for code, title in note_specs: |
| 1526 |
header = f"{title} #1 (notes={code})" if title else None |
| 1527 |
if title is None: |
| 1528 |
# Unknown note must not appear as a detail header. |
| 1529 |
assert f"(notes={code})" not in verbose.stdout, \ |
| 1530 |
f"Unexpected detail block emitted for notes={code}" |
| 1531 |
else: |
| 1532 |
assert header in verbose.stdout, \ |
| 1533 |
f"Missing verbose detail block for notes={code}: {header!r}" |
| 1534 |
|
| 1535 |
|
| 1536 |
if __name__ == '__main__': |
| 1537 |
# Run isolated |
| 1538 |
# -s for DEBUG mode |
| 1539 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1540 |
pytest.main(["-s", CURRENT_FILE]) |
| 1541 |
|