Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Slim\Tests; use ReflectionClass; use Slim\ResponseEmitter; use Slim\Test..

Decoded Output download

<?php
  namespace Slim\Tests; use ReflectionClass; use Slim\ResponseEmitter; use Slim\Tests\Assets\HeaderStack; use Slim\Tests\Mocks\MockStream; use Slim\Tests\Mocks\SlowPokeStream; use Slim\Tests\Mocks\SmallChunksStream; use function base64_decode; use function fopen; use function fwrite; use function in_array; use function popen; use function rewind; use function str_repeat; use function stream_filter_append; use function stream_filter_remove; use function stream_get_filters; use function strlen; use function trim; use const CONNECTION_ABORTED; use const CONNECTION_TIMEOUT; use const STREAM_FILTER_READ; use const STREAM_FILTER_WRITE; class ResponseEmitterTest extends TestCase { public function setUp() : void { HeaderStack::reset(); } public function tearDown() : void { HeaderStack::reset(); } public function testRespond() : void { $response = $this->createResponse(); $response->getBody()->write("Hello"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("Hello"); } public function testRespondWithPaddedStreamFilterOutput() : void { $availableFilter = stream_get_filters(); $filterName = "string.rot13"; $unfilterName = "string.rot13"; $specificFilterName = "string.rot13"; $specificUnfilterName = "string.rot13"; if (in_array($filterName, $availableFilter) && in_array($unfilterName, $availableFilter)) { $key = base64_decode("xxxxxxxxxxxxxxxx"); $iv = base64_decode("Z6wNDk9LogWI4HYlRu0mng=="); $data = "Hello"; $length = strlen($data); $stream = fopen("php://temp", "r+"); $filter = stream_filter_append($stream, $specificFilterName, STREAM_FILTER_WRITE, array("key" => $key, "iv" => $iv)); fwrite($stream, $data); rewind($stream); stream_filter_remove($filter); stream_filter_append($stream, $specificUnfilterName, STREAM_FILTER_READ, array("key" => $key, "iv" => $iv)); $body = $this->getStreamFactory()->createStreamFromResource($stream); $response = $this->createResponse()->withHeader("Content-Length", $length)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("Hello"); } else { $this->assertTrue(true); } } public function testRespondIndeterminateLength() : void { $stream = fopen("php://temp", "r+"); fwrite($stream, "Hello"); rewind($stream); $body = $this->getMockBuilder(MockStream::class)->setConstructorArgs(array($stream))->onlyMethods(array("getSize"))->getMock(); $body->method("getSize")->willReturn(null); $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("Hello"); } public function testResponseWithStreamReadYieldingLessBytesThanAsked() : void { $body = new SmallChunksStream(); $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter($body::CHUNK_SIZE * 2); $responseEmitter->emit($response); $this->expectOutputString(str_repeat(".", $body->getSize())); } public function testResponseReplacesPreviouslySetHeaders() : void { $response = $this->createResponse(200, "OK")->withHeader("X-Foo", "baz1")->withAddedHeader("X-Foo", "baz2"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $expectedStack = array(array("header" => "X-Foo: baz1", "replace" => true, "status_code" => null), array("header" => "X-Foo: baz2", "replace" => false, "status_code" => null), array("header" => "HTTP/1.1 200 OK", "replace" => true, "status_code" => 200)); $this->assertSame($expectedStack, HeaderStack::stack()); } public function testResponseDoesNotReplacePreviouslySetSetCookieHeaders() : void { $response = $this->createResponse(200, "OK")->withHeader("set-cOOkie", "foo=bar")->withAddedHeader("Set-Cookie", "bar=baz"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $expectedStack = array(array("header" => "set-cOOkie: foo=bar", "replace" => false, "status_code" => null), array("header" => "set-cOOkie: bar=baz", "replace" => false, "status_code" => null), array("header" => "HTTP/1.1 200 OK", "replace" => true, "status_code" => 200)); $this->assertSame($expectedStack, HeaderStack::stack()); } public function testIsResponseEmptyWithNonEmptyBodyAndTriggeringStatusCode() : void { $body = $this->createStream("Hello"); $response = $this->createResponse(204)->withBody($body); $responseEmitter = new ResponseEmitter(); $this->assertTrue($responseEmitter->isResponseEmpty($response)); } public function testIsResponseEmptyDoesNotReadAllDataFromNonEmptySeekableResponse() : void { $body = $this->createStream("Hello"); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->isResponseEmpty($response); $this->assertTrue($body->isSeekable()); $this->assertFalse($body->eof()); } public function testIsResponseEmptyDoesNotDrainNonSeekableResponseWithContent() : void { $resource = popen("echo 12", "r"); $body = $this->getStreamFactory()->createStreamFromResource($resource); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->isResponseEmpty($response); $this->assertFalse($body->isSeekable()); $this->assertSame("12", trim((string) $body)); } public function testAvoidReadFromSlowStreamAccordingToStatus() : void { $body = new SlowPokeStream(); $response = $this->createResponse(204, "No content")->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->assertFalse($body->eof()); $this->expectOutputString(''); } public function testIsResponseEmptyWithEmptyBody() : void { $response = $this->createResponse(200); $responseEmitter = new ResponseEmitter(); $this->assertTrue($responseEmitter->isResponseEmpty($response)); } public function testIsResponseEmptyWithZeroAsBody() : void { $body = $this->createStream("0"); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $this->assertFalse($responseEmitter->isResponseEmpty($response)); } public function testWillHandleInvalidConnectionStatusWithADeterminateBody() : void { $body = $this->getStreamFactory()->createStreamFromResource(fopen("php://temp", "r+")); $body->write("Hello!" . "
"); $body->write("Hello!" . "\xa"); $GLOBALS["connection_status_return"] = CONNECTION_ABORTED; $response = $this->createResponse()->withHeader("Content-Length", $body->getSize())->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("Hello!\xaHello!\xa"); unset($GLOBALS["connection_status_return"]); } public function testWillHandleInvalidConnectionStatusWithAnIndeterminateBody() : void { $body = $this->getStreamFactory()->createStreamFromResource(fopen("php://input", "r+")); $GLOBALS["connection_status_return"] = CONNECTION_TIMEOUT; $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter(); $mirror = new ReflectionClass(ResponseEmitter::class); $emitBodyMethod = $mirror->getMethod("emitBody"); $emitBodyMethod->setAccessible(true); $emitBodyMethod->invoke($responseEmitter, $response); $this->expectOutputString(''); unset($GLOBALS["connection_status_return"]); } } ?>

Did this file decode correctly?

Original Code

<?php
  namespace Slim\Tests; use ReflectionClass; use Slim\ResponseEmitter; use Slim\Tests\Assets\HeaderStack; use Slim\Tests\Mocks\MockStream; use Slim\Tests\Mocks\SlowPokeStream; use Slim\Tests\Mocks\SmallChunksStream; use function base64_decode; use function fopen; use function fwrite; use function in_array; use function popen; use function rewind; use function str_repeat; use function stream_filter_append; use function stream_filter_remove; use function stream_get_filters; use function strlen; use function trim; use const CONNECTION_ABORTED; use const CONNECTION_TIMEOUT; use const STREAM_FILTER_READ; use const STREAM_FILTER_WRITE; class ResponseEmitterTest extends TestCase { public function setUp() : void { HeaderStack::reset(); } public function tearDown() : void { HeaderStack::reset(); } public function testRespond() : void { $response = $this->createResponse(); $response->getBody()->write("\x48\145\x6c\154\x6f"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("\110\145\x6c\154\157"); } public function testRespondWithPaddedStreamFilterOutput() : void { $availableFilter = stream_get_filters(); $filterName = "\x73\164\162\151\156\147\56\x72\x6f\x74\x31\x33"; $unfilterName = "\163\x74\x72\x69\156\147\56\x72\x6f\x74\x31\63"; $specificFilterName = "\163\164\162\x69\x6e\x67\56\x72\x6f\x74\x31\x33"; $specificUnfilterName = "\163\x74\x72\x69\x6e\147\x2e\x72\157\x74\61\63"; if (in_array($filterName, $availableFilter) && in_array($unfilterName, $availableFilter)) { $key = base64_decode("\170\x78\170\170\170\x78\x78\170\x78\170\x78\x78\170\170\170\x78"); $iv = base64_decode("\x5a\66\x77\116\104\x6b\71\114\157\147\x57\111\x34\110\131\x6c\x52\165\x30\155\156\147\75\x3d"); $data = "\x48\145\154\x6c\x6f"; $length = strlen($data); $stream = fopen("\160\150\x70\72\57\57\164\x65\155\x70", "\x72\53"); $filter = stream_filter_append($stream, $specificFilterName, STREAM_FILTER_WRITE, array("\x6b\145\171" => $key, "\x69\x76" => $iv)); fwrite($stream, $data); rewind($stream); stream_filter_remove($filter); stream_filter_append($stream, $specificUnfilterName, STREAM_FILTER_READ, array("\153\145\x79" => $key, "\x69\x76" => $iv)); $body = $this->getStreamFactory()->createStreamFromResource($stream); $response = $this->createResponse()->withHeader("\x43\157\x6e\x74\145\156\x74\x2d\x4c\145\156\147\x74\x68", $length)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("\x48\x65\154\154\x6f"); } else { $this->assertTrue(true); } } public function testRespondIndeterminateLength() : void { $stream = fopen("\160\x68\x70\72\x2f\57\164\x65\155\x70", "\x72\x2b"); fwrite($stream, "\x48\145\154\x6c\157"); rewind($stream); $body = $this->getMockBuilder(MockStream::class)->setConstructorArgs(array($stream))->onlyMethods(array("\147\145\x74\123\151\x7a\x65"))->getMock(); $body->method("\x67\x65\164\123\151\172\145")->willReturn(null); $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("\x48\145\154\154\x6f"); } public function testResponseWithStreamReadYieldingLessBytesThanAsked() : void { $body = new SmallChunksStream(); $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter($body::CHUNK_SIZE * 2); $responseEmitter->emit($response); $this->expectOutputString(str_repeat("\56", $body->getSize())); } public function testResponseReplacesPreviouslySetHeaders() : void { $response = $this->createResponse(200, "\117\113")->withHeader("\x58\x2d\x46\157\x6f", "\142\141\x7a\61")->withAddedHeader("\x58\55\x46\157\157", "\x62\141\172\x32"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $expectedStack = array(array("\x68\x65\141\x64\145\162" => "\130\x2d\x46\x6f\x6f\x3a\x20\x62\x61\172\x31", "\x72\145\x70\154\141\143\145" => true, "\x73\164\x61\x74\x75\x73\137\x63\x6f\x64\145" => null), array("\150\x65\141\144\145\162" => "\x58\x2d\106\x6f\x6f\x3a\x20\x62\141\x7a\62", "\162\x65\x70\x6c\141\143\145" => false, "\x73\x74\141\x74\x75\x73\137\x63\157\x64\x65" => null), array("\x68\x65\141\x64\145\x72" => "\x48\124\x54\x50\57\61\56\x31\40\x32\x30\60\x20\117\113", "\x72\145\160\154\141\143\x65" => true, "\163\x74\x61\x74\x75\163\137\143\157\144\145" => 200)); $this->assertSame($expectedStack, HeaderStack::stack()); } public function testResponseDoesNotReplacePreviouslySetSetCookieHeaders() : void { $response = $this->createResponse(200, "\x4f\x4b")->withHeader("\163\x65\164\x2d\143\117\x4f\x6b\151\x65", "\x66\157\157\x3d\142\141\x72")->withAddedHeader("\x53\x65\164\55\103\x6f\x6f\153\x69\x65", "\142\x61\x72\75\142\x61\x7a"); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $expectedStack = array(array("\150\x65\141\x64\x65\x72" => "\163\x65\164\55\x63\117\x4f\153\151\145\x3a\40\x66\157\x6f\75\x62\x61\162", "\162\145\x70\154\141\x63\145" => false, "\163\x74\x61\164\165\x73\137\x63\x6f\x64\x65" => null), array("\x68\145\x61\x64\x65\x72" => "\163\x65\164\55\143\117\x4f\x6b\x69\x65\72\40\142\x61\162\x3d\142\141\x7a", "\162\145\x70\154\x61\143\x65" => false, "\163\x74\x61\164\x75\163\x5f\x63\157\x64\x65" => null), array("\150\x65\x61\144\x65\x72" => "\x48\124\x54\120\x2f\61\56\61\40\x32\x30\60\40\117\x4b", "\162\145\x70\154\141\x63\145" => true, "\163\x74\141\164\x75\x73\x5f\143\x6f\x64\145" => 200)); $this->assertSame($expectedStack, HeaderStack::stack()); } public function testIsResponseEmptyWithNonEmptyBodyAndTriggeringStatusCode() : void { $body = $this->createStream("\x48\x65\x6c\x6c\x6f"); $response = $this->createResponse(204)->withBody($body); $responseEmitter = new ResponseEmitter(); $this->assertTrue($responseEmitter->isResponseEmpty($response)); } public function testIsResponseEmptyDoesNotReadAllDataFromNonEmptySeekableResponse() : void { $body = $this->createStream("\110\145\x6c\154\x6f"); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->isResponseEmpty($response); $this->assertTrue($body->isSeekable()); $this->assertFalse($body->eof()); } public function testIsResponseEmptyDoesNotDrainNonSeekableResponseWithContent() : void { $resource = popen("\x65\x63\x68\157\x20\61\62", "\x72"); $body = $this->getStreamFactory()->createStreamFromResource($resource); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->isResponseEmpty($response); $this->assertFalse($body->isSeekable()); $this->assertSame("\x31\x32", trim((string) $body)); } public function testAvoidReadFromSlowStreamAccordingToStatus() : void { $body = new SlowPokeStream(); $response = $this->createResponse(204, "\116\x6f\x20\143\x6f\156\164\x65\x6e\164")->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->assertFalse($body->eof()); $this->expectOutputString(''); } public function testIsResponseEmptyWithEmptyBody() : void { $response = $this->createResponse(200); $responseEmitter = new ResponseEmitter(); $this->assertTrue($responseEmitter->isResponseEmpty($response)); } public function testIsResponseEmptyWithZeroAsBody() : void { $body = $this->createStream("\60"); $response = $this->createResponse(200)->withBody($body); $responseEmitter = new ResponseEmitter(); $this->assertFalse($responseEmitter->isResponseEmpty($response)); } public function testWillHandleInvalidConnectionStatusWithADeterminateBody() : void { $body = $this->getStreamFactory()->createStreamFromResource(fopen("\x70\x68\x70\x3a\57\x2f\x74\145\x6d\x70", "\162\x2b")); $body->write("\x48\x65\154\x6c\x6f\x21" . "\12"); $body->write("\x48\x65\x6c\154\x6f\x21" . "\xa"); $GLOBALS["\x63\x6f\156\x6e\145\143\164\151\x6f\156\x5f\x73\x74\141\x74\165\x73\137\x72\145\164\165\x72\x6e"] = CONNECTION_ABORTED; $response = $this->createResponse()->withHeader("\x43\x6f\156\x74\x65\156\x74\x2d\114\x65\156\x67\x74\x68", $body->getSize())->withBody($body); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); $this->expectOutputString("\110\x65\x6c\154\157\41\xa\110\145\154\x6c\157\x21\xa"); unset($GLOBALS["\x63\x6f\156\156\x65\143\x74\x69\x6f\156\137\x73\164\x61\x74\165\x73\x5f\162\x65\x74\165\162\156"]); } public function testWillHandleInvalidConnectionStatusWithAnIndeterminateBody() : void { $body = $this->getStreamFactory()->createStreamFromResource(fopen("\x70\150\x70\72\57\x2f\151\156\160\x75\164", "\x72\53")); $GLOBALS["\x63\x6f\156\x6e\x65\143\x74\151\x6f\156\x5f\x73\164\x61\164\x75\163\137\162\145\164\165\162\x6e"] = CONNECTION_TIMEOUT; $response = $this->createResponse()->withBody($body); $responseEmitter = new ResponseEmitter(); $mirror = new ReflectionClass(ResponseEmitter::class); $emitBodyMethod = $mirror->getMethod("\x65\155\151\164\102\157\144\171"); $emitBodyMethod->setAccessible(true); $emitBodyMethod->invoke($responseEmitter, $response); $this->expectOutputString(''); unset($GLOBALS["\x63\x6f\x6e\x6e\145\x63\x74\151\157\x6e\137\163\x74\x61\164\165\163\137\162\x65\164\x75\x72\x6e"]); } }

Function Calls

None

Variables

None

Stats

MD5 8e849dc41fa5efe130858922de707077
Eval Count 0
Decode Time 97 ms