Skip to content

Commit

Permalink
Fixed OAuth to use new HTTP client functionality
Browse files Browse the repository at this point in the history
- Reworked how the Authorization header is reset
- Fixed tests:
  - cast URI object to string for assertion
  - use assertInstanceOf
  - test class: s/Oauth/OAuth/
  - headers should be passed as an array
  • Loading branch information
weierophinney committed Aug 30, 2011
1 parent 5051305 commit bff32e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion library/Zend/OAuth/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public static function getHttpClient()
if (!isset(self::$httpClient)) {
self::$httpClient = new HTTPClient;
} else {
self::$httpClient->setHeaders('Authorization', null);
$request = self::$httpClient->getRequest();
$headers = $request->headers();
if ($headers->has('Authorization')) {
$auth = $headers->get('Authorization');
$headers->removeHeader($auth);
}
self::$httpClient->resetParameters();
}
return self::$httpClient;
Expand Down
12 changes: 6 additions & 6 deletions tests/Zend/OAuth/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
namespace ZendTest\OAuth;

use Zend\OAuth,
Zend\Config\Config;
Zend\Config\Config,
Zend\Http\Client;

/**
* @category Zend
* @package Zend_OAuth
* @subpackage UnitTests
* @group Zend_OAuth
* @group disable
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class OauthTest extends \PHPUnit_Framework_TestCase
class OAuthTest extends \PHPUnit_Framework_TestCase
{

public function teardown()
Expand All @@ -45,7 +45,7 @@ public function teardown()
public function testCanSetCustomHttpClient()
{
OAuth\OAuth::setHttpClient(new HTTPClient19485876());
$this->assertType('ZendTest\\OAuth\\HttpClient19485876', OAuth\OAuth::getHttpClient());
$this->assertInstanceOf('ZendTest\\OAuth\\HttpClient19485876', OAuth\OAuth::getHttpClient());
}

public function testGetHttpClientResetsParameters()
Expand All @@ -55,13 +55,13 @@ public function testGetHttpClientResetsParameters()
OAuth\OAuth::setHttpClient($client);
$resetClient = OAuth\OAuth::getHttpClient();
$resetClient->setUri('http://www.example.com');
$this->assertEquals('http://www.example.com:80', $resetClient->getUri(true));
$this->assertEquals('http://www.example.com:80', (string) $resetClient->getUri(true));
}

public function testGetHttpClientResetsAuthorizationHeader()
{
$client = new HTTPClient19485876();
$client->setHeaders('Authorization', 'realm="http://www.example.com",oauth_version="1.0"');
$client->setHeaders(array('Authorization' => 'realm="http://www.example.com",oauth_version="1.0"'));
OAuth\OAuth::setHttpClient($client);
$resetClient = OAuth\OAuth::getHttpClient();
$this->assertEquals(null, $resetClient->getHeader('Authorization'));
Expand Down

0 comments on commit bff32e2

Please sign in to comment.