Skip to content

Commit

Permalink
Fixed bug causing requests with queries to be invalidated
Browse files Browse the repository at this point in the history
The SecurityComponent would fail at _validatePost because the query
arguments were not encoded when the tokens were generated in the
IntegrationTestCase
  • Loading branch information
jeremyharris committed Jul 27, 2017
1 parent c75f2e7 commit 44d001c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -547,11 +547,12 @@ protected function _buildRequest($url, $method, $data)
list ($url, $query) = $this->_url($url);
$tokenUrl = $url;

parse_str($query, $queryData);

if ($query) {
$tokenUrl .= '?' . $query;
$tokenUrl .= '?' . http_build_query($queryData);
}

parse_str($query, $queryData);
$props = [
'url' => $url,
'post' => $this->_addTokens($tokenUrl, $data),
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -534,6 +534,24 @@ public function testPostSecuredFormWithQuery()
$this->assertResponseContains('Request was accepted');
}

/**
* Test posting to a secured form action with a query that has a part that
* will be encoded by the security component
*
* @return void
*/
public function testPostSecuredFormWithUnencodedQuery()
{
$this->enableSecurityToken();
$data = [
'title' => 'Some title',
'body' => 'Some text'
];
$this->post('/posts/securePost?foo=/', $data);
$this->assertResponseOk();
$this->assertResponseContains('Request was accepted');
}

/**
* Test posting to a secured form action action.
*
Expand Down

0 comments on commit 44d001c

Please sign in to comment.