diff --git a/tests/PHPUnit/Integration/Http/HttpAuthentication.php b/tests/PHPUnit/Integration/Http/HttpAuthentication.php new file mode 100644 index 0000000000000000000000000000000000000000..50bfa4d02f157577cbbde430d7001c64ef778fa0 --- /dev/null +++ b/tests/PHPUnit/Integration/Http/HttpAuthentication.php @@ -0,0 +1,11 @@ +<?php + +if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] == 'test' && $_SERVER['PHP_AUTH_PW'] == 'test') { + echo 'Authentication successful'; + exit; +} else { + header('WWW-Authenticate: Basic realm="TestAuth"'); + header('HTTP/1.0 401 Unauthorized'); + echo 'Authentication required'; + exit; +} \ No newline at end of file diff --git a/tests/PHPUnit/Integration/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php index 193147d068d975b2f70172b82117ad429d10ed10..1f2ff373bb2d6193589e5ac48631ce9ebfeb4d54 100644 --- a/tests/PHPUnit/Integration/HttpTest.php +++ b/tests/PHPUnit/Integration/HttpTest.php @@ -116,6 +116,57 @@ class HttpTest extends \PHPUnit_Framework_TestCase $this->assertTrue(in_array($result['headers']['Content-Type'], array('application/zip', 'application/x-zip-compressed'))); } + /** + * @dataProvider getMethodsToTest + */ + public function testHttpAuthentication($method) + { + $result = Http::sendHttpRequestBy( + $method, + Fixture::getRootUrl() . 'tests/PHPUnit/Integration/Http/HttpAuthentication.php', + 30, + $userAgent = null, + $destinationPath = null, + $file = null, + $followDepth = 0, + $acceptLanguage = false, + $acceptInvalidSslCertificate = false, + $byteRange = false, + $getExtendedInfo = true, + $httpMethod = 'GET', + $httpUsername = 'test', + $httpPassword = 'test' + ); + + $this->assertEquals('Authentication successful', $result['data']); + $this->assertEquals(200, $result['status']); + } + + /** + * @dataProvider getMethodsToTest + */ + public function testHttpAuthenticationInvalid($method) + { + $result = Http::sendHttpRequestBy( + $method, + Fixture::getRootUrl() . 'tests/PHPUnit/Integration/Http/HttpAuthentication.php', + 30, + $userAgent = null, + $destinationPath = null, + $file = null, + $followDepth = 0, + $acceptLanguage = false, + $acceptInvalidSslCertificate = false, + $byteRange = false, + $getExtendedInfo = true, + $httpMethod = 'GET', + $httpUsername = '', + $httpPassword = '' + ); + + $this->assertEquals(401, $result['status']); + } + /** * @dataProvider getMethodsToTest */