This commit is contained in:
2022-11-25 21:21:30 +01:00
parent 2d6df0d5f0
commit 94deb06f52
132 changed files with 44887 additions and 41368 deletions

View File

@@ -1,4 +1,5 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
@@ -12,97 +13,102 @@ use Domframework\Outputdl;
/** Test the Outputdl.php file */
class OutputdlTest extends \PHPUnit_Framework_TestCase
{
public function test_outputdl_init ()
{
exec ("rm -f /tmp/testDFWoutputDL*");
file_put_contents ("/tmp/testDFWoutputDL",
str_repeat (
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000)
);
symlink ("/etc/passwd", "/tmp/testDFWoutputDL2");
symlink ("/tmp/testDFWoutputDL", "/tmp/testDFWoutputDL3");
}
public function test_outputdl_init()
{
exec("rm -f /tmp/testDFWoutputDL*");
file_put_contents(
"/tmp/testDFWoutputDL",
str_repeat(
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000
)
);
symlink("/etc/passwd", "/tmp/testDFWoutputDL2");
symlink("/tmp/testDFWoutputDL", "/tmp/testDFWoutputDL3");
}
public function test_outputdl_1 ()
{
// Check the full download content
$outputdl = new Outputdl ();
$this->expectOutputString (str_repeat (
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000));
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_1()
{
// Check the full download content
$outputdl = new Outputdl();
$this->expectOutputString(str_repeat(
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000
));
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_Announce_1 ()
{
// Check the announce of Resume mode Enabled
$outputdl = new Outputdl ();
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
$res = $outputdl->headers ();
$this->assertSame (in_array ("Accept-Ranges: bytes", $res), true);
}
public function test_outputdl_Announce_1()
{
// Check the announce of Resume mode Enabled
$outputdl = new Outputdl();
$outputdl->downloadFile("/tmp/testDFWoutputDL");
$res = $outputdl->headers();
$this->assertSame(in_array("Accept-Ranges: bytes", $res), true);
}
public function test_outputdl_Announce_2 ()
{
// Check the announce of Resume mode Disabled
$outputdl = new Outputdl ();
$outputdl->resumeAllow (false);
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
$res = $outputdl->headers ();
$this->assertSame (in_array ("Accept-Ranges: none", $res), true);
}
public function test_outputdl_Announce_2()
{
// Check the announce of Resume mode Disabled
$outputdl = new Outputdl();
$outputdl->resumeAllow(false);
$outputdl->downloadFile("/tmp/testDFWoutputDL");
$res = $outputdl->headers();
$this->assertSame(in_array("Accept-Ranges: none", $res), true);
}
public function test_outputdl_Partial_1 ()
{
// Check the content get with provided range
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=3-9";
$this->expectOutputString ("4567890");
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
unset ($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_1()
{
// Check the content get with provided range
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=3-9";
$this->expectOutputString("4567890");
$outputdl->downloadFile("/tmp/testDFWoutputDL");
unset($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_2 ()
{
// Check the content get with provided range
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=3-";
$this->expectOutputString (substr (str_repeat (
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000), 3));
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
unset ($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_2()
{
// Check the content get with provided range
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=3-";
$this->expectOutputString(substr(str_repeat(
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000
), 3));
$outputdl->downloadFile("/tmp/testDFWoutputDL");
unset($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_3 ()
{
// Check the content get with provided range
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=0-";
$this->expectOutputString (str_repeat (
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000));
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
unset ($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_3()
{
// Check the content get with provided range
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=0-";
$this->expectOutputString(str_repeat(
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000
));
$outputdl->downloadFile("/tmp/testDFWoutputDL");
unset($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_4 ()
{
// Check the content get with provided range
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=-5";
$this->expectOutputString ("wxyz\n");
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
unset ($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_4()
{
// Check the content get with provided range
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=-5";
$this->expectOutputString("wxyz\n");
$outputdl->downloadFile("/tmp/testDFWoutputDL");
unset($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_Partial_5 ()
{
// Check the content get with provided range
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=0-3,6-9";
$this->expectOutputString ("--Qm91bmRhcnk=\r
public function test_outputdl_Partial_5()
{
// Check the content get with provided range
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=0-3,6-9";
$this->expectOutputString("--Qm91bmRhcnk=\r
Content-Range: bytes 0-3/63000\r
Content-Type: application/octet-stream\r
\r
@@ -114,92 +120,102 @@ Content-Type: application/octet-stream\r
7890\r
--Qm91bmRhcnk=--\r
");
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
unset ($_SERVER["HTTP_RANGE"]);
}
$outputdl->downloadFile("/tmp/testDFWoutputDL");
unset($_SERVER["HTTP_RANGE"]);
}
public function test_outputdl_PartialWrong_1 ()
{
// Check the invalid provided range
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=99999-";
$this->expectException ("Exception", "Invalid range provided", 416);
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_1()
{
// Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=99999-";
$this->expectException("Exception", "Invalid range provided", 416);
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_2 ()
{
// Check the invalid provided range
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=9-3";
$this->expectException ("Exception", "Invalid range provided", 416);
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_2()
{
// Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=9-3";
$this->expectException("Exception", "Invalid range provided", 416);
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_3 ()
{
// Check the invalid provided range
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=9-999999";
$this->expectException ("Exception", "Invalid range provided", 416);
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_3()
{
// Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=9-999999";
$this->expectException("Exception", "Invalid range provided", 416);
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_4 ()
{
// Check the invalid provided range
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$_SERVER["HTTP_RANGE"] = "bytes=-";
$this->expectException ("Exception", "Invalid range provided", 416);
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_PartialWrong_4()
{
// Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$_SERVER["HTTP_RANGE"] = "bytes=-";
$this->expectException("Exception", "Invalid range provided", 416);
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_invalidBase_1 ()
{
// Check the base comparison : OK
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$outputdl->base ("/tmp");
$this->expectOutputString (str_repeat (
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000));
$outputdl->downloadFile ("/tmp/testDFWoutputDL");
}
public function test_outputdl_invalidBase_1()
{
// Check the base comparison : OK
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$outputdl->base("/tmp");
$this->expectOutputString(str_repeat(
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
1000
));
$outputdl->downloadFile("/tmp/testDFWoutputDL");
}
public function test_outputdl_invalidBase_2 ()
{
// Check the base comparison : BAD
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$outputdl->base ("/tmp");
$this->expectException ("Exception",
"Invalid file to download : out of base", 406);
$outputdl->downloadFile ("../../../../../..//etc/passwd");
}
public function test_outputdl_invalidBase_2()
{
// Check the base comparison : BAD
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$outputdl->base("/tmp");
$this->expectException(
"Exception",
"Invalid file to download : out of base",
406
);
$outputdl->downloadFile("../../../../../..//etc/passwd");
}
public function test_outputdl_invalidFile_1 ()
{
// Check the base comparison : BAD Symlink
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$outputdl->base ("/tmp");
$this->expectException ("Exception",
"Invalid file to download : not a file", 406);
$outputdl->downloadFile ("/tmp/testDFWoutputDL3");
}
public function test_outputdl_invalidFile_1()
{
// Check the base comparison : BAD Symlink
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$outputdl->base("/tmp");
$this->expectException(
"Exception",
"Invalid file to download : not a file",
406
);
$outputdl->downloadFile("/tmp/testDFWoutputDL3");
}
public function test_outputdl_invalidFile_2 ()
{
// Check the base comparison : Non existing
unset ($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl ();
$outputdl->base ("/tmp");
$this->expectException ("Exception",
"Invalid file to download : file doesn't exists", 404);
$outputdl->downloadFile ("/tmp/testDFWoutputNON");
}
public function test_outputdl_invalidFile_2()
{
// Check the base comparison : Non existing
unset($_SERVER["HTTP_RANGE"]);
$outputdl = new Outputdl();
$outputdl->base("/tmp");
$this->expectException(
"Exception",
"Invalid file to download : file doesn't exists",
404
);
$outputdl->downloadFile("/tmp/testDFWoutputNON");
}
}