Skip to content

Commit

Permalink
Fix deprecation warnings in Client/Auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 792f1b9 commit dbd0c07
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/Http/Client/Auth/Digest.php
Expand Up @@ -116,7 +116,7 @@ protected function _generateHeader(Request $request, $credentials)
{
$path = $request->getUri()->getPath();
$a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']);
$a2 = md5($request->method() . ':' . $path);
$a2 = md5($request->getMethod() . ':' . $path);
$nc = null;

if (empty($credentials['qop'])) {
Expand Down
126 changes: 64 additions & 62 deletions tests/TestCase/Http/Client/Auth/OauthTest.php
Expand Up @@ -112,8 +112,7 @@ public function testPlainTextSigning()
*/
public function testBaseStringNormalizeUrl()
{
$request = new Request();
$request->url('HTTP://exAmple.com:80/parts/foo');
$request = new Request('HTTP://exAmple.com:80/parts/foo');

$auth = new Oauth();
$creds = [];
Expand All @@ -129,8 +128,7 @@ public function testBaseStringNormalizeUrl()
*/
public function testBaseStringWithQueryString()
{
$request = new Request();
$request->url('http://example.com/search?q=pogo&cat=2');
$request = new Request('http://example.com/search?q=pogo&cat=2');

$auth = new Oauth();
$values = [
Expand Down Expand Up @@ -172,17 +170,19 @@ public function testBaseStringWithQueryString()
*/
public function testBaseStringWithPostDataNestedArrays()
{
$request = new Request();
$request->url('http://example.com/search?q=pogo')
->method(Request::METHOD_POST)
->body([
$request = new Request(
'http://example.com/search?q=pogo',
Request::METHOD_POST,
[],
[
'search' => [
'filters' => [
'field' => 'date',
'value' => 'one two'
]
]
]);
]
);

$auth = new Oauth();
$values = [
Expand Down Expand Up @@ -228,14 +228,16 @@ public function testBaseStringWithPostDataNestedArrays()
*/
public function testBaseStringWithPostData()
{
$request = new Request();
$request->url('http://example.com/search?q=pogo')
->method(Request::METHOD_POST)
->body([
$request = new Request(
'http://example.com/search?q=pogo',
Request::METHOD_POST,
[],
[
'address' => 'post',
'zed' => 'last',
'tags' => ['oauth', 'cake']
]);
]
);

$auth = new Oauth();
$values = [
Expand Down Expand Up @@ -279,12 +281,12 @@ public function testBaseStringWithPostData()
*/
public function testHmacSigning()
{
$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacation.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacation.jpg', 'size' => 'original']
);

$options = [
'consumerKey' => 'dpf43f3p2l4k3l03',
Expand Down Expand Up @@ -315,12 +317,12 @@ public function testHmacSigning()
*/
public function testRsaSigningString()
{
$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = $this->privateKeyString;

$options = [
Expand All @@ -333,7 +335,7 @@ public function testRsaSigningString()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand All @@ -351,12 +353,12 @@ public function testRsaSigningString()
*/
public function testRsaSigningFile()
{
$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key.pem', 'r');

$options = [
Expand All @@ -369,7 +371,7 @@ public function testRsaSigningFile()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand All @@ -387,12 +389,12 @@ public function testRsaSigningFile()
*/
public function testRsaSigningWithPassphraseString()
{
$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key_with_passphrase.pem', 'r');
$passphrase = 'fancy-cakephp-passphrase';

Expand All @@ -407,7 +409,7 @@ public function testRsaSigningWithPassphraseString()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand All @@ -425,12 +427,12 @@ public function testRsaSigningWithPassphraseString()
*/
public function testRsaSigningStringWithPassphraseString()
{
$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = $this->privateKeyStringEnc;
$passphrase = 'fancy-cakephp-passphrase';

Expand All @@ -445,7 +447,7 @@ public function testRsaSigningStringWithPassphraseString()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand All @@ -465,12 +467,12 @@ public function testRsaSigningWithPassphraseFile()
{
$this->skipIf(PHP_EOL != "\n", 'Just the line ending "\n" is supported. You can run the test again e.g. on a linux system.');

$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key_with_passphrase.pem', 'r');
$passphrase = fopen(TEST_APP . DS . 'config' . DS . 'key_passphrase_lf', 'r');

Expand All @@ -485,7 +487,7 @@ public function testRsaSigningWithPassphraseFile()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand All @@ -507,12 +509,12 @@ public function testRsaSigningStringWithPassphraseFile()
{
$this->skipIf(PHP_EOL != "\n", 'Just the line ending "\n" is supported. You can run the test again e.g. on a linux system.');

$request = new Request();
$request->url('http://photos.example.net/photos')
->body([
'file' => 'vacaction.jpg',
'size' => 'original'
]);
$request = new Request(
'http://photos.example.net/photos',
'GET',
[],
['file' => 'vacaction.jpg', 'size' => 'original']
);
$privateKey = $this->privateKeyStringEnc;
$passphrase = fopen(TEST_APP . DS . 'config' . DS . 'key_passphrase_lf', 'r');

Expand All @@ -527,7 +529,7 @@ public function testRsaSigningStringWithPassphraseFile()
$auth = new Oauth();
$request = $auth->authentication($request, $options);

$result = $request->header('Authorization');
$result = $request->getHeaderLine('Authorization');
$expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertContains(
'oauth_signature="' . $expected . '"',
Expand Down

0 comments on commit dbd0c07

Please sign in to comment.