Server IP : 127.0.0.2 / Your IP : 18.223.172.41 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/symfony/http-foundation/Tests/ |
Upload File : |
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpFoundation\Tests; use Symfony\Component\HttpFoundation\ServerBag; /** * ServerBagTest. * * @author Bulat Shakirzyanov <mallluhuct@gmail.com> */ class ServerBagTest extends \PHPUnit_Framework_TestCase { public function testShouldExtractHeadersFromServerArray() { $server = array( 'SOME_SERVER_VARIABLE' => 'value', 'SOME_SERVER_VARIABLE2' => 'value', 'ROOT' => 'value', 'HTTP_CONTENT_TYPE' => 'text/html', 'HTTP_CONTENT_LENGTH' => '0', 'HTTP_ETAG' => 'asdf', 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar', ); $bag = new ServerBag($server); $this->assertEquals(array( 'CONTENT_TYPE' => 'text/html', 'CONTENT_LENGTH' => '0', 'ETAG' => 'asdf', 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'), 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar', ), $bag->getHeaders()); } public function testHttpPasswordIsOptional() { $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo')); $this->assertEquals(array( 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'), 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => '', ), $bag->getHeaders()); } public function testHttpBasicAuthWithPhpCgi() { $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'))); $this->assertEquals(array( 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'), 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar', ), $bag->getHeaders()); } public function testHttpBasicAuthWithPhpCgiBogus() { $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic_'.base64_encode('foo:bar'))); // Username and passwords should not be set as the header is bogus $headers = $bag->getHeaders(); $this->assertFalse(isset($headers['PHP_AUTH_USER'])); $this->assertFalse(isset($headers['PHP_AUTH_PW'])); } public function testHttpBasicAuthWithPhpCgiRedirect() { $bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word'))); $this->assertEquals(array( 'AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word'), 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'pass:word', ), $bag->getHeaders()); } public function testHttpBasicAuthWithPhpCgiEmptyPassword() { $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:'))); $this->assertEquals(array( 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'), 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => '', ), $bag->getHeaders()); } public function testHttpDigestAuthWithPhpCgi() { $digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"'; $bag = new ServerBag(array('HTTP_AUTHORIZATION' => $digest)); $this->assertEquals(array( 'AUTHORIZATION' => $digest, 'PHP_AUTH_DIGEST' => $digest, ), $bag->getHeaders()); } public function testHttpDigestAuthWithPhpCgiBogus() { $digest = 'Digest_username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"'; $bag = new ServerBag(array('HTTP_AUTHORIZATION' => $digest)); // Username and passwords should not be set as the header is bogus $headers = $bag->getHeaders(); $this->assertFalse(isset($headers['PHP_AUTH_USER'])); $this->assertFalse(isset($headers['PHP_AUTH_PW'])); } public function testHttpDigestAuthWithPhpCgiRedirect() { $digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"'; $bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => $digest)); $this->assertEquals(array( 'AUTHORIZATION' => $digest, 'PHP_AUTH_DIGEST' => $digest, ), $bag->getHeaders()); } public function testOAuthBearerAuth() { $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo'; $bag = new ServerBag(array('HTTP_AUTHORIZATION' => $headerContent)); $this->assertEquals(array( 'AUTHORIZATION' => $headerContent, ), $bag->getHeaders()); } public function testOAuthBearerAuthWithRedirect() { $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo'; $bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => $headerContent)); $this->assertEquals(array( 'AUTHORIZATION' => $headerContent, ), $bag->getHeaders()); } /** * @see https://github.com/symfony/symfony/issues/17345 */ public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet() { $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo'; $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent)); $this->assertEquals(array( 'AUTHORIZATION' => $headerContent, 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => '', ), $bag->getHeaders()); } }