toBe(str_repeat('2a', 16)) ->and($event)->toBe([ 'event' => 'input_validation_failure', 'event_id' => $event_id, 'variable' => 'graph_id', 'source_address' => '192.0.2.10', 'request_method' => 'POST', 'script' => 'graphs.php' ]) ->and($GLOBALS['validation_security_logs'][0][1])->toBeFalse() ->and($GLOBALS['validation_security_logs'][0][2])->toBe('SECURITY'); }); test('non-scalar variables and missing request metadata are handled safely', function () : void { unset($_SERVER['REQUEST_METHOD'], $_SERVER['SCRIPT_NAME']); $GLOBALS['validation_client_addr'] = false; security_log_input_validation_failure(['secret' => 'not logged']); $event = json_decode($GLOBALS['validation_security_logs'][0][0], true); expect($event['variable'])->toBe('array') ->and($event['source_address'])->toBe('') ->and($event['request_method'])->toBe(PHP_SAPI) ->and($event['script'])->toBe('') ->and($GLOBALS['validation_security_logs'][0][0])->not->toContain('not logged'); }); test('validation diagnostics include the structured event correlation ID', function () : void { $source = file_get_contents(dirname(__DIR__, 4) . '/lib/html_validate.php'); expect($source)->toContain('$event_id = security_log_input_validation_failure($variable)') ->and(substr_count($source, "'Validation Error, Event: ' . \$event_id"))->toBe(3) ->and(substr_count($source, ". \$variable . \$value . ', Source: '"))->toBe(2) ->and($source)->toContain("\$source_address = CACTI_CLI ? '' : get_client_addr();"); });