Skip to content

Commit 144c2e2

Browse files
committed
ACP2E-2969: REST API unable to make requests with slash (/) in SKU when using Oauth1
1 parent db27a9e commit 144c2e2

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

app/code/Magento/Integration/Test/Unit/Oauth/OauthTest.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\Integration\Test\Unit\Oauth;
99

10-
use Laminas\OAuth\Http\Utility;
10+
use Magento\Framework\Oauth\Helper\Utility;
1111
use Magento\Framework\DataObject;
1212
use Magento\Framework\Math\Random;
1313
use Magento\Framework\Oauth\Helper\Oauth;
@@ -56,7 +56,7 @@ class OauthTest extends TestCase
5656
private $_oauth;
5757

5858
/** @var \Zend_Oauth_Http_Utility */
59-
private $_httpUtilityMock;
59+
private $utility;
6060

6161
/** @var DateTime */
6262
private $_dateMock;
@@ -160,7 +160,7 @@ protected function setUp(): void
160160
$this->_oauthHelperMock = $this->getMockBuilder(Oauth::class)
161161
->setConstructorArgs([new Random()])
162162
->getMock();
163-
$this->_httpUtilityMock = $this->getMockBuilder(Utility::class)
163+
$this->utility = $this->getMockBuilder(Utility::class)
164164
->onlyMethods(['sign'])
165165
->getMock();
166166
$this->_dateMock = $this->getMockBuilder(DateTime::class)
@@ -190,7 +190,7 @@ protected function setUp(): void
190190
$this->_oauthHelperMock,
191191
$nonceGenerator,
192192
$tokenProvider,
193-
$this->_httpUtilityMock
193+
$this->utility
194194
);
195195
$this->_oauthToken = $this->_generateRandomString(Oauth::LENGTH_TOKEN);
196196
$this->_oauthSecret = $this->_generateRandomString(Oauth::LENGTH_TOKEN_SECRET);
@@ -199,17 +199,6 @@ protected function setUp(): void
199199
);
200200
}
201201

202-
protected function tearDown(): void
203-
{
204-
unset($this->_consumerFactory);
205-
unset($this->_nonceFactory);
206-
unset($this->_tokenFactory);
207-
unset($this->_oauthHelperMock);
208-
unset($this->_httpUtilityMock);
209-
unset($this->_dateMock);
210-
unset($this->_oauth);
211-
}
212-
213202
/**
214203
* @param array $amendments
215204
* @return array
@@ -477,7 +466,7 @@ public function testGetRequestTokenTokenRejected()
477466
$this->_setupToken(false);
478467

479468
$signature = 'valid_signature';
480-
$this->_httpUtilityMock->expects($this->any())->method('sign')->willReturn($signature);
469+
$this->utility->expects($this->any())->method('sign')->willReturn($signature);
481470

482471
$this->_oauth->getRequestToken(
483472
$this->_getRequestTokenParams(['oauth_signature' => $signature]),
@@ -498,7 +487,7 @@ public function testGetRequestTokenTokenRejectedByType()
498487
// wrong type
499488

500489
$signature = 'valid_signature';
501-
$this->_httpUtilityMock->expects($this->any())->method('sign')->willReturn($signature);
490+
$this->utility->expects($this->any())->method('sign')->willReturn($signature);
502491

503492
$this->_oauth->getRequestToken(
504493
$this->_getRequestTokenParams(['oauth_signature' => $signature]),
@@ -548,7 +537,7 @@ public function testGetRequestToken()
548537
$this->_setupToken();
549538

550539
$signature = 'valid_signature';
551-
$this->_httpUtilityMock->expects($this->any())->method('sign')->willReturn($signature);
540+
$this->utility->expects($this->any())->method('sign')->willReturn($signature);
552541

553542
$requestToken = $this->_oauth->getRequestToken(
554543
$this->_getRequestTokenParams(['oauth_signature' => $signature]),
@@ -802,7 +791,7 @@ public function testValidateAccessToken()
802791
public function testBuildAuthorizationHeader()
803792
{
804793
$signature = 'valid_signature';
805-
$this->_httpUtilityMock->expects($this->any())->method('sign')->willReturn($signature);
794+
$this->utility->expects($this->any())->method('sign')->willReturn($signature);
806795

807796
$this->_setupConsumer(false);
808797
$this->_oauthHelperMock->expects(

lib/internal/Magento/Framework/Oauth/Helper/Utility.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
class Utility extends HTTPUtility
2525
{
2626
/**
27+
* Generate signature string
28+
*
2729
* @param array $params
28-
* @param $signatureMethod
30+
* @param string $signatureMethod
2931
* @param string $consumerSecret
30-
* @param null $tokenSecret
31-
* @param null $method
32-
* @param null $url
32+
* @param string|null $tokenSecret
33+
* @param string|null $method
34+
* @param string|null $url
3335
* @return string
3436
*/
3537
public function sign(
@@ -52,31 +54,6 @@ public function sign(
5254
return base64_encode($binaryHash);
5355
}
5456

55-
/**
56-
* Cast to authorization header
57-
*
58-
* @param array $params
59-
* @param null $realm
60-
* @param bool $excludeCustomParams
61-
* @return string
62-
*/
63-
public function toAuthorizationHeader(array $params, $realm = null, $excludeCustomParams = true)
64-
{
65-
$headerValue = [];
66-
foreach ($params as $key => $value) {
67-
if ($excludeCustomParams) {
68-
if (! preg_match("/^oauth_/", $key)) {
69-
continue;
70-
}
71-
}
72-
$headerValue[] = $this->urlEncode($key)
73-
. '="'
74-
. $this->urlEncode($value) . '"';
75-
}
76-
77-
return implode(",", $headerValue);
78-
}
79-
8057
/**
8158
* Assemble key from consumer and token secrets
8259
*

lib/internal/Magento/Framework/Oauth/Oauth.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ public function buildAuthorizationHeader(
162162
$httpMethod,
163163
$requestUrl
164164
);
165-
166-
return $this->hmacSignatureHelper->toAuthorizationHeader($headerParameters);
165+
$authorizationHeader = $this->hmacSignatureHelper->toAuthorizationHeader($headerParameters);
166+
// toAuthorizationHeader adds an optional realm="" which is not required for now.
167+
// http://tools.ietf.org/html/rfc2617#section-1.2
168+
return str_replace('realm="",', '', $authorizationHeader);
167169
}
168170

169171
/**

0 commit comments

Comments
 (0)