diff --git a/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php b/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php index 17b88e398230e..22fed9cfc7467 100644 --- a/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php +++ b/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php @@ -26,4 +26,57 @@ public function testInvalidProtocol() $client = new Curl(); $client->get('telnet://127.0.0.1/test'); } + + /** + * Check the HTTP client ability to parse headers case-insensitive. + */ + public function testParseHeaders() + { + // Prepare protected parseHeaders method + $curl = new Curl(); + $parseHeaders = new \ReflectionMethod( + $curl, + 'parseHeaders' + ); + $parseHeaders->setAccessible(true); + + // Parse headers + foreach ($this->headersDataProvider() as $header) { + $parseHeaders->invoke($curl, null, $header); + } + + // Validate headers + $headers = $curl->getHeaders(); + $this->assertIsArray($headers); + $this->assertEquals([ + 'Content-Type' => 'text/html; charset=utf-8', + 'Set-Cookie' => [ + 'Normal=OK', + 'Uppercase=OK', + 'Lowercase=OK', + ] + ], $headers); + + // Validate status + $status = $curl->getStatus(); + $this->assertIsInt($status); + $this->assertEquals(200, $status); + + // Validate cookies + $cookies = $curl->getCookies(); + $this->assertIsArray($cookies); + $this->assertEquals([ + 'Normal' => 'OK', + 'Uppercase' => 'OK', + 'Lowercase' => 'OK', + ], $cookies); + } + + /** + * @return array + */ + public function headersDataProvider() + { + return array_filter(explode(PHP_EOL, file_get_contents(__DIR__ . '/_files/curl_headers.txt'))); + } } diff --git a/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/_files/curl_headers.txt b/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/_files/curl_headers.txt new file mode 100644 index 0000000000000..48a2d6fbcf0b7 --- /dev/null +++ b/lib/internal/Magento/Framework/HTTP/Test/Unit/Client/_files/curl_headers.txt @@ -0,0 +1,5 @@ +Status: 200 OK +Content-Type: text/html; charset=utf-8 +Set-Cookie: Normal=OK +SET-COOKIE: Uppercase=OK +set-cookie: Lowercase=OK diff --git a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/CurlMockTest.php b/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/CurlMockTest.php deleted file mode 100644 index bf386a2387d71..0000000000000 --- a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/CurlMockTest.php +++ /dev/null @@ -1,86 +0,0 @@ -model = new CurlMock(); - } - - /** - * Handle Curl response - * - * @param string $response - * @return string - */ - private function handleResponse(string $response): string - { - // Make sure we use valid newlines - $response = explode("\r\n\r\n", str_replace("\n", "\r\n", $response), 2); - - // Parse headers - $headers = explode("\r\n", $response[0]); - foreach ($headers as $header) { - call_user_func([$this->model, 'parseHeaders'], $this->model->getResource(), $header); - } - - // Return body - return $response[1] ?? ''; - } - - /** - * Check that HTTP client parses cookies. - * - * @param string $response - * @dataProvider cookiesDataProvider - */ - public function testCookies($response) - { - self::$curlExectClosure = function () use ($response) { - $this->handleResponse($response); - }; - $this->model->get('http://127.0.0.1/test'); - $cookies = $this->model->getCookies(); - $this->assertIsArray($cookies); - $this->assertEquals([ - 'Normal' => 'OK', - 'Uppercase' => 'OK', - 'Lowercase' => 'OK', - ], $cookies); - } - - /** - * @return array - */ - public function cookiesDataProvider() - { - return [ - [file_get_contents(__DIR__ . '/_files/curl_response_cookies.txt')], - ]; - } -} diff --git a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/Mock/CurlMock.php b/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/Mock/CurlMock.php deleted file mode 100644 index 03d786a7ec73c..0000000000000 --- a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/Mock/CurlMock.php +++ /dev/null @@ -1,41 +0,0 @@ -_ch; - } -} diff --git a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/_files/curl_exec_mock.php b/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/_files/curl_exec_mock.php deleted file mode 100644 index 019f4889530d8..0000000000000 --- a/lib/internal/Magento/Framework/HTTP/Test/Unit/ClientMock/_files/curl_exec_mock.php +++ /dev/null @@ -1,22 +0,0 @@ -