Skip to content

Commit ee692ff

Browse files
committed
Simplify test
1 parent 474b771 commit ee692ff

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

tests/unit/zip/ZipFunctionsTest.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,17 @@
33
namespace unit\zip;
44

55
use PHPUnitTestCase;
6-
use Symfony\Component\Filesystem\Filesystem;
76
use Symfony\Component\Filesystem\Path;
8-
use ZipArchive;
97
use function WordPress\Zip\zip_extract_to;
108

119
class ZipFunctionsTest extends PHPUnitTestCase {
1210
public function testIsImmuneToZipSlipVulnerability() {
13-
$filesystem = new Filesystem();
11+
// zipped file named: "../../../../../../../../tmp/zip-slip-test.txt"
12+
$zip = __DIR__ . '/resources/zip-slip-test.zip';
1413

15-
$filename = __DIR__ . 'tmp/zip-slip-test.zip';
16-
$filesystem->mkdir( dirname( $filename ) );
14+
zip_extract_to( fopen( $zip, 'rb' ), dirname( $zip ) );
1715

18-
$zip = new ZipArchive();
19-
$zip->open( $filename, ZipArchive::CREATE );
20-
$zip->addFromString( "../../../../../../../../tmp/zip-slip-test.txt" . time(), "zip slip test" );
21-
$zip->close();
22-
23-
zip_extract_to( fopen( $filename, 'rb' ), dirname( $filename ) );
24-
25-
$slipped_dir = Path::canonicalize(__DIR__ . "../../../../../../../../tmp");
26-
self::assertDirectoryDoesNotExist( $slipped_dir );
27-
28-
$filesystem->remove( dirname( $filename ) );
16+
$slipped_file = Path::canonicalize(__DIR__ . "../../../../../../../../tmp/zip-slip-test.txt");
17+
self::assertFileDoesNotExist( $slipped_file );
2918
}
30-
}
19+
}
201 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)