From 92ab47edc3abaf11f138a242c534963681b337cd Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 14 Oct 2017 11:50:17 -0400 Subject: [PATCH] Fix errors when request data is a string and tokens are enabled. Refs #11325 --- src/TestSuite/IntegrationTestCase.php | 7 +++++-- .../TestSuite/IntegrationTestCaseTest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/TestSuite/IntegrationTestCase.php b/src/TestSuite/IntegrationTestCase.php index 976ee6b3123..83a157a3a0f 100644 --- a/src/TestSuite/IntegrationTestCase.php +++ b/src/TestSuite/IntegrationTestCase.php @@ -587,14 +587,17 @@ protected function _buildRequest($url, $method, $data) $props = [ 'url' => $url, - 'post' => $this->_addTokens($tokenUrl, $data), - 'cookies' => $this->_cookie, 'session' => $session, 'query' => $queryData ]; if (is_string($data)) { $props['input'] = $data; } + if (!isset($props['input'])) { + $props['post'] = $this->_addTokens($tokenUrl, $data); + } + $props['cookies'] = $this->_cookie; + $env = [ 'REQUEST_METHOD' => $method, 'QUERY_STRING' => $query, diff --git a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php index d1391a8d082..a3ed979137d 100644 --- a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php +++ b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php @@ -361,6 +361,21 @@ public function testInputDataHttpServer() $this->assertHeader('X-Middleware', 'true'); } + /** + * Test that the PSR7 requests receive encoded data. + * + * @return void + */ + public function testInputDataSecurityToken() + { + $this->useHttpServer(true); + $this->enableSecurityToken(); + + $this->post('/request_action/input_test', '{"hello":"world"}'); + $this->assertSame('world', '' . $this->_response->getBody()); + $this->assertHeader('X-Middleware', 'true'); + } + /** * Test that the PSR7 requests get cookies *