Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.
Merged
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
25 changes: 9 additions & 16 deletions library/Zend/Oauth/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,20 @@ public function prepareOauth()

/**
* Collect all signable parameters into a single array across query string
* and POST body. These are returned as a properly formatted single
* query string.
* and POST body. Don't include POST parameters if content type is multipart POST.
*
* @return string
* @return array
*/
protected function _getSignableParametersAsQueryString()
{
$params = array();
if (!empty($this->paramsGet)) {
$params = array_merge($params, $this->paramsGet);
$query = $this->getToken()->toQueryString(
$this->getUri(true), $this->_config, $params
);
}
if (!empty($this->paramsPost)) {
$params = array_merge($params, $this->paramsPost);
$query = $this->getToken()->toQueryString(
$this->getUri(true), $this->_config, $params
);
}
return $params;
if (!empty($this->paramsGet)) {
$params = array_merge($params, $this->paramsGet);
}
if ($this->enctype != self::ENC_FORMDATA && !empty($this->paramsPost)) {
$params = array_merge($params, $this->paramsPost);
}
return $params;
}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/Zend/Oauth/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

require_once 'Zend/Oauth.php';
require_once 'Zend/Oauth/Config.php';
require_once 'Zend/Oauth/Client.php';

class Test_Oauth_Client extends Zend_Oauth_Client {
public function getSignableParametersAsQueryString()
{
return $this->_getSignableParametersAsQueryString();
}
}

/**
* @category Zend
Expand All @@ -46,4 +54,36 @@ public function testAllowsOptionsAsRequestMethod()
$this->client->setRequestMethod(Zend_Oauth_Client::OPTIONS);
$this->assertEquals(Zend_Oauth_Client::OPTIONS, $this->client->getRequestMethod());
}

/**
* zendframework / zf1 # 244
*/
public function testIncludesParametersForSignatureOnPostEncUrlEncoded()
{
$client = new Test_Oauth_Client(array());
$client->setEncType(Zend_Http_Client::ENC_URLENCODED);
$params = array(
'param1' => 'dummy1',
'param2' => 'dummy2',
);
$client->setParameterPost($params);
$client->setMethod(Zend_Http_Client::POST);
$this->assertEquals(2, count($client->getSignableParametersAsQueryString()));
}

/**
* zendframework / zf1 # 244
*/
public function testExcludesParametersOnPostEncFormData()
{
$client = new Test_Oauth_Client(array());
$client->setEncType(Zend_Http_Client::ENC_FORMDATA);
$params = array(
'param1' => 'dummy1',
'param2' => 'dummy2',
);
$client->setParameterPost($params);
$client->setMethod(Zend_Http_Client::POST);
$this->assertEquals(0, count($client->getSignableParametersAsQueryString()));
}
}