@@ -7,34 +7,68 @@ FPM: Test excluding URIs from access log
7
7
8
8
require_once "tester.inc " ;
9
9
10
- $ normalCode = <<<EOT
11
- <?php
12
- echo \$_REQUEST['test'] ?? "Hello world";
13
- EOT ;
10
+ function doTestCalls (FPM \Tester &$ tester , bool $ expectSuppressableEntries )
11
+ {
12
+ $ tester ->expectSuppressableAccessLogEntries ($ expectSuppressableEntries );
13
+
14
+ $ tester ->ping ();
15
+ $ tester ->expectAccessLog ("'GET /ping' 200 " , suppressable: true );
16
+
17
+ $ tester ->request ()->expectBody ('OK ' );
18
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php' 200 " , suppressable: true );
19
+
20
+ $ tester ->ping ();
21
+ $ tester ->expectAccessLog ("'GET /ping' 200 " , suppressable: true );
22
+
23
+ $ tester ->request ()->expectBody ('OK ' );
24
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php' 200 " , suppressable: true );
25
+
26
+ $ tester ->ping ();
27
+ $ tester ->expectAccessLog ("'GET /ping' 200 " , suppressable: true );
28
+
29
+ $ tester ->request (query: 'test=output ' )->expectBody ('output ' );
30
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php?test=output' 200 " , suppressable: false );
31
+
32
+ $ tester ->ping ();
33
+ $ tester ->expectAccessLog ("'GET /ping' 200 " , suppressable: true );
14
34
15
- file_put_contents (__DIR__ . '/log_exclude_paths_normal.php ' , $ normalCode );
35
+ $ tester ->request ()->expectBody ('OK ' );
36
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php' 200 " , suppressable: true );
16
37
17
- $ statusCode = <<<EOT
38
+ $ tester ->request (query: 'test=output ' , uri: '/ping ' )->expectBody ('pong ' , 'text/plain ' );
39
+ $ tester ->expectAccessLog ("'GET /ping?test=output' 200 " , suppressable: false );
40
+
41
+ $ tester ->request (headers: ['X_ERROR ' => 1 ])->expectBody ('Not OK ' );
42
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php' 500 " , suppressable: false );
43
+
44
+ $ tester ->request ()->expectBody ('OK ' );
45
+ $ tester ->expectAccessLog ("'GET /log-suppress-output.src.php' 200 " , suppressable: true );
46
+
47
+ $ tester ->request (query: 'test=output ' , uri: '/ping ' )->expectBody ('pong ' , 'text/plain ' );
48
+ $ tester ->expectAccessLog ("'GET /ping?test=output' 200 " , suppressable: false );
49
+
50
+ $ tester ->ping ();
51
+ $ tester ->expectAccessLog ("'GET /ping' 200 " , suppressable: true );
52
+ }
53
+
54
+ $ src = <<<EOT
18
55
<?php
19
56
if (isset( \$_SERVER['X_ERROR'])) {
20
57
echo "Not OK";
21
58
http_response_code(500);
22
59
exit;
23
60
}
24
- echo "OK";
61
+ echo \$ _REQUEST['test'] ?? "OK";
25
62
EOT ;
26
63
27
- file_put_contents (__DIR__ . '/log_exclude_paths_status.php ' , $ statusCode );
28
-
29
-
30
64
$ cfg = <<<EOT
31
65
[global]
32
66
error_log = {{RFILE:LOG:ERR}}
33
67
pid = {{RFILE:PID}}
34
68
[unconfined]
35
69
listen = {{ADDR}}
36
70
access.log = {{RFILE:LOG:ACC}}
37
- access.format = "%R \" % m %r%Q%q\" %s Output "
71
+ access.format = "'% m %r%Q%q' %s"
38
72
slowlog = {{RFILE:LOG:SLOW}}
39
73
request_slowlog_timeout = 1
40
74
ping.path = /ping
@@ -47,36 +81,21 @@ pm.max_spare_servers = 3
47
81
EOT ;
48
82
49
83
$ prefix = __DIR__ ;
50
- $ tester = new FPM \Tester ($ cfg );
84
+ $ tester = new FPM \Tester ($ cfg, $ src );
51
85
$ tester ->start (['--prefix ' , $ prefix ]);
52
86
$ 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
87
+ doTestCalls ($ tester , expectSuppressableEntries: true );
88
+ // Add source file and ping to ignore list
70
89
$ cfg = <<<EOT
71
90
[global]
72
91
error_log = {{RFILE:LOG:ERR}}
73
92
pid = {{RFILE:PID}}
74
93
[unconfined]
75
94
listen = {{ADDR}}
76
95
access.log = {{RFILE:LOG:ACC}}
77
- access.format = "%R \" % m %r%Q%q\" %s Ignore "
96
+ access.format = "'% m %r%Q%q' %s"
78
97
access.suppress_path[] = /ping
79
- access.suppress_path[] = /log_exclude_paths_status .php
98
+ access.suppress_path[] = /log-suppress-output.src .php
80
99
slowlog = {{RFILE:LOG:SLOW}}
81
100
request_slowlog_timeout = 1
82
101
ping.path = /ping
@@ -89,55 +108,16 @@ pm.max_spare_servers = 3
89
108
EOT ;
90
109
$ tester ->reload ($ cfg );
91
110
$ 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 ();
111
+ doTestCalls ($ tester , expectSuppressableEntries: false );
107
112
$ tester ->terminate ();
108
113
$ tester ->expectLogTerminatingNotices ();
109
114
$ tester ->close ();
110
115
$ 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 ' );
116
+ $ tester ->checkAccessLog ();
115
117
116
118
?>
117
119
Done
118
120
--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
121
Done
142
122
--CLEAN--
143
123
<?php
0 commit comments