1
0
mirror of https://github.com/php/php-src.git synced 2026-04-24 16:38:25 +02:00
Files
archived-php-src/ext/zip/tests/bug80833.phpt
Peter Kokot 218a93b898 Use EXTENSIONS instead of SKIPIF sections in *.phpt
This also fixes skipped tests due to different naming "zend-test"
instead of "zend_test" and "PDO" instead of "pdo":

- ext/dom/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/simplexml/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/xmlreader/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/zend_test/tests/observer_sqlite_create_function.phpt

EXTENSIONS section is used for the Windows build to load the non-static
extensions.

Closes GH-13276
2024-01-31 11:18:21 +01:00

59 lines
1.8 KiB
PHP

--TEST--
Bug #80833 (ZipArchive::getStream doesn't use setPassword)
--EXTENSIONS--
zip
--SKIPIF--
<?php
if (!method_exists('ZipArchive', 'setEncryptionName')) die('skip encryption not supported');
?>
--FILE--
<?php
$create_zip = new ZipArchive();
$create_zip->open(__DIR__ . "/80833.zip", ZipArchive::CREATE);
$create_zip->setPassword("default_password");
$create_zip->addFromString("test.txt", "This is a test string.");
$create_zip->setEncryptionName("test.txt", ZipArchive::EM_AES_256, "first_password");
$create_zip->addFromString("test2.txt", "This is another test string.");
$create_zip->setEncryptionName("test2.txt", ZipArchive::EM_AES_256, "second_password");
$create_zip->close();
// Stream API
$o = [
'zip' => [
'password' => "first_password",
],
];
$c = stream_context_create($o);
var_dump(file_get_contents("zip://" . __DIR__ . "/80833.zip#test.txt", false, $c));
// getStream method
$extract_zip = new ZipArchive();
$extract_zip->open(__DIR__ . "/80833.zip", ZipArchive::RDONLY);
$extract_zip->setPassword("first_password");
$file_stream = $extract_zip->getStream("test.txt");
var_dump(stream_get_contents($file_stream));
fclose($file_stream);
$extract_zip->setPassword("second_password");
$file_stream = $extract_zip->getStream("test2.txt");
var_dump(stream_get_contents($file_stream));
fclose($file_stream);
// Archive close before the stream
$extract_zip->setPassword("first_password");
$file_stream = $extract_zip->getStream("test.txt");
$extract_zip->close();
var_dump(stream_get_contents($file_stream));
fclose($file_stream);
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/80833.zip");
?>
--EXPECTF--
string(22) "This is a test string."
string(22) "This is a test string."
string(28) "This is another test string."
Warning: stream_get_contents(): Zip stream error: Containing zip archive was closed in %s
string(0) ""