Skip to content

Commit 36b8a2c

Browse files
committed
update the test framework for the http authentication part.
adding test.
1 parent 71f8824 commit 36b8a2c

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

sapi/fpm/tests/gh15395.phpt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--TEST--
2+
GH-15335 data logging during shutdown
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR:UDS}}
15+
pm = dynamic
16+
pm.max_children = 2
17+
pm.start_servers = 1
18+
pm.min_spare_servers = 1
19+
pm.max_spare_servers = 2
20+
php_admin_value[cgi.fix_pathinfo] = yes
21+
EOT;
22+
23+
$code = <<<EOT
24+
<?php
25+
echo \$_SERVER["SCRIPT_NAME"] . "\n";
26+
echo \$_SERVER["SCRIPT_FILENAME"] . "\n";
27+
echo \$_SERVER["PHP_SELF"];
28+
EOT;
29+
30+
$tester = new FPM\Tester($cfg, $code);
31+
[$sourceFilePath, $scriptName] = $tester->createSourceFileAndScriptName();
32+
$tester->start();
33+
$tester->expectLogStartNotices();
34+
$tester
35+
->request(
36+
uri: $scriptName,
37+
address: '{{ADDR:UDS}}',
38+
scriptFilename: "/",
39+
scriptName: "/",
40+
httpAuthorization: "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
41+
);
42+
43+
$tester
44+
->request(
45+
uri: $scriptName,
46+
address: '{{ADDR:UDS}}',
47+
scriptFilename: "/",
48+
scriptName: "/",
49+
);
50+
$tester->terminate();
51+
$tester->expectLogTerminatingNotices();
52+
$tester->close();
53+
54+
?>
55+
Done
56+
--EXPECT--
57+
Done
58+
--CLEAN--
59+
<?php
60+
require_once "tester.inc";
61+
FPM\Tester::clean();
62+
?>
63+

sapi/fpm/tests/tester.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,8 @@ class Tester
627627
string $uri = null,
628628
string $scriptFilename = null,
629629
string $scriptName = null,
630-
?string $stdin = null
630+
?string $stdin = null,
631+
?string $httpAuthorization = null
631632
): array {
632633
if (is_null($scriptFilename)) {
633634
$scriptFilename = $this->makeSourceFile();
@@ -657,7 +658,8 @@ class Tester
657658
'SERVER_PROTOCOL' => 'HTTP/1.1',
658659
'DOCUMENT_ROOT' => __DIR__,
659660
'CONTENT_TYPE' => '',
660-
'CONTENT_LENGTH' => strlen($stdin ?? "") // Default to 0
661+
'CONTENT_LENGTH' => strlen($stdin ?? ""), // Default to 0
662+
'HTTP_AUTHORIZATION' => $httpAuthorization ? $httpAuthorization : ""
661663
],
662664
$headers
663665
);
@@ -762,6 +764,7 @@ class Tester
762764
string|array $stdin = null,
763765
bool $expectError = false,
764766
int $readLimit = -1,
767+
string $httpAuthorization = null,
765768
): Response {
766769
if ($this->hasError()) {
767770
return $this->createResponse(expectInvalid: true);
@@ -771,7 +774,7 @@ class Tester
771774
$stdin = $this->parseStdin($stdin, $headers);
772775
}
773776

774-
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename, $scriptName, $stdin);
777+
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename, $scriptName, $stdin, $httpAuthorization);
775778
$this->trace('Request params', $params);
776779

777780
try {

0 commit comments

Comments
 (0)