From e4850cba6fd67a6d4d9d8c969281e57447c17fd9 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 2 Sep 2018 18:58:32 -0400 Subject: add tests/ and composer test script --- tests/PathTest.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/PathTest.php (limited to 'tests/PathTest.php') diff --git a/tests/PathTest.php b/tests/PathTest.php new file mode 100644 index 0000000..a71be8d --- /dev/null +++ b/tests/PathTest.php @@ -0,0 +1,83 @@ +expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('', 'empty test'); + }); + } + + public function testAddLongPath() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $long_path = str_repeat('x', 65535); + $zip->add_file($long_path, 'long path test'); + }); + } + + public function testAddPathWithLeadingSlash() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('/foo', 'leading slash path test'); + }); + } + + public function testAddPathWithTrailingSlash() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('foo/', 'trailing slash path test'); + }); + } + + public function testAddPathWithDoubleSlashes() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('foo//bar', 'double slash path test'); + }); + } + + public function testAddPathWithBackslashes() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('foo\\bar', 'backslash path test'); + }); + } + + public function testLeadingRelativePath() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('../bar', 'leading relative path test'); + }); + } + + public function testMiddleRelativePath() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('foo/../bar', 'middle relative path test'); + }); + } + + public function testTrailingRelativePath() : void { + $this->expectException(\Pablotron\ZipStream\PathError::class); + + $this->with_temp_zip(function(ZipStream &$zip) { + $zip->add_file('foo/../bar', 'trailing relative path test'); + }); + } + +}; -- cgit v1.2.3