diff --git a/test/compat_test.cpp b/test/compat_test.cpp index 4ef95027..95811484 100644 --- a/test/compat_test.cpp +++ b/test/compat_test.cpp @@ -24,7 +24,9 @@ // TODO: this test should be autogenerated somehow... #include +#include #include +#include #include #include #include @@ -52,9 +54,12 @@ #include "test_logger.h" using namespace dwarfs; +namespace fs = std::filesystem; namespace { +auto test_dir = fs::path(TEST_DATA_DIR).make_preferred(); + char const* reference_v0_2 = R"( { "root": { @@ -1241,3 +1246,38 @@ INSTANTIATE_TEST_SUITE_P(dwarfs_compat, rewrite, ::testing::Combine(::testing::ValuesIn(versions), ::testing::Bool(), ::testing::Bool())); + +class set_uidgid_test : public testing::TestWithParam {}; + +TEST_P(set_uidgid_test, read_legacy_image) { + auto image = test_dir / GetParam(); + + test::test_logger lgr; + filesystem_v2 fs(lgr, std::make_shared(image)); + + ASSERT_EQ(0, fs.check(filesystem_check_level::FULL)); + + for (auto path : {"/dwarfs", "/dwarfs/version.h"}) { + auto v = fs.find(path); + ASSERT_TRUE(v) << path; + EXPECT_EQ(33333, v->getuid()) << path; + EXPECT_EQ(44444, v->getgid()) << path; + + file_stat st; + EXPECT_EQ(0, fs.getattr(*v, &st)) << path; + EXPECT_EQ(33333, st.uid) << path; + EXPECT_EQ(44444, st.gid) << path; + } +} + +namespace { + +std::array legacy_images{ + "setuidgid-v0.4.1.dwarfs", + "setuidgid-v0.5.6.dwarfs", +}; + +} // namespace + +INSTANTIATE_TEST_SUITE_P(dwarfs_compat, set_uidgid_test, + ::testing::ValuesIn(legacy_images)); diff --git a/test/setuidgid-v0.4.1.dwarfs b/test/setuidgid-v0.4.1.dwarfs new file mode 100644 index 00000000..654d85c9 Binary files /dev/null and b/test/setuidgid-v0.4.1.dwarfs differ diff --git a/test/setuidgid-v0.5.6.dwarfs b/test/setuidgid-v0.5.6.dwarfs new file mode 100644 index 00000000..df5078ec Binary files /dev/null and b/test/setuidgid-v0.5.6.dwarfs differ