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 Piwik\Tests\Integration; use Exception; use Piwik\ProxyHttp; use Piwik\Se..

Decoded Output download

<?php
 namespace Piwik\Tests\Integration; use Exception; use Piwik\ProxyHttp; use Piwik\SettingsServer; use Piwik\Tests\Framework\Fixture; define("TEST_FILE_LOCATION", realpath(dirname(__FILE__) . "/../../resources/lipsum.txt")); define("TEST_FILE_CONTENT_TYPE", "text/plain"); define("FILE_MODE_REQUEST_VAR", "fileMode"); define("SRV_MODE_REQUEST_VAR", "serverMode"); define("ZLIB_OUTPUT_REQUEST_VAR", "zlibOutput"); define("STATIC_SERVER_MODE", "staticServerMode"); define("UNIT_TEST_MODE", "unitTestMode"); define("NULL_FILE_SRV_MODE", "nullFile"); define("GHOST_FILE_SRV_MODE", "ghostFile"); define("TEST_FILE_SRV_MODE", "testFile"); define("PARTIAL_TEST_FILE_SRV_MODE", "partialTestFile"); define("WHOLE_TEST_FILE_WITH_RANGE_SRV_MODE", "wholeTestFileWithRange"); define("PARTIAL_BYTE_START", 1204); define("PARTIAL_BYTE_END", 14724); class ServeStaticFileTest extends \PHPUnit\Framework\TestCase { public function tearDown() : void { parent::tearDown(); if (!chmod(TEST_FILE_LOCATION, 420)) { throw new Exception("Could not chmod 0644 " . TEST_FILE_LOCATION); } } public function test_phpOutputCompression() { $this->assertFalse(ProxyHttp::isPhpOutputCompressed()); } public function test_nullFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getNullFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["http_code"], 404); } public function test_ghostFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getGhostFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["http_code"], 404); } public function test_nonReadableFile() { if (SettingsServer::isWindows()) { return; } chmod(TEST_FILE_LOCATION, 128); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url = $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); chmod(TEST_FILE_LOCATION, 420); $this->assertEquals($responseInfo["http_code"], 500); } public function test_firstAccessNoCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_HEADER, true); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals(200, $responseInfo["http_code"]); self::assertStringContainsString(TEST_FILE_CONTENT_TYPE, $responseInfo["content_type"]); $this->assertNull($this->getContentEncodingValue($fullResponse)); $this->assertEquals(filesize(TEST_FILE_LOCATION), $responseInfo["size_download"]); $this->assertEquals(gmdate("D, d M Y H:i:s", filemtime(TEST_FILE_LOCATION)) . " GMT", $this->getLastModifiedValue($fullResponse)); $this->assertEquals("public, must-revalidate", $this->getCacheControlValue($fullResponse)); $pragma = $this->getPragma($fullResponse); $this->assertTrue($pragma == null || $pragma == "Pragma:"); $expires = $this->getExpires($fullResponse); $this->assertTrue(strtotime($expires) > time() + 99 * 86400); } public function test_secondAccessNoCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_TIMECONDITION, 1); curl_setopt($curlHandle, CURLOPT_TIMEVALUE, filemtime(TEST_FILE_LOCATION)); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["http_code"], 304); } public function test_secondAccessNoCompressionExpiredFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_TIMECONDITION, 1); curl_setopt($curlHandle, CURLOPT_TIMEVALUE, filemtime(TEST_FILE_LOCATION) - 1); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["http_code"], 200); } public function test_responseReadableWithPhpCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->setZlibOutputRequest($this->getTestFileSrvModeUrl())); curl_setopt($curlHandle, CURLOPT_ENCODING, ''); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); } public function test_deflateCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); $deflateFileLocation = $this->getCompressedFileLocation() . ".deflate"; $this->assertFileExists($deflateFileLocation); $this->assertEquals(gzinflate(file_get_contents($deflateFileLocation)), file_get_contents(TEST_FILE_LOCATION)); $this->removeCompressedFiles(); } public function test_gzipCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "gzip"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); $gzipFileLocation = $this->getCompressedFileLocation() . ".gz"; $this->assertFileExists($gzipFileLocation); $this->removeCompressedFiles(); } public function test_compressionCache() { $this->removeCompressedFiles(); $deflateFileLocation = $this->getCompressedFileLocation() . ".deflate"; $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); $firstAccessModificationTime = filemtime($deflateFileLocation); sleep(1); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertEquals($firstAccessModificationTime, filemtime($deflateFileLocation)); $this->removeCompressedFiles(); } public function test_compressionCacheInvalidation() { $this->removeCompressedFiles(); $deflateFileLocation = $this->getCompressedFileLocation() . ".deflate"; $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); $firstAccessModificationTime = filemtime($deflateFileLocation); sleep(1); touch(TEST_FILE_LOCATION); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertNotEquals($firstAccessModificationTime, filemtime($deflateFileLocation)); $this->removeCompressedFiles(); } public function test_partialFileServeNoCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getPartialTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $partialResponse = curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFalse(file_exists($this->getCompressedFileLocation() . ".deflate")); $this->assertFalse(file_exists($this->getCompressedFileLocation() . ".gz")); $this->assertEquals(PARTIAL_BYTE_END - PARTIAL_BYTE_START, $responseInfo["size_download"]); $expectedPartialContents = substr(file_get_contents(TEST_FILE_LOCATION), PARTIAL_BYTE_START, PARTIAL_BYTE_END - PARTIAL_BYTE_START); $this->assertEquals($expectedPartialContents, $partialResponse); } public function test_partialFileServeWithCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getPartialTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); $partialResponse = curl_exec($curlHandle); curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFileExists($this->getCompressedFileLocation() . "." . PARTIAL_BYTE_START . "." . PARTIAL_BYTE_END . ".deflate"); $this->assertFileNotExists($this->getCompressedFileLocation() . ".gz"); $expectedPartialContents = substr(file_get_contents(TEST_FILE_LOCATION), PARTIAL_BYTE_START, PARTIAL_BYTE_END - PARTIAL_BYTE_START); $this->assertEquals($expectedPartialContents, $partialResponse); $this->removeCompressedFiles(); } public function test_wholeFileServeWithByteRange() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getWholeTestFileWithRangeSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_ENCODING, "deflate"); $fullResponse = curl_exec($curlHandle); curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFileExists($this->getCompressedFileLocation() . ".deflate"); $this->assertFileNotExists($this->getCompressedFileLocation() . ".gz"); $this->assertEquals(file_get_contents(TEST_FILE_LOCATION), $fullResponse); $this->removeCompressedFiles(); } private function getStaticSrvUrl() { $url = Fixture::getRootUrl(); $url .= "/tests/resources/"; return $url . "staticFileServer.php?" . FILE_MODE_REQUEST_VAR . "=" . STATIC_SERVER_MODE . "&" . SRV_MODE_REQUEST_VAR . "="; } private function getNullFileSrvModeUrl() { return $this->getStaticSrvUrl() . NULL_FILE_SRV_MODE; } private function getGhostFileSrvModeUrl() { return $this->getStaticSrvUrl() . GHOST_FILE_SRV_MODE; } private function getTestFileSrvModeUrl() { return $this->getStaticSrvUrl() . TEST_FILE_SRV_MODE; } private function getPartialTestFileSrvModeUrl() { return $this->getStaticSrvUrl() . PARTIAL_TEST_FILE_SRV_MODE; } private function getWholeTestFileWithRangeSrvModeUrl() { return $this->getStaticSrvUrl() . WHOLE_TEST_FILE_WITH_RANGE_SRV_MODE; } private function setZlibOutputRequest($url) { return $url . "&" . ZLIB_OUTPUT_REQUEST_VAR . "=1"; } private function getContentEncodingValue($fullResponse) { preg_match_all("/Content-Encoding:[\s*]([[:print:]]*)/", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getCacheControlValue($fullResponse) { preg_match_all("/Cache-Control:[\s*]([[:print:]]*)/", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getPragma($fullResponse) { preg_match_all("/(Pragma:[[:print:]]*)/", $fullResponse, $matches); if (isset($matches[1][0])) { return trim($matches[1][0]); } return null; } private function getExpires($fullResponse) { preg_match_all("/Expires: ([[:print:]]*)/", $fullResponse, $matches); if (isset($matches[1][0])) { return trim($matches[1][0]); } return null; } private function getLastModifiedValue($fullResponse) { preg_match_all("/Last-Modified:[\s*]([[:print:]]*)/", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getCompressedFileLocation() { return \Piwik\AssetManager::getInstance()->getAssetDirectory() . "/" . basename(TEST_FILE_LOCATION); } private function removeCompressedFiles() { @unlink($this->getCompressedFileLocation() . ".deflate"); @unlink($this->getCompressedFileLocation() . ".gz"); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Piwik\Tests\Integration; use Exception; use Piwik\ProxyHttp; use Piwik\SettingsServer; use Piwik\Tests\Framework\Fixture; define("\x54\x45\x53\124\x5f\106\x49\114\x45\137\x4c\x4f\103\x41\124\x49\x4f\x4e", realpath(dirname(__FILE__) . "\x2f\56\56\57\x2e\56\x2f\162\x65\x73\157\x75\x72\143\x65\x73\57\154\x69\160\x73\165\x6d\x2e\164\170\164")); define("\124\x45\x53\x54\x5f\106\x49\x4c\x45\x5f\103\117\116\124\x45\116\x54\x5f\124\131\120\x45", "\x74\145\170\164\x2f\160\x6c\x61\x69\x6e"); define("\106\x49\114\105\137\x4d\x4f\104\105\137\x52\x45\121\x55\105\123\x54\137\126\101\122", "\146\x69\154\145\115\x6f\x64\x65"); define("\x53\x52\126\x5f\x4d\x4f\x44\105\137\x52\105\x51\x55\105\x53\124\x5f\x56\101\x52", "\x73\x65\x72\166\145\162\x4d\157\x64\145"); define("\x5a\114\x49\x42\137\x4f\125\124\x50\x55\x54\x5f\122\105\x51\x55\x45\123\124\137\x56\x41\x52", "\172\x6c\151\142\117\165\x74\x70\165\x74"); define("\x53\124\x41\x54\x49\x43\x5f\x53\x45\x52\126\105\122\x5f\x4d\x4f\104\x45", "\x73\164\x61\x74\x69\x63\x53\x65\162\166\x65\162\115\x6f\144\x65"); define("\125\x4e\x49\124\x5f\124\105\x53\x54\137\x4d\117\x44\105", "\165\x6e\151\x74\x54\145\163\x74\x4d\157\x64\x65"); define("\x4e\x55\x4c\114\x5f\106\111\x4c\105\x5f\123\122\x56\x5f\x4d\117\104\x45", "\156\165\x6c\154\x46\151\154\145"); define("\x47\110\x4f\x53\124\137\106\111\x4c\105\x5f\x53\122\126\x5f\115\117\x44\105", "\147\x68\157\x73\x74\x46\151\154\x65"); define("\x54\105\x53\124\137\x46\x49\114\x45\137\x53\x52\x56\x5f\115\x4f\104\105", "\164\x65\x73\x74\106\151\154\145"); define("\120\x41\x52\x54\x49\101\114\x5f\124\105\123\124\137\106\111\x4c\x45\137\123\x52\126\x5f\115\x4f\x44\105", "\x70\x61\x72\x74\151\141\x6c\124\145\163\x74\106\151\x6c\x65"); define("\127\110\x4f\114\105\137\x54\x45\123\x54\x5f\106\x49\x4c\105\x5f\x57\x49\x54\x48\x5f\122\x41\x4e\x47\x45\x5f\x53\x52\126\137\115\117\104\105", "\167\x68\x6f\154\145\x54\x65\163\x74\106\x69\154\x65\127\x69\164\150\122\x61\156\x67\145"); define("\x50\x41\x52\x54\x49\x41\x4c\137\102\131\x54\x45\x5f\123\x54\101\122\124", 1204); define("\x50\x41\122\124\111\x41\114\137\102\131\x54\105\x5f\105\116\x44", 14724); class ServeStaticFileTest extends \PHPUnit\Framework\TestCase { public function tearDown() : void { parent::tearDown(); if (!chmod(TEST_FILE_LOCATION, 420)) { throw new Exception("\103\x6f\x75\154\144\x20\156\x6f\164\x20\143\x68\x6d\x6f\144\40\60\x36\x34\x34\x20" . TEST_FILE_LOCATION); } } public function test_phpOutputCompression() { $this->assertFalse(ProxyHttp::isPhpOutputCompressed()); } public function test_nullFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getNullFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["\150\164\164\160\137\143\x6f\144\x65"], 404); } public function test_ghostFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getGhostFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["\150\164\164\160\137\143\157\x64\x65"], 404); } public function test_nonReadableFile() { if (SettingsServer::isWindows()) { return; } chmod(TEST_FILE_LOCATION, 128); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url = $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); chmod(TEST_FILE_LOCATION, 420); $this->assertEquals($responseInfo["\x68\164\x74\160\x5f\143\157\144\145"], 500); } public function test_firstAccessNoCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_HEADER, true); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals(200, $responseInfo["\x68\164\x74\160\x5f\x63\x6f\144\145"]); self::assertStringContainsString(TEST_FILE_CONTENT_TYPE, $responseInfo["\143\x6f\x6e\164\145\156\164\x5f\x74\x79\x70\x65"]); $this->assertNull($this->getContentEncodingValue($fullResponse)); $this->assertEquals(filesize(TEST_FILE_LOCATION), $responseInfo["\x73\x69\x7a\145\137\x64\157\167\156\x6c\157\x61\144"]); $this->assertEquals(gmdate("\104\54\x20\144\x20\x4d\x20\x59\x20\x48\72\x69\72\x73", filemtime(TEST_FILE_LOCATION)) . "\x20\x47\x4d\124", $this->getLastModifiedValue($fullResponse)); $this->assertEquals("\160\165\x62\154\x69\143\x2c\40\155\165\x73\164\55\x72\145\166\141\x6c\x69\x64\x61\164\145", $this->getCacheControlValue($fullResponse)); $pragma = $this->getPragma($fullResponse); $this->assertTrue($pragma == null || $pragma == "\x50\162\141\147\155\141\x3a"); $expires = $this->getExpires($fullResponse); $this->assertTrue(strtotime($expires) > time() + 99 * 86400); } public function test_secondAccessNoCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_TIMECONDITION, 1); curl_setopt($curlHandle, CURLOPT_TIMEVALUE, filemtime(TEST_FILE_LOCATION)); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["\x68\x74\164\x70\x5f\x63\x6f\x64\145"], 304); } public function test_secondAccessNoCompressionExpiredFile() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_TIMECONDITION, 1); curl_setopt($curlHandle, CURLOPT_TIMEVALUE, filemtime(TEST_FILE_LOCATION) - 1); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); $this->assertEquals($responseInfo["\x68\x74\164\160\x5f\143\157\144\x65"], 200); } public function test_responseReadableWithPhpCompression() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->setZlibOutputRequest($this->getTestFileSrvModeUrl())); curl_setopt($curlHandle, CURLOPT_ENCODING, ''); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); } public function test_deflateCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x64\145\146\x6c\141\164\145"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); $deflateFileLocation = $this->getCompressedFileLocation() . "\x2e\x64\x65\146\154\x61\164\x65"; $this->assertFileExists($deflateFileLocation); $this->assertEquals(gzinflate(file_get_contents($deflateFileLocation)), file_get_contents(TEST_FILE_LOCATION)); $this->removeCompressedFiles(); } public function test_gzipCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x67\x7a\x69\160"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $fullResponse = curl_exec($curlHandle); curl_close($curlHandle); $this->assertEquals($fullResponse, file_get_contents(TEST_FILE_LOCATION)); $gzipFileLocation = $this->getCompressedFileLocation() . "\x2e\147\172"; $this->assertFileExists($gzipFileLocation); $this->removeCompressedFiles(); } public function test_compressionCache() { $this->removeCompressedFiles(); $deflateFileLocation = $this->getCompressedFileLocation() . "\x2e\x64\x65\146\154\141\164\145"; $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\144\x65\146\154\141\x74\145"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); $firstAccessModificationTime = filemtime($deflateFileLocation); sleep(1); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x64\x65\x66\x6c\141\x74\x65"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertEquals($firstAccessModificationTime, filemtime($deflateFileLocation)); $this->removeCompressedFiles(); } public function test_compressionCacheInvalidation() { $this->removeCompressedFiles(); $deflateFileLocation = $this->getCompressedFileLocation() . "\x2e\x64\x65\146\x6c\x61\x74\x65"; $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x64\145\146\x6c\141\x74\x65"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); $firstAccessModificationTime = filemtime($deflateFileLocation); sleep(1); touch(TEST_FILE_LOCATION); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x64\145\x66\154\x61\164\145"); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_exec($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertNotEquals($firstAccessModificationTime, filemtime($deflateFileLocation)); $this->removeCompressedFiles(); } public function test_partialFileServeNoCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getPartialTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); $partialResponse = curl_exec($curlHandle); $responseInfo = curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFalse(file_exists($this->getCompressedFileLocation() . "\56\144\145\x66\x6c\141\164\x65")); $this->assertFalse(file_exists($this->getCompressedFileLocation() . "\56\147\x7a")); $this->assertEquals(PARTIAL_BYTE_END - PARTIAL_BYTE_START, $responseInfo["\163\151\172\145\x5f\144\x6f\167\x6e\x6c\157\141\x64"]); $expectedPartialContents = substr(file_get_contents(TEST_FILE_LOCATION), PARTIAL_BYTE_START, PARTIAL_BYTE_END - PARTIAL_BYTE_START); $this->assertEquals($expectedPartialContents, $partialResponse); } public function test_partialFileServeWithCompression() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getPartialTestFileSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_ENCODING, "\x64\x65\x66\x6c\141\164\145"); $partialResponse = curl_exec($curlHandle); curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFileExists($this->getCompressedFileLocation() . "\x2e" . PARTIAL_BYTE_START . "\56" . PARTIAL_BYTE_END . "\x2e\144\145\146\154\x61\x74\x65"); $this->assertFileNotExists($this->getCompressedFileLocation() . "\x2e\x67\x7a"); $expectedPartialContents = substr(file_get_contents(TEST_FILE_LOCATION), PARTIAL_BYTE_START, PARTIAL_BYTE_END - PARTIAL_BYTE_START); $this->assertEquals($expectedPartialContents, $partialResponse); $this->removeCompressedFiles(); } public function test_wholeFileServeWithByteRange() { $this->removeCompressedFiles(); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->getWholeTestFileWithRangeSrvModeUrl()); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_ENCODING, "\144\145\146\x6c\141\x74\x65"); $fullResponse = curl_exec($curlHandle); curl_getinfo($curlHandle); curl_close($curlHandle); clearstatcache(); $this->assertFileExists($this->getCompressedFileLocation() . "\56\x64\x65\146\x6c\x61\164\145"); $this->assertFileNotExists($this->getCompressedFileLocation() . "\56\x67\x7a"); $this->assertEquals(file_get_contents(TEST_FILE_LOCATION), $fullResponse); $this->removeCompressedFiles(); } private function getStaticSrvUrl() { $url = Fixture::getRootUrl(); $url .= "\57\x74\145\x73\164\x73\57\x72\145\x73\157\165\162\143\x65\163\x2f"; return $url . "\163\164\x61\164\x69\x63\x46\151\154\145\123\x65\162\166\145\162\x2e\160\x68\160\x3f" . FILE_MODE_REQUEST_VAR . "\x3d" . STATIC_SERVER_MODE . "\46" . SRV_MODE_REQUEST_VAR . "\75"; } private function getNullFileSrvModeUrl() { return $this->getStaticSrvUrl() . NULL_FILE_SRV_MODE; } private function getGhostFileSrvModeUrl() { return $this->getStaticSrvUrl() . GHOST_FILE_SRV_MODE; } private function getTestFileSrvModeUrl() { return $this->getStaticSrvUrl() . TEST_FILE_SRV_MODE; } private function getPartialTestFileSrvModeUrl() { return $this->getStaticSrvUrl() . PARTIAL_TEST_FILE_SRV_MODE; } private function getWholeTestFileWithRangeSrvModeUrl() { return $this->getStaticSrvUrl() . WHOLE_TEST_FILE_WITH_RANGE_SRV_MODE; } private function setZlibOutputRequest($url) { return $url . "\x26" . ZLIB_OUTPUT_REQUEST_VAR . "\75\61"; } private function getContentEncodingValue($fullResponse) { preg_match_all("\x2f\103\x6f\156\x74\x65\156\x74\x2d\x45\156\143\x6f\x64\151\156\147\72\x5b\134\x73\x2a\135\50\x5b\x5b\x3a\160\162\151\156\164\72\x5d\x5d\52\x29\x2f", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getCacheControlValue($fullResponse) { preg_match_all("\57\103\141\143\150\x65\55\x43\x6f\x6e\164\x72\x6f\154\x3a\133\134\x73\x2a\135\x28\x5b\x5b\72\160\162\151\x6e\x74\x3a\135\x5d\52\x29\57", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getPragma($fullResponse) { preg_match_all("\57\x28\x50\x72\141\x67\x6d\141\72\133\x5b\72\160\162\x69\x6e\164\x3a\135\135\x2a\51\57", $fullResponse, $matches); if (isset($matches[1][0])) { return trim($matches[1][0]); } return null; } private function getExpires($fullResponse) { preg_match_all("\x2f\105\170\160\151\x72\145\163\x3a\x20\x28\x5b\133\x3a\160\x72\151\156\164\x3a\x5d\x5d\52\51\57", $fullResponse, $matches); if (isset($matches[1][0])) { return trim($matches[1][0]); } return null; } private function getLastModifiedValue($fullResponse) { preg_match_all("\x2f\114\141\x73\164\55\115\x6f\x64\x69\146\x69\145\x64\x3a\x5b\x5c\163\52\135\x28\x5b\133\x3a\160\x72\x69\156\x74\x3a\x5d\x5d\52\51\x2f", $fullResponse, $matches); if (isset($matches[1][0])) { return $matches[1][0]; } return null; } private function getCompressedFileLocation() { return \Piwik\AssetManager::getInstance()->getAssetDirectory() . "\57" . basename(TEST_FILE_LOCATION); } private function removeCompressedFiles() { @unlink($this->getCompressedFileLocation() . "\x2e\x64\145\x66\154\141\x74\145"); @unlink($this->getCompressedFileLocation() . "\56\x67\x7a"); } }

Function Calls

None

Variables

None

Stats

MD5 0fa9dd6ad4d07fe28d235b1c0507cee1
Eval Count 0
Decode Time 80 ms