name: ServerBagTest class_comment: '# * ServerBagTest. # * # * @author Bulat Shakirzyanov ' dependencies: - name: TestCase type: class source: PHPUnit\Framework\TestCase - name: ServerBag type: class source: Symfony\Component\HttpFoundation\ServerBag properties: [] methods: - name: testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet visibility: public parameters: [] comment: "# * ServerBagTest.\n# *\n# * @author Bulat Shakirzyanov \n\ # */\n# class ServerBagTest extends TestCase\n# {\n# public function testShouldExtractHeadersFromServerArray()\n\ # {\n# $server = [\n# 'SOME_SERVER_VARIABLE' => 'value',\n# 'SOME_SERVER_VARIABLE2'\ \ => 'value',\n# 'ROOT' => 'value',\n# 'HTTP_CONTENT_TYPE' => 'text/html',\n#\ \ 'HTTP_CONTENT_LENGTH' => '0',\n# 'HTTP_ETAG' => 'asdf',\n# 'PHP_AUTH_USER' =>\ \ 'foo',\n# 'PHP_AUTH_PW' => 'bar',\n# ];\n# \n# $bag = new ServerBag($server);\n\ # \n# $this->assertEquals([\n# 'CONTENT_TYPE' => 'text/html',\n# 'CONTENT_LENGTH'\ \ => '0',\n# 'ETAG' => 'asdf',\n# 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),\n\ # 'PHP_AUTH_USER' => 'foo',\n# 'PHP_AUTH_PW' => 'bar',\n# ], $bag->getHeaders());\n\ # }\n# \n# public function testHttpPasswordIsOptional()\n# {\n# $bag = new ServerBag(['PHP_AUTH_USER'\ \ => 'foo']);\n# \n# $this->assertEquals([\n# 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),\n\ # 'PHP_AUTH_USER' => 'foo',\n# 'PHP_AUTH_PW' => '',\n# ], $bag->getHeaders());\n\ # }\n# \n# public function testHttpPasswordIsOptionalWhenPassedWithHttpPrefix()\n\ # {\n# $bag = new ServerBag(['HTTP_PHP_AUTH_USER' => 'foo']);\n# \n# $this->assertEquals([\n\ # 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),\n# 'PHP_AUTH_USER' => 'foo',\n\ # ], $bag->getHeaders());\n# }\n# \n# public function testHttpBasicAuthWithPhpCgi()\n\ # {\n# $bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')]);\n\ # \n# $this->assertEquals([\n# 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),\n\ # 'PHP_AUTH_USER' => 'foo',\n# 'PHP_AUTH_PW' => 'bar',\n# ], $bag->getHeaders());\n\ # }\n# \n# public function testHttpBasicAuthWithPhpCgiBogus()\n# {\n# $bag = new\ \ ServerBag(['HTTP_AUTHORIZATION' => 'Basic_'.base64_encode('foo:bar')]);\n# \n\ # // Username and passwords should not be set as the header is bogus\n# $headers\ \ = $bag->getHeaders();\n# $this->assertArrayNotHasKey('PHP_AUTH_USER', $headers);\n\ # $this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);\n# }\n# \n# public function\ \ testHttpBasicAuthWithPhpCgiRedirect()\n# {\n# $bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION'\ \ => 'Basic '.base64_encode('username:pass:word')]);\n# \n# $this->assertEquals([\n\ # 'AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word'),\n# 'PHP_AUTH_USER'\ \ => 'username',\n# 'PHP_AUTH_PW' => 'pass:word',\n# ], $bag->getHeaders());\n\ # }\n# \n# public function testHttpBasicAuthWithPhpCgiEmptyPassword()\n# {\n#\ \ $bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:')]);\n\ # \n# $this->assertEquals([\n# 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),\n\ # 'PHP_AUTH_USER' => 'foo',\n# 'PHP_AUTH_PW' => '',\n# ], $bag->getHeaders());\n\ # }\n# \n# public function testHttpDigestAuthWithPhpCgi()\n# {\n# $digest = 'Digest\ \ username=\"foo\", realm=\"acme\", nonce=\"'.md5('secret').'\", uri=\"/protected,\ \ qop=\"auth\"';\n# $bag = new ServerBag(['HTTP_AUTHORIZATION' => $digest]);\n\ # \n# $this->assertEquals([\n# 'AUTHORIZATION' => $digest,\n# 'PHP_AUTH_DIGEST'\ \ => $digest,\n# ], $bag->getHeaders());\n# }\n# \n# public function testHttpDigestAuthWithPhpCgiBogus()\n\ # {\n# $digest = 'Digest_username=\"foo\", realm=\"acme\", nonce=\"'.md5('secret').'\"\ , uri=\"/protected, qop=\"auth\"';\n# $bag = new ServerBag(['HTTP_AUTHORIZATION'\ \ => $digest]);\n# \n# // Username and passwords should not be set as the header\ \ is bogus\n# $headers = $bag->getHeaders();\n# $this->assertArrayNotHasKey('PHP_AUTH_USER',\ \ $headers);\n# $this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);\n# }\n#\ \ \n# public function testHttpDigestAuthWithPhpCgiRedirect()\n# {\n# $digest =\ \ 'Digest username=\"foo\", realm=\"acme\", nonce=\"'.md5('secret').'\", uri=\"\ /protected, qop=\"auth\"';\n# $bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION'\ \ => $digest]);\n# \n# $this->assertEquals([\n# 'AUTHORIZATION' => $digest,\n\ # 'PHP_AUTH_DIGEST' => $digest,\n# ], $bag->getHeaders());\n# }\n# \n# public\ \ function testOAuthBearerAuth()\n# {\n# $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';\n\ # $bag = new ServerBag(['HTTP_AUTHORIZATION' => $headerContent]);\n# \n# $this->assertEquals([\n\ # 'AUTHORIZATION' => $headerContent,\n# ], $bag->getHeaders());\n# }\n# \n# public\ \ function testOAuthBearerAuthWithRedirect()\n# {\n# $headerContent = 'Bearer\ \ L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';\n# $bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION'\ \ => $headerContent]);\n# \n# $this->assertEquals([\n# 'AUTHORIZATION' => $headerContent,\n\ # ], $bag->getHeaders());\n# }\n# \n# /**\n# * @see https://github.com/symfony/symfony/issues/17345" - name: testRequestWithoutContentTypeAndContentLength visibility: public parameters: [] comment: '# * An HTTP request without content-type and content-length will result in # * the variables $_SERVER[''CONTENT_TYPE''] and $_SERVER[''CONTENT_LENGTH''] # * containing an empty string in PHP.' traits: - PHPUnit\Framework\TestCase - Symfony\Component\HttpFoundation\ServerBag interfaces: []