From dbd0c07ec69d29bc7c97bb2acf31fcbb0c48e208 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 11 Nov 2017 22:50:30 -0500 Subject: [PATCH] Fix deprecation warnings in Client/Auth. --- src/Http/Client/Auth/Digest.php | 2 +- tests/TestCase/Http/Client/Auth/OauthTest.php | 126 +++++++++--------- 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/src/Http/Client/Auth/Digest.php b/src/Http/Client/Auth/Digest.php index c639818ddae..9d4256479cb 100644 --- a/src/Http/Client/Auth/Digest.php +++ b/src/Http/Client/Auth/Digest.php @@ -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'])) { diff --git a/tests/TestCase/Http/Client/Auth/OauthTest.php b/tests/TestCase/Http/Client/Auth/OauthTest.php index 8d7845d6652..4d9bdf60a31 100644 --- a/tests/TestCase/Http/Client/Auth/OauthTest.php +++ b/tests/TestCase/Http/Client/Auth/OauthTest.php @@ -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 = []; @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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', @@ -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 = [ @@ -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 . '"', @@ -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 = [ @@ -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 . '"', @@ -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'; @@ -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 . '"', @@ -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'; @@ -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 . '"', @@ -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'); @@ -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 . '"', @@ -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'); @@ -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 . '"',