Skip to content

Commit

Permalink
Migrated a test from integration tests to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Feb 11, 2024
1 parent 6f838c5 commit 32c83fa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
21 changes: 0 additions & 21 deletions Source/VFS/tests/VFSArchive_IT.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
[[clang::no_destroy]] static const auto g_Adium = g_Preffix + "adium.app.zip";
[[clang::no_destroy]] static const auto g_Angular = g_Preffix + "angular-1.4.0-beta.4.zip";
[[clang::no_destroy]] static const auto g_Files = g_Preffix + "files-1.1.0(1341).zip";
[[clang::no_destroy]] static const auto g_Encrypted = g_Preffix + "encrypted_archive_pass1.zip";
[[clang::no_destroy]] static const auto g_LZMA = g_Preffix + "lzma-4.32.7.tar.xz";
[[clang::no_destroy]] static const auto g_WarningArchive = g_Preffix + "maverix-master.zip";
[[clang::no_destroy]] static const auto g_ChineseArchive = g_Preffix + "GB18030.zip";
Expand Down Expand Up @@ -178,26 +177,6 @@ static int VFSCompareEntries(const std::filesystem::path &_file1_full_path,
REQUIRE(std::memcmp(d->data(), ref, strlen(ref)) == 0);
}

TEST_CASE(PREFIX "Encrypted")
{
const auto passwd = std::string("pass1");
std::shared_ptr<ArchiveHost> host;
REQUIRE_NOTHROW(
host = std::make_shared<ArchiveHost>(g_Encrypted.c_str(), TestEnv().vfs_native, passwd));
REQUIRE(host->StatTotalFiles() == 2);
REQUIRE(host->StatTotalRegs() == 2);
REQUIRE(host->StatTotalDirs() == 0);

VFSFilePtr file;
auto fn = "/file2";
REQUIRE(host->CreateFile(fn, file, nullptr) == 0);
REQUIRE(file->Open(VFSFlags::OF_Read) == 0);
auto d = file->ReadFile();
REQUIRE(d->size() == 19);
auto ref = "contents of file2.\0A";
REQUIRE(memcmp(d->data(), ref, strlen(ref)) == 0);
}

// contains symlinks
TEST_CASE(PREFIX "adium.zip")
{
Expand Down
46 changes: 46 additions & 0 deletions Source/VFS/tests/VFSArchive_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,49 @@ TEST_CASE(PREFIX "Cyrilic encoding in a file downloaded from GDrive")
auto ref = "Тест!";
REQUIRE(std::memcmp(d->data(), ref, std::strlen(ref)) == 0);
}

TEST_CASE(PREFIX "Encrypted zip archive")
{
const unsigned char arc_zip[] = {
0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x09, 0x00, 0x00, 0x00, 0x38, 0x99, 0x44, 0x45, 0xe4, 0x12, 0x35, 0x0c,
0x1f, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x05, 0x00, 0x1c, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x55,
0x54, 0x09, 0x00, 0x03, 0x6c, 0xc7, 0x2f, 0x54, 0x02, 0xc7, 0x2f, 0x54, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04,
0xf5, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x8a, 0x8c, 0x24, 0x28, 0x2f, 0x8a, 0xa5, 0x05, 0x1d,
0xe2, 0xba, 0x7c, 0xfe, 0x6c, 0x4a, 0xd2, 0x52, 0xc3, 0x24, 0xcd, 0x24, 0x5f, 0x4d, 0x2b, 0xcf, 0x03, 0xd7,
0xc9, 0x6c, 0x93, 0x54, 0x50, 0x4b, 0x07, 0x08, 0xe4, 0x12, 0x35, 0x0c, 0x1f, 0x00, 0x00, 0x00, 0x13, 0x00,
0x00, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x09, 0x00, 0x00, 0x00, 0x41, 0x99, 0x44, 0x45, 0xbd, 0xac,
0x73, 0x0e, 0x1f, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x05, 0x00, 0x1c, 0x00, 0x66, 0x69, 0x6c, 0x65,
0x32, 0x55, 0x54, 0x09, 0x00, 0x03, 0x79, 0xc7, 0x2f, 0x54, 0x02, 0xc7, 0x2f, 0x54, 0x75, 0x78, 0x0b, 0x00,
0x01, 0x04, 0xf5, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x64, 0x0d, 0x6e, 0xbc, 0x82, 0x3a, 0x58,
0xd9, 0x19, 0xe9, 0xaa, 0xf5, 0x74, 0xa7, 0x3c, 0x66, 0xfa, 0x96, 0x97, 0x39, 0xbe, 0x53, 0x70, 0xd9, 0xd3,
0x13, 0x9b, 0xe3, 0xb0, 0x88, 0xff, 0x50, 0x4b, 0x07, 0x08, 0xbd, 0xac, 0x73, 0x0e, 0x1f, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x0a, 0x00, 0x09, 0x00, 0x00, 0x00, 0x38, 0x99,
0x44, 0x45, 0xe4, 0x12, 0x35, 0x0c, 0x1f, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x05, 0x00, 0x18, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65,
0x31, 0x55, 0x54, 0x05, 0x00, 0x03, 0x6c, 0xc7, 0x2f, 0x54, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0xf5, 0x01,
0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x0a, 0x00, 0x09, 0x00, 0x00,
0x00, 0x41, 0x99, 0x44, 0x45, 0xbd, 0xac, 0x73, 0x0e, 0x1f, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x05,
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x6e, 0x00, 0x00, 0x00, 0x66,
0x69, 0x6c, 0x65, 0x32, 0x55, 0x54, 0x05, 0x00, 0x03, 0x79, 0xc7, 0x2f, 0x54, 0x75, 0x78, 0x0b, 0x00, 0x01,
0x04, 0xf5, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x02, 0x00, 0x96, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00};
TestDir dir;
const auto path = std::filesystem::path(dir.directory) / "arc_zip";
REQUIRE(nc::base::WriteAtomically(path, {reinterpret_cast<const std::byte *>(arc_zip), std::size(arc_zip)}));

const auto passwd = std::string("pass1");
std::shared_ptr<ArchiveHost> host;
REQUIRE_NOTHROW(host = std::make_shared<ArchiveHost>(path.c_str(), TestEnv().vfs_native, passwd));
REQUIRE(host->StatTotalFiles() == 2);
REQUIRE(host->StatTotalRegs() == 2);
REQUIRE(host->StatTotalDirs() == 0);

VFSFilePtr file;
auto fn = "/file2";
REQUIRE(host->CreateFile(fn, file, nullptr) == 0);
REQUIRE(file->Open(VFSFlags::OF_Read) == 0);
auto d = file->ReadFile();
REQUIRE(d->size() == 19);
auto ref = "contents of file2.\0A";
REQUIRE(memcmp(d->data(), ref, strlen(ref)) == 0);
}

0 comments on commit 32c83fa

Please sign in to comment.