Skip to content

Commit cb4600a

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

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class OauthTest extends TestCase
5555
/** @var \Magento\Framework\Oauth\Oauth */
5656
private $_oauth;
5757

58-
/** @var \Zend_Oauth_Http_Utility */
58+
/** @var Utility */
5959
private $utility;
6060

6161
/** @var DateTime */
@@ -160,9 +160,7 @@ protected function setUp(): void
160160
$this->_oauthHelperMock = $this->getMockBuilder(Oauth::class)
161161
->setConstructorArgs([new Random()])
162162
->getMock();
163-
$this->utility = $this->getMockBuilder(Utility::class)
164-
->onlyMethods(['sign'])
165-
->getMock();
163+
$this->utility = $this->createMock(Utility::class);
166164
$this->_dateMock = $this->getMockBuilder(DateTime::class)
167165
->disableOriginalConstructor()
168166
->getMock();
@@ -791,7 +789,13 @@ public function testValidateAccessToken()
791789
public function testBuildAuthorizationHeader()
792790
{
793791
$signature = 'valid_signature';
794-
$this->utility->expects($this->any())->method('sign')->willReturn($signature);
792+
$this->utility->expects($this->once())->method('sign')->willReturn($signature);
793+
$this->utility->expects($this->once())
794+
->method('toAuthorizationHeader')
795+
->willReturn('OAuth oauth_nonce="tyukmnjhgfdcvxstyuioplkmnhtfvert",oauth_timestamp="1657789046",' .
796+
'oauth_version="1.0",oauth_consumer_key="edf957ef88492f0a32eb7e1731e85da2",' .
797+
'oauth_consumer_secret="asdawwewefrtyh2f0a32eb7e1731e85d",oauth_token="7c0709f789e1f38a17aa4b9a28e1b06c",' .
798+
'oauth_token_secret="a6agsfrsfgsrjjjjyy487939244ssggg",oauth_signature="valid_signature"');
795799

796800
$this->_setupConsumer(false);
797801
$this->_oauthHelperMock->expects(

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ public function sign(
4343
return base64_encode($binaryHash);
4444
}
4545

46+
/**
47+
* Cast to authorization header
48+
*
49+
* @param array $params
50+
* @param bool $excludeCustomParams
51+
* @return string
52+
*/
53+
public function toAuthorizationHeader(array $params, bool $excludeCustomParams = true): string
54+
{
55+
$headerValue = [];
56+
foreach ($params as $key => $value) {
57+
if ($excludeCustomParams) {
58+
if (! preg_match("/^oauth_/", $key)) {
59+
continue;
60+
}
61+
}
62+
$headerValue[] = $this->urlEncode((string)$key)
63+
. '="'
64+
. $this->urlEncode((string)$value) . '"';
65+
}
66+
return 'OAuth ' . implode(",", $headerValue);
67+
}
68+
4669
/**
4770
* Assemble key from consumer and token secrets
4871
*

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,8 @@ public function buildAuthorizationHeader(
162162
$httpMethod,
163163
$requestUrl
164164
);
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);
165+
166+
return $this->hmacSignatureHelper->toAuthorizationHeader($headerParameters);
169167
}
170168

171169
/**

0 commit comments

Comments
 (0)