Skip to content

Match FPM status pool's expose_php with parent #9514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,17 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */
} while (0)
#define FPM_WPC_STR_CP(_cfg, _scfg, _field) FPM_WPC_STR_CP_EX(_cfg, _scfg, _field, _field)

void fpm_conf_apply_kv_array_to_kv_array(struct key_value_s *src, void *dest) {
struct key_value_s *kv;

for (kv = src; kv; kv = kv->next) {
zval k, v;
ZVAL_STRING(&k, kv->key);
ZVAL_STRING(&v, kv->value);
fpm_conf_set_array(&k, &v, &dest, 0);
}
}

static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_wp) { /* {{{ */
struct fpm_worker_pool_config_s *config, *shared_config;
config = fpm_worker_pool_config_alloc();
Expand Down Expand Up @@ -738,6 +749,9 @@ static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_
FPM_WPC_STR_CP(config, shared_config, group);
FPM_WPC_STR_CP(config, shared_config, pm_status_path);

fpm_conf_apply_kv_array_to_kv_array(shared_config->php_values, (char *)config + WPO(php_values));
fpm_conf_apply_kv_array_to_kv_array(shared_config->php_admin_values, (char *)config + WPO(php_admin_values));

config->pm = PM_STYLE_ONDEMAND;
config->pm_max_children = 2;

Expand Down
30 changes: 28 additions & 2 deletions sapi/fpm/tests/response.inc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,20 @@ class Response
*
* @return Response
*/
public function expectHeader($name, $value): Response
public function expectHeader($name, $value, $useRegex = false): Response
{
$this->checkHeader($name, $value);
$this->checkHeader($name, $value, $useRegex);

return $this;
}

/**
* @param string $name
* @return Response
*/
public function expectNoHeader($name)
{
$this->checkNoHeader($name);

return $this;
}
Expand Down Expand Up @@ -264,6 +275,21 @@ class Response
return true;
}

/**
* @param string $name
* @return bool
*/
private function checkNoHeader(string $name)
{
$lcName = strtolower($name);
$headers = $this->getHeaders();
if (isset($headers[$lcName])) {
return $this->error("The header $name is present");
}

return true;
}

/**
* Get all headers.
*
Expand Down
39 changes: 39 additions & 0 deletions sapi/fpm/tests/status-listen-expose-php-off.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
FPM: Status pool is inheriting FPM setting overrides test - expose_php = off
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = static
pm.max_children = 1
pm.status_listen = {{ADDR[status]}}
pm.status_path = /status
php_flag[expose_php] = Off
EOT;

$tester = new FPM\Tester($cfg);
$tester->start();
$tester->expectLogStartNotices();
$response = $tester->request('', [], '/status', '{{ADDR[status]}}');
$response->expectNoHeader('X-Powered-By');
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
39 changes: 39 additions & 0 deletions sapi/fpm/tests/status-listen-expose-php-on.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
FPM: Status pool is inheriting FPM setting overrides test - expose_php = on
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = static
pm.max_children = 1
pm.status_listen = {{ADDR[status]}}
pm.status_path = /status
php_flag[expose_php] = On
EOT;

$tester = new FPM\Tester($cfg);
$tester->start();
$tester->expectLogStartNotices();
$response = $tester->request('', [], '/status', '{{ADDR[status]}}');
$response->expectHeader('X-Powered-By', '|^PHP/8|', true);
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>