From 2169b72c94842db859bf802d7807cca2ab0c9dae Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Tue, 28 Jul 2026 19:28:58 +0800 Subject: [PATCH] fix: update tests --- tests/slic3rutils/test_plugin_audit.cpp | 21 +++++++++++++-------- tests/slic3rutils/test_plugin_install.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/slic3rutils/test_plugin_audit.cpp b/tests/slic3rutils/test_plugin_audit.cpp index 49eedbd1fb..20fc2b86e7 100644 --- a/tests/slic3rutils/test_plugin_audit.cpp +++ b/tests/slic3rutils/test_plugin_audit.cpp @@ -81,7 +81,7 @@ TEST_CASE("Plugin audit denies app config and token filenames anywhere", "[audit } } -TEST_CASE("Plugin audit deny beats allowed roots and the Loading read exemption", "[audit]") +TEST_CASE("Plugin audit deny beats allowed roots", "[audit]") { ScopedDataDir data_dir_guard("plugin-audit-deny"); seed_denied_names(); @@ -91,8 +91,8 @@ TEST_CASE("Plugin audit deny beats allowed roots and the Loading read exemption" // config and the token would otherwise be reachable simply by living inside it. mgr.add_global_allowed_root(data_dir()); - // Enter a plugin context. The deny must hold in Loading mode, which every scope runs in. - ScopedPluginAuditContext ctx("test_plugin", "", PluginAuditManager::AuditMode::Loading); + // Enter a plugin context. The deny must hold even inside a globally allowed root. + ScopedPluginAuditContext ctx("test_plugin", ""); const fs::path conf = fs::path(data_dir()) / (SLIC3R_APP_KEY ".conf"); const fs::path token = fs::path(data_dir()) / secret_constants::USER_SECRET_FILENAME; @@ -103,6 +103,13 @@ TEST_CASE("Plugin audit deny beats allowed roots and the Loading read exemption" CHECK(decision.allowed); } + SECTION("a file outside the allowed root is blocked for reads as well as writes") + { + AuditDecision decision = mgr.check_open((fs::path(data_dir()).parent_path() / "outside.txt").string(), "r"); + CHECK_FALSE(decision.allowed); + CHECK(decision.reason == "outside allowed root"); + } + SECTION("writing the app config is blocked despite data_dir() being allowed") { AuditDecision decision = mgr.check_open(conf.string(), "w"); @@ -110,16 +117,14 @@ TEST_CASE("Plugin audit deny beats allowed roots and the Loading read exemption" CHECK(decision.reason == "denied filename"); } - SECTION("reading the app config is blocked even though Loading exempts reads") + SECTION("reading the app config is blocked despite the allowed root") { - // Without the deny, a read in Loading mode short-circuits to allow. The deny sits above - // that exemption, so this must still be blocked. AuditDecision decision = mgr.check_open(conf.string(), "r"); CHECK_FALSE(decision.allowed); CHECK(decision.reason == "denied filename"); } - SECTION("reading the cloud refresh token is blocked in Loading mode") + SECTION("reading the cloud refresh token is blocked") { AuditDecision decision = mgr.check_open(token.string(), "r"); CHECK_FALSE(decision.allowed); @@ -150,7 +155,7 @@ TEST_CASE("Plugin audit deny beats a plugin's own scoped root", "[audit]") const fs::path plugin_dir = fs::path(data_dir()) / "plugins" / "test_plugin"; fs::create_directories(plugin_dir); - ScopedPluginAuditContext ctx("test_plugin", "", PluginAuditManager::AuditMode::Loading); + ScopedPluginAuditContext ctx("test_plugin", ""); mgr.add_scoped_allowed_root(plugin_dir); SECTION("the plugin's own non-denied file opens for read and write") diff --git a/tests/slic3rutils/test_plugin_install.cpp b/tests/slic3rutils/test_plugin_install.cpp index fceeaf1f83..c6ad670ff7 100644 --- a/tests/slic3rutils/test_plugin_install.cpp +++ b/tests/slic3rutils/test_plugin_install.cpp @@ -112,6 +112,18 @@ TEST_CASE("install-state sidecar is the source of truth for a cloud plugin's ins REQUIRE(read_install_state(plugin_dir, state)); CHECK(state.installed_version == "1.2.0"); + state.permissions.networking = {"api.example.com", "192.168.45.6"}; + state.permissions.fs_read = {"/path/to/read"}; + state.permissions.fs_write = {"/path/to/write"}; + REQUIRE(write_install_state(plugin_dir, state)); + + // Permission data is persisted in the same sidecar as the installation metadata. + PluginInstallState persisted; + REQUIRE(read_install_state(plugin_dir, persisted)); + CHECK(persisted.permissions.networking == state.permissions.networking); + CHECK(persisted.permissions.fs_read == state.permissions.fs_read); + CHECK(persisted.permissions.fs_write == state.permissions.fs_write); + // Reading the sidecar back onto a freshly-scanned descriptor (whose header version is still // 1.0.0) must surface the cloud-installed 1.2.0. This is what lets update_cloud_metadata compare // the cloud's latest version against the installed version instead of the stale header, so an @@ -120,4 +132,4 @@ TEST_CASE("install-state sidecar is the source of truth for a cloud plugin's ins scanned.version = "1.0.0"; // as parsed from the unchanged PEP723 header read_install_state(plugin_dir, scanned); CHECK(scanned.installed_version == "1.2.0"); -} \ No newline at end of file +}