#include #include #include int main() { // TODO(Faraphel): use a real unit test framework ? // create a basic virtual file system vfs::VirtualFileSystem fs; // mount a directory into our system fs.mount("_assets", "/assets"); // TEST: check if a file outside of an allowed mounted directory can't be resolved try { const std::filesystem::path path = fs.resolve("/content.txt"); throw std::runtime_error("[Test 1] - Impossible path should not be resolved !"); } catch (const std::runtime_error& exception) {} // TEST: check if a file in a mounted directory can be resolved try { const std::filesystem::path path = fs.resolve("/assets/content.txt"); // auto file = QFile(path); // file.open(QIODeviceBase::Text | QIODevice::ReadOnly); // std::cout << file.readAll().toStdString() << std::endl; } catch (const std::runtime_error& exception) { throw std::runtime_error("[Test 2] - Path could not be accessed !"); } // TEST: cannot bypass security with the ".." parent directory syntax try { // const std::filesystem::path path = fs.resolve("/assets/../content.txt"); // throw std::runtime_error("[Test 3] - Resolved impossible path"); } catch (const std::runtime_error& exception) { } }