1--TEST--
2FPM: Test URIs are not excluded from access log when there is a request body
3--SKIPIF--
4<?php include "skipif.inc"; ?>
5--FILE--
6<?php
7
8require_once "tester.inc";
9
10$testScript = <<<EOT
11<?php
12echo strlen(file_get_contents('php://input'));
13EOT;
14
15$body = str_repeat('a', 100);
16
17// Add health checks to ignore list
18$cfg = <<<EOT
19[global]
20error_log = {{FILE:LOG:ERR}}
21pid = {{FILE:PID}}
22[unconfined]
23listen = {{ADDR}}
24access.log = {{FILE:LOG:ACC}}
25access.format = "'%m %r%Q%q' %s"
26access.suppress_path[] = /ping
27access.suppress_path[] = /request-1
28access.suppress_path[] = /request-2
29access.suppress_path[] = /request-3
30access.suppress_path[] = /request-4
31access.suppress_path[] = /request-5
32access.suppress_path[] = /request-6
33slowlog = {{FILE:LOG:SLOW}}
34request_slowlog_timeout = 1
35ping.path = /ping
36ping.response = pong
37pm = dynamic
38pm.max_children = 5
39pm.start_servers = 2
40pm.min_spare_servers = 1
41pm.max_spare_servers = 3
42EOT;
43
44$tester = new FPM\Tester($cfg, $testScript);
45$tester->start();
46$tester->expectLogStartNotices();
47$tester->expectSuppressableAccessLogEntries(false);
48$tester->ping();
49
50// Should not suppress POST with no body
51$tester->request(
52    uri: '/request-1',
53    headers: ['REQUEST_METHOD' => 'POST']
54)->expectBody('0');
55$tester->expectAccessLog("'POST /request-1' 200", suppressable: false);
56
57// Should not suppress POST with body
58$tester->request(
59    uri: '/request-2',
60    stdin: $body
61)->expectBody('100');
62$tester->expectAccessLog("'POST /request-2' 200", suppressable: false);
63
64// Should not suppress GET with body
65$tester->request(
66    uri: '/request-3',
67    headers: ['REQUEST_METHOD' => 'GET'],
68    stdin: $body
69)->expectBody('100');
70$tester->expectAccessLog("'GET /request-3' 200", suppressable: false);
71
72// Should suppress GET with no body
73$tester->request(
74    uri: '/request-4'
75)->expectBody('0');
76$tester->expectAccessLog("'GET /request-4' 200", suppressable: true);
77
78// Should not suppress GET with no body but incorrect content length
79$tester->request(
80    uri: '/request-5',
81    headers: ['REQUEST_METHOD' => 'GET', 'CONTENT_LENGTH' => 100]
82)->expectBody('0');
83$tester->expectAccessLog("'GET /request-5' 200", suppressable: false);
84
85// Should suppress GET with body but 0 content length (no stdin readable)
86$tester->request(
87    uri: '/request-6',
88    headers: ['REQUEST_METHOD' => 'GET', 'CONTENT_LENGTH' => 0],
89    stdin: $body
90)->expectBody('0');
91$tester->expectAccessLog("'GET /request-6' 200", suppressable: true);
92
93$tester->terminate();
94$tester->expectLogTerminatingNotices();
95$tester->close();
96$tester->expectNoFile(FPM\Tester::FILE_EXT_PID);
97$tester->checkAccessLog();
98
99?>
100Done
101--EXPECT--
102Done
103--CLEAN--
104<?php
105require_once "tester.inc";
106FPM\Tester::clean();
107?>
108