|
7 | 7 | */
|
8 | 8 | namespace Magento\Framework\Oauth\Test\Unit\Helper;
|
9 | 9 |
|
| 10 | +use Magento\Framework\App\Request\Http; |
10 | 11 | use Magento\Framework\Phrase;
|
11 | 12 |
|
12 | 13 | class RequestTest extends \PHPUnit_Framework_TestCase
|
@@ -120,4 +121,70 @@ public function hostsDataProvider()
|
120 | 121 | ]
|
121 | 122 | ];
|
122 | 123 | }
|
| 124 | + |
| 125 | + /** |
| 126 | + * Test that the OAuth parameters are correctly extracted from the Authorization header. |
| 127 | + * |
| 128 | + * @param $authHeaderValue |
| 129 | + * @param $expectedParams |
| 130 | + * @dataProvider dataProviderForTestPrepareRequestOAuthHeader |
| 131 | + */ |
| 132 | + public function testPrepareRequestOAuthHeader($authHeaderValue, $expectedParams) |
| 133 | + { |
| 134 | + $httpRequestMock = $this->getMockBuilder(Http::class) |
| 135 | + ->disableOriginalConstructor() |
| 136 | + ->getMock(); |
| 137 | + |
| 138 | + $httpRequestMock->expects($this->once())->method('getScheme')->willReturn('https'); |
| 139 | + $httpRequestMock->expects($this->once())->method('getHttpHost')->willReturn('example.com'); |
| 140 | + $httpRequestMock->expects($this->once())->method('getRequestUri')->willReturn('/'); |
| 141 | + |
| 142 | + $httpRequestMock->expects($this->any()) |
| 143 | + ->method('getHeader') |
| 144 | + ->willReturnCallback(function ($header) use ($authHeaderValue) { |
| 145 | + switch ($header) { |
| 146 | + case 'Authorization': |
| 147 | + return $authHeaderValue; |
| 148 | + case \Zend_Http_Client::CONTENT_TYPE: |
| 149 | + return \Zend_Http_Client::ENC_URLENCODED; |
| 150 | + default: |
| 151 | + return null; |
| 152 | + } |
| 153 | + }); |
| 154 | + |
| 155 | + $this->assertEquals($expectedParams, $this->oauthRequestHelper->prepareRequest($httpRequestMock)); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * @return array |
| 160 | + */ |
| 161 | + public function dataProviderForTestPrepareRequestOAuthHeader() |
| 162 | + { |
| 163 | + return [ |
| 164 | + [ |
| 165 | + null, |
| 166 | + [] |
| 167 | + ], |
| 168 | + [ |
| 169 | + '', |
| 170 | + [] |
| 171 | + ], |
| 172 | + [ |
| 173 | + 'OAuth oauth_consumer_key="x",oauth_token="x", Basic d2luZHNvcm0yOldpTmRzb1JTbWlUSDAwMTQ=', |
| 174 | + ['oauth_consumer_key' => 'x', 'oauth_token' => 'x'] |
| 175 | + ], |
| 176 | + [ |
| 177 | + 'Basic d2luZHNvcm0yOldpTmRzb1JTbWlUSDAwMTQ=, OAuth oauth_consumer_key="x",oauth_token="x"', |
| 178 | + ['oauth_consumer_key' => 'x', 'oauth_token' => 'x'] |
| 179 | + ], |
| 180 | + [ |
| 181 | + 'Basic d2luZHNvcm0yOldpTmRzb1JTbWlUSDAwMTQ=, oauth oauth_consumer_key="x", oauth_token="x"', |
| 182 | + ['oauth_consumer_key' => 'x', 'oauth_token' => 'x'] |
| 183 | + ], |
| 184 | + [ |
| 185 | + 'oauth oauth_consumer_key="x", oauth_token="x", Basic d2luZHNvcm0yOldpTmRzb1JTbWlUSDAwMTQ=', |
| 186 | + ['oauth_consumer_key' => 'x', 'oauth_token' => 'x'] |
| 187 | + ] |
| 188 | + ]; |
| 189 | + } |
123 | 190 | }
|
0 commit comments