#include "test.h"
__FBSDID("$FreeBSD$");
+#ifdef HAVE_LIBZ
+static const int libz_enabled = 1;
+#else
+static const int libz_enabled = 0;
+#endif
+
DEFINE_TEST(test_read_format_zip_traditional_encryption_data)
{
/* This file is password protected (Traditional PKWARE Enctypted).
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
/* Verify encrypted file "foo.txt" */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
assertEqualInt(2, archive_file_count(a));
#include "test.h"
__FBSDID("$FreeBSD$");
+#ifdef HAVE_LIBZ
+static const int libz_enabled = 1;
+#else
+static const int libz_enabled = 0;
+#endif
+
static void
-test_winzip_aes(const char *refname)
+test_winzip_aes(const char *refname, int need_libz)
{
struct archive_entry *ae;
struct archive *a;
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ if (!need_libz || libz_enabled) {
+ assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
assertEqualInt(1, archive_file_count(a));
DEFINE_TEST(test_read_format_zip_winzip_aes128)
{
/* WinZip AES-128 encryption. */
- test_winzip_aes("test_read_format_zip_winzip_aes128.zip");
+ test_winzip_aes("test_read_format_zip_winzip_aes128.zip", 1);
}
DEFINE_TEST(test_read_format_zip_winzip_aes256)
{
/* WinZip AES-256 encryption. */
- test_winzip_aes("test_read_format_zip_winzip_aes256.zip");
+ test_winzip_aes("test_read_format_zip_winzip_aes256.zip", 1);
}
DEFINE_TEST(test_read_format_zip_winzip_aes256_stored)
{
/* WinZip AES-256 encryption with stored data. */
- test_winzip_aes("test_read_format_zip_winzip_aes256_stored.zip");
+ test_winzip_aes("test_read_format_zip_winzip_aes256_stored.zip", 0);
}
#include "test.h"
__FBSDID("$FreeBSD$");
+#ifdef HAVE_LIBZ
+static const int libz_enabled = 1;
+#else
+static const int libz_enabled = 0;
+#endif
+
DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
{
const char *refname = "test_read_format_zip_winzip_aes256_large.zip";
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
/* Verify encrypted file "NEWS" */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
/* Verify encrypted file "README" */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
/* Verify encrypted file "config.h" */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ if (libz_enabled) {
+ assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
+ } else {
+ assertEqualInt(ARCHIVE_FAILED,
+ archive_read_data(a, buff, sizeof(buff)));
+ assertEqualString(archive_error_string(a),
+ "Unsupported ZIP compression method (deflation)");
+ assert(archive_errno(a) != 0);
+ }
assertEqualInt(4, archive_file_count(a));