From d0df62b804ec2f215db32c86f324670c5940c381 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Tue, 29 Sep 2026 13:42:33 +0800 Subject: [PATCH] Keep the Orca Cloud Agent Tests Out of the System Keychain The display-name tests call set_user_session(), which persists the session. The agent they built was in keychain mode, so every run saved a fake OrcaSlicer/Auth session into the system keychain of whoever ran the tests, replacing their real Orca Cloud login on any desktop with a working keychain. Move them next to the other agent tests and build the agent the same way: encrypted-file mode with a throwaway config directory. --- tests/slic3rutils/slic3rutils_tests_main.cpp | 89 -------------------- tests/slic3rutils/test_orca_cloud_agent.cpp | 87 +++++++++++++++++++ 2 files changed, 87 insertions(+), 89 deletions(-) diff --git a/tests/slic3rutils/slic3rutils_tests_main.cpp b/tests/slic3rutils/slic3rutils_tests_main.cpp index cea6934e8e..176e34a5df 100644 --- a/tests/slic3rutils/slic3rutils_tests_main.cpp +++ b/tests/slic3rutils/slic3rutils_tests_main.cpp @@ -1,39 +1,6 @@ #include #include "slic3r/Utils/Http.hpp" -#include "slic3r/Utils/OrcaCloudServiceAgent.hpp" - -namespace { - -nlohmann::json flat_session_json(const nlohmann::json& fields) -{ - nlohmann::json session = { - {"access_token", "test-token"}, - {"user_id", "test-user-id"} - }; - session.update(fields); - return session; -} - -nlohmann::json nested_session_json(const nlohmann::json& metadata) -{ - return { - {"access_token", "test-token"}, - {"user", { - {"id", "test-user-id"}, - {"user_metadata", metadata} - }} - }; -} - -std::string resolved_display_name(const nlohmann::json& session) -{ - Slic3r::OrcaCloudServiceAgent agent(""); - REQUIRE(agent.set_user_session(session, false)); - return agent.get_user_nickname(); -} - -} // namespace TEST_CASE("Check SSL certificates paths", "[Http][NotWorking]") { @@ -53,62 +20,6 @@ TEST_CASE("Check SSL certificates paths", "[Http][NotWorking]") { REQUIRE(status == 200); } -TEST_CASE("Orca cloud flat session resolves display name consistently", "[OrcaCloudServiceAgent]") -{ - CHECK(resolved_display_name(flat_session_json({ - {"username", "orca_username"}, - {"display_name", "Display Name"}, - {"nickname", "Nickname"} - })) == "Display Name"); - - CHECK(resolved_display_name(flat_session_json({ - {"username", "orca_username"}, - {"nickname", "Nickname"} - })) == "Nickname"); - - CHECK(resolved_display_name(flat_session_json({ - {"username", "orca_username"}, - {"full_name", "Full Name"} - })) == "Full Name"); - - CHECK(resolved_display_name(flat_session_json({ - {"username", "orca_username"}, - {"name", "Provider Name"} - })) == "Provider Name"); - - CHECK(resolved_display_name(flat_session_json({ - {"username", "orca_username"} - })) == "orca_username"); -} - -TEST_CASE("Orca cloud nested session resolves display name consistently", "[OrcaCloudServiceAgent]") -{ - CHECK(resolved_display_name(nested_session_json({ - {"username", "orca_username"}, - {"display_name", "Display Name"}, - {"nickname", "Nickname"} - })) == "Display Name"); - - CHECK(resolved_display_name(nested_session_json({ - {"username", "orca_username"}, - {"nickname", "Nickname"} - })) == "Nickname"); - - CHECK(resolved_display_name(nested_session_json({ - {"username", "orca_username"}, - {"full_name", "Full Name"} - })) == "Full Name"); - - CHECK(resolved_display_name(nested_session_json({ - {"username", "orca_username"}, - {"name", "Provider Name"} - })) == "Provider Name"); - - CHECK(resolved_display_name(nested_session_json({ - {"username", "orca_username"} - })) == "orca_username"); -} - TEST_CASE("Http digest authentication", "[Http][NotWorking]") { Slic3r::Http g = Slic3r::Http::get("https://httpbingo.org/digest-auth/auth/guest/guest"); diff --git a/tests/slic3rutils/test_orca_cloud_agent.cpp b/tests/slic3rutils/test_orca_cloud_agent.cpp index 76f4e8df16..5f325751cb 100644 --- a/tests/slic3rutils/test_orca_cloud_agent.cpp +++ b/tests/slic3rutils/test_orca_cloud_agent.cpp @@ -27,6 +27,37 @@ std::unique_ptr make_file_backed_agent(const fs::path& di fs::path secret_file(const fs::path& dir) { return dir / secret_constants::USER_SECRET_FILENAME; } +nlohmann::json flat_session_json(const nlohmann::json& fields) +{ + nlohmann::json session = { + {"access_token", "test-token"}, + {"user_id", "test-user-id"} + }; + session.update(fields); + return session; +} + +nlohmann::json nested_session_json(const nlohmann::json& metadata) +{ + return { + {"access_token", "test-token"}, + {"user", { + {"id", "test-user-id"}, + {"user_metadata", metadata} + }} + }; +} + +// set_user_session() persists the session, so it goes to a throwaway token file rather than the +// system keychain of whoever runs the tests. +std::string resolved_display_name(const nlohmann::json& session) +{ + ScopedTemporaryDir dir("orca-secret"); + auto agent = make_file_backed_agent(dir.path()); + REQUIRE(agent->set_user_session(session, false)); + return agent->get_user_nickname(); +} + } // namespace TEST_CASE("Logging out removes the secret this instance saved", "[OrcaCloudServiceAgent]") @@ -84,3 +115,59 @@ TEST_CASE("Logging out leaves a secret this instance could not read alone", "[Or agent->user_logout(false); CHECK(fs::exists(secret_file(dir.path()))); } + +TEST_CASE("Orca cloud flat session resolves display name consistently", "[OrcaCloudServiceAgent]") +{ + CHECK(resolved_display_name(flat_session_json({ + {"username", "orca_username"}, + {"display_name", "Display Name"}, + {"nickname", "Nickname"} + })) == "Display Name"); + + CHECK(resolved_display_name(flat_session_json({ + {"username", "orca_username"}, + {"nickname", "Nickname"} + })) == "Nickname"); + + CHECK(resolved_display_name(flat_session_json({ + {"username", "orca_username"}, + {"full_name", "Full Name"} + })) == "Full Name"); + + CHECK(resolved_display_name(flat_session_json({ + {"username", "orca_username"}, + {"name", "Provider Name"} + })) == "Provider Name"); + + CHECK(resolved_display_name(flat_session_json({ + {"username", "orca_username"} + })) == "orca_username"); +} + +TEST_CASE("Orca cloud nested session resolves display name consistently", "[OrcaCloudServiceAgent]") +{ + CHECK(resolved_display_name(nested_session_json({ + {"username", "orca_username"}, + {"display_name", "Display Name"}, + {"nickname", "Nickname"} + })) == "Display Name"); + + CHECK(resolved_display_name(nested_session_json({ + {"username", "orca_username"}, + {"nickname", "Nickname"} + })) == "Nickname"); + + CHECK(resolved_display_name(nested_session_json({ + {"username", "orca_username"}, + {"full_name", "Full Name"} + })) == "Full Name"); + + CHECK(resolved_display_name(nested_session_json({ + {"username", "orca_username"}, + {"name", "Provider Name"} + })) == "Provider Name"); + + CHECK(resolved_display_name(nested_session_json({ + {"username", "orca_username"} + })) == "orca_username"); +}