Skip to content

Fix FPM status json encoded value test #11276

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 1 commit 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
5 changes: 1 addition & 4 deletions sapi/fpm/tests/bug64539-status-json-encoding.phpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
--TEST--
FPM: bug64539 - status json format escaping
--XFAIL--
--SKIPIF--
<?php
include "skipif.inc"; ?>
Expand Down Expand Up @@ -33,16 +32,14 @@ $responses = $tester
['query' => 'a=b"c'],
['uri' => '/status', 'query' => 'full&json', 'delay' => 100000],
]);
$data = json_decode($responses[1]->getBody('application/json'), true);
var_dump(explode('?', $data['processes'][0]['request uri'])[1]);
$responses[1]->expectJsonBodyPatternForStatusProcessField('request uri', '\?a=b"c$');
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
string(5) "a=b"c"
Done
--CLEAN--
<?php
Expand Down
31 changes: 31 additions & 0 deletions sapi/fpm/tests/response.inc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ class Response
return $this;
}

/**
* Expect that one of the processes in json status process list has a field with value that
* matches the supplied pattern.
*
* @param string $fieldName
* @param string $pattern
*
* @return Response
*/
public function expectJsonBodyPatternForStatusProcessField(string $fieldName, string $pattern)
{
$rawData = $this->getBody('application/json');
$data = json_decode($rawData, true);
if (empty($data['processes']) || !is_array($data['processes'])) {
$this->error(
"The body data is not a valid status json containing processes field '$rawData'"
);
}
foreach ($data['processes'] as $process) {
if (preg_match('/' . $pattern . '/', $process[$fieldName]) !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using () as the delimiter so that the caller doesn't need to escape / or any other literal character.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for compatibility with Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah will use pipes in case it was used for matching the whole uri...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually using pipes elsewhere - not sure why I used slashes here...

return $this;
}
}

$this->error(
"No field $fieldName matched pattern $pattern for any process in status data '$rawData'"
);

return $this;
}

/**
* @return Response
*/
Expand Down