Skip to content

Commit 2e45de7

Browse files
authored
Merge pull request #7780 from magento-atwix-pyrrans/AC-5928-replace-zend-oauth
[Pyrrans] AC-5928: Replace Zend_Oauth with Laminas\Oauth
2 parents d379b7f + 2f31e77 commit 2e45de7

File tree

5 files changed

+243
-25
lines changed

5 files changed

+243
-25
lines changed

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

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

10+
use Laminas\OAuth\Http\Utility;
1011
use Magento\Framework\DataObject;
1112
use Magento\Framework\Math\Random;
1213
use Magento\Framework\Oauth\Helper\Oauth;
@@ -31,6 +32,8 @@
3132
*/
3233
class OauthTest extends TestCase
3334
{
35+
private const TIMESTAMP_STUB = 1657789046;
36+
3437
/** @var ConsumerFactory */
3538
private $_consumerFactory;
3639

@@ -145,24 +148,26 @@ protected function setUp(): void
145148
)
146149
->addMethods(
147150
[
148-
'getType',
149-
'getToken',
150-
'getSecret',
151-
'getConsumerId',
152-
'getRevoked'
151+
'getType',
152+
'getToken',
153+
'getSecret',
154+
'getConsumerId',
155+
'getRevoked'
153156
]
154157
)
155158
->getMock();
156159
$this->_tokenFactory->expects($this->any())->method('create')->willReturn($this->_tokenMock);
157160
$this->_oauthHelperMock = $this->getMockBuilder(Oauth::class)
158161
->setConstructorArgs([new Random()])
159162
->getMock();
160-
$this->_httpUtilityMock = $this->getMockBuilder(\Zend_Oauth_Http_Utility::class)
163+
$this->_httpUtilityMock = $this->getMockBuilder(Utility::class)
161164
->onlyMethods(['sign'])
162165
->getMock();
163166
$this->_dateMock = $this->getMockBuilder(DateTime::class)
164167
->disableOriginalConstructor()
165168
->getMock();
169+
$this->_dateMock->method('timestamp')
170+
->willReturn(self::TIMESTAMP_STUB);
166171
$this->_loggerMock = $this->getMockBuilder(LoggerInterface::class)
167172
->disableOriginalConstructor()
168173
->getMockForAbstractClass();
@@ -821,7 +826,7 @@ public function testBuildAuthorizationHeader()
821826
$oauthHeader = $this->_oauth->buildAuthorizationHeader($request, $requestUrl);
822827

823828
$expectedHeader = 'OAuth oauth_nonce="tyukmnjhgfdcvxstyuioplkmnhtfvert",' .
824-
'oauth_timestamp="",' .
829+
'oauth_timestamp="' . self::TIMESTAMP_STUB . '",' .
825830
'oauth_version="1.0",oauth_consumer_key="edf957ef88492f0a32eb7e1731e85da2",' .
826831
'oauth_consumer_secret="asdawwewefrtyh2f0a32eb7e1731e85d",' .
827832
'oauth_token="7c0709f789e1f38a17aa4b9a28e1b06c",' .

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@
5555
"laminas/laminas-mime": "^2.9.1",
5656
"laminas/laminas-modulemanager": "^2.11.0",
5757
"laminas/laminas-mvc": "^3.3.3",
58+
"laminas/laminas-oauth": "^2.4",
5859
"laminas/laminas-servicemanager": "^3.11.0",
5960
"laminas/laminas-soap": "^2.10.0",
60-
"laminas/laminas-stdlib": "^3.7.1",
61+
"laminas/laminas-stdlib": "^3.10.0",
6162
"laminas/laminas-uri": "^2.9.1",
6263
"laminas/laminas-validator": "^2.17.0",
6364
"league/flysystem": "~2.4.5",

composer.lock

+221-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Framework\Oauth;
88

9+
use Laminas\OAuth\Http\Utility;
910
use Magento\Framework\Encryption\Helper\Security;
1011
use Magento\Framework\Phrase;
1112
use Magento\Framework\Oauth\Exception as AuthException;
@@ -21,7 +22,7 @@ class Oauth implements OauthInterface
2122
protected $_oauthHelper;
2223

2324
/**
24-
* @var \Zend_Oauth_Http_Utility
25+
* @var Utility
2526
*/
2627
protected $_httpUtility;
2728

@@ -45,13 +46,13 @@ public function __construct(
4546
Helper\Oauth $oauthHelper,
4647
NonceGeneratorInterface $nonceGenerator,
4748
TokenProviderInterface $tokenProvider,
48-
\Zend_Oauth_Http_Utility $httpUtility = null
49+
Utility $httpUtility = null
4950
) {
5051
$this->_oauthHelper = $oauthHelper;
5152
$this->_nonceGenerator = $nonceGenerator;
5253
$this->_tokenProvider = $tokenProvider;
5354
// null default to prevent ObjectManagerFactory from injecting, see MAGETWO-30809
54-
$this->_httpUtility = $httpUtility ?: new \Zend_Oauth_Http_Utility();
55+
$this->_httpUtility = $httpUtility ?: new Utility();
5556
}
5657

5758
/**
@@ -249,12 +250,8 @@ protected function _validateProtocolParams($protocolParams, $requiredParams = []
249250
}
250251
$this->_checkRequiredParams($protocolParams, $requiredParams);
251252

252-
if (isset(
253-
$protocolParams['oauth_token']
254-
) && !$this->_tokenProvider->validateOauthToken(
255-
$protocolParams['oauth_token']
256-
)
257-
) {
253+
if (isset($protocolParams['oauth_token'])
254+
&& !$this->_tokenProvider->validateOauthToken($protocolParams['oauth_token'])) {
258255
throw new OauthInputException(new Phrase('The token length is invalid. Check the length and try again.'));
259256
}
260257

0 commit comments

Comments
 (0)