|
| 1 | +--TEST-- |
| 2 | +FPM: Test excluding URIs from access log |
| 3 | +--SKIPIF-- |
| 4 | +<?php include "skipif.inc"; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once "tester.inc"; |
| 9 | + |
| 10 | +$normalCode = <<<EOT |
| 11 | +<?php |
| 12 | +echo \$_REQUEST['test'] ?? "Hello world"; |
| 13 | +EOT; |
| 14 | + |
| 15 | +file_put_contents(__DIR__ . '/log_exclude_paths_normal.php', $normalCode); |
| 16 | + |
| 17 | +$statusCode = <<<EOT |
| 18 | +<?php |
| 19 | +if (isset(\$_SERVER['X_ERROR'])) { |
| 20 | + echo "Not OK"; |
| 21 | + http_response_code(500); |
| 22 | + exit; |
| 23 | +} |
| 24 | +echo "OK"; |
| 25 | +EOT; |
| 26 | + |
| 27 | +file_put_contents(__DIR__ . '/log_exclude_paths_status.php', $statusCode); |
| 28 | + |
| 29 | + |
| 30 | +$cfg = <<<EOT |
| 31 | +[global] |
| 32 | +error_log = {{RFILE:LOG:ERR}} |
| 33 | +pid = {{RFILE:PID}} |
| 34 | +[unconfined] |
| 35 | +listen = {{ADDR}} |
| 36 | +access.log = {{RFILE:LOG:ACC}} |
| 37 | +access.format = "%R \"%m %r%Q%q\" %s Output" |
| 38 | +slowlog = {{RFILE:LOG:SLOW}} |
| 39 | +request_slowlog_timeout = 1 |
| 40 | +ping.path = /ping |
| 41 | +ping.response = pong |
| 42 | +pm = dynamic |
| 43 | +pm.max_children = 5 |
| 44 | +pm.start_servers = 2 |
| 45 | +pm.min_spare_servers = 1 |
| 46 | +pm.max_spare_servers = 3 |
| 47 | +EOT; |
| 48 | + |
| 49 | +$prefix = __DIR__; |
| 50 | +$tester = new FPM\Tester($cfg); |
| 51 | +$tester->start(['--prefix', $prefix]); |
| 52 | +$tester->expectLogStartNotices(); |
| 53 | +$tester->ping(); |
| 54 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 55 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 56 | +$tester->ping(); |
| 57 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 58 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('output'); |
| 59 | +$tester->ping(); |
| 60 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 61 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/ping')->expectBody('pong', 'text/plain'); |
| 62 | +$tester->request(headers: ['X_ERROR' => 1], scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('Not OK'); |
| 63 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 64 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 65 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 66 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/ping')->expectBody('pong', 'text/plain'); |
| 67 | +$tester->ping(); |
| 68 | + |
| 69 | +// Add health checks to ignore list |
| 70 | +$cfg = <<<EOT |
| 71 | +[global] |
| 72 | +error_log = {{RFILE:LOG:ERR}} |
| 73 | +pid = {{RFILE:PID}} |
| 74 | +[unconfined] |
| 75 | +listen = {{ADDR}} |
| 76 | +access.log = {{RFILE:LOG:ACC}} |
| 77 | +access.format = "%R \"%m %r%Q%q\" %s Ignore" |
| 78 | +access.suppress_path[] = /ping |
| 79 | +access.suppress_path[] = /log_exclude_paths_status.php |
| 80 | +slowlog = {{RFILE:LOG:SLOW}} |
| 81 | +request_slowlog_timeout = 1 |
| 82 | +ping.path = /ping |
| 83 | +ping.response = pong |
| 84 | +pm = dynamic |
| 85 | +pm.max_children = 5 |
| 86 | +pm.start_servers = 2 |
| 87 | +pm.min_spare_servers = 1 |
| 88 | +pm.max_spare_servers = 3 |
| 89 | +EOT; |
| 90 | +$tester->reload($cfg); |
| 91 | +$tester->expectLogReloadingNotices(); |
| 92 | +$tester->ping(); |
| 93 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 94 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 95 | +$tester->ping(); |
| 96 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 97 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('output'); |
| 98 | +$tester->ping(); |
| 99 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 100 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/ping')->expectBody('pong', 'text/plain'); |
| 101 | +$tester->request(headers: ['X_ERROR' => 1], scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('Not OK'); |
| 102 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 103 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_status.php')->expectBody('OK'); |
| 104 | +$tester->request(scriptFilename: __DIR__ . '/log_exclude_paths_normal.php')->expectBody('Hello world'); |
| 105 | +$tester->request(query: 'test=output', scriptFilename: __DIR__ . '/ping')->expectBody('pong', 'text/plain'); |
| 106 | +$tester->ping(); |
| 107 | +$tester->terminate(); |
| 108 | +$tester->expectLogTerminatingNotices(); |
| 109 | +$tester->close(); |
| 110 | +$tester->expectNoFile(FPM\Tester::FILE_EXT_PID, $prefix); |
| 111 | +$tester->printAccessLog(); |
| 112 | + |
| 113 | +unlink(__DIR__ . '/log_exclude_paths_normal.php'); |
| 114 | +unlink(__DIR__ . '/log_exclude_paths_status.php'); |
| 115 | + |
| 116 | +?> |
| 117 | +Done |
| 118 | +--EXPECT-- |
| 119 | +127.0.0.1 "GET /ping" 200 Output |
| 120 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Output |
| 121 | +127.0.0.1 "GET /log_exclude_paths_status.php" 200 Output |
| 122 | +127.0.0.1 "GET /ping" 200 Output |
| 123 | +127.0.0.1 "GET /log_exclude_paths_status.php" 200 Output |
| 124 | +127.0.0.1 "GET /log_exclude_paths_normal.php?test=output" 200 Output |
| 125 | +127.0.0.1 "GET /ping" 200 Output |
| 126 | +127.0.0.1 "GET /log_exclude_paths_status.php" 200 Output |
| 127 | +127.0.0.1 "GET /ping?test=output" 200 Output |
| 128 | +127.0.0.1 "GET /log_exclude_paths_status.php" 500 Output |
| 129 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Output |
| 130 | +127.0.0.1 "GET /log_exclude_paths_status.php" 200 Output |
| 131 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Output |
| 132 | +127.0.0.1 "GET /ping?test=output" 200 Output |
| 133 | +127.0.0.1 "GET /ping" 200 Output |
| 134 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Ignore |
| 135 | +127.0.0.1 "GET /log_exclude_paths_normal.php?test=output" 200 Ignore |
| 136 | +127.0.0.1 "GET /ping?test=output" 200 Ignore |
| 137 | +127.0.0.1 "GET /log_exclude_paths_status.php" 500 Ignore |
| 138 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Ignore |
| 139 | +127.0.0.1 "GET /log_exclude_paths_normal.php" 200 Ignore |
| 140 | +127.0.0.1 "GET /ping?test=output" 200 Ignore |
| 141 | +Done |
| 142 | +--CLEAN-- |
| 143 | +<?php |
| 144 | +require_once "tester.inc"; |
| 145 | +FPM\Tester::clean(); |
| 146 | +?> |
0 commit comments