mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 22:31:02 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
177 lines
5.6 KiB
C++
177 lines
5.6 KiB
C++
#include <boost/filesystem/path.hpp>
|
|
#include <boost/filesystem/operations.hpp>
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/filesystem/fstream.hpp>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include "slic3r/Utils/OrcaCloudServiceAgent.hpp"
|
|
#include "test_utils.hpp"
|
|
|
|
using namespace Slic3r;
|
|
namespace fs = boost::filesystem;
|
|
|
|
namespace {
|
|
|
|
// The encrypted token file is the one secret backend a test can observe without a system
|
|
// keychain. Every agent pointed at the same directory shares it, like separate app instances
|
|
// share the keychain entry.
|
|
std::unique_ptr<OrcaCloudServiceAgent> make_file_backed_agent(const fs::path& dir)
|
|
{
|
|
auto agent = std::make_unique<OrcaCloudServiceAgent>(dir.string());
|
|
agent->set_use_encrypted_token_file(true);
|
|
agent->set_config_dir(dir.string());
|
|
return agent;
|
|
}
|
|
|
|
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]")
|
|
{
|
|
ScopedTemporaryDir dir("orca-secret");
|
|
auto agent = make_file_backed_agent(dir.path());
|
|
|
|
agent->persist_user_secret("refresh-token");
|
|
REQUIRE(fs::exists(secret_file(dir.path())));
|
|
|
|
agent->user_logout(false);
|
|
CHECK_FALSE(fs::exists(secret_file(dir.path())));
|
|
}
|
|
|
|
TEST_CASE("Logging out removes a secret this instance loaded from the store", "[OrcaCloudServiceAgent]")
|
|
{
|
|
ScopedTemporaryDir dir("orca-secret");
|
|
make_file_backed_agent(dir.path())->persist_user_secret("refresh-token");
|
|
|
|
auto agent = make_file_backed_agent(dir.path());
|
|
std::string secret;
|
|
REQUIRE(agent->load_user_secret(secret));
|
|
CHECK(secret == "refresh-token");
|
|
|
|
agent->user_logout(false);
|
|
CHECK_FALSE(fs::exists(secret_file(dir.path())));
|
|
}
|
|
|
|
TEST_CASE("Logging out leaves a secret this instance never loaded or saved alone", "[OrcaCloudServiceAgent]")
|
|
{
|
|
ScopedTemporaryDir dir("orca-secret");
|
|
make_file_backed_agent(dir.path())->persist_user_secret("refresh-token");
|
|
|
|
// A logged-out instance is asked to log out on every login-status poll.
|
|
auto other = make_file_backed_agent(dir.path());
|
|
other->user_logout(false);
|
|
other->user_logout(false);
|
|
CHECK(fs::exists(secret_file(dir.path())));
|
|
|
|
std::string secret;
|
|
REQUIRE(make_file_backed_agent(dir.path())->load_user_secret(secret));
|
|
CHECK(secret == "refresh-token");
|
|
}
|
|
|
|
TEST_CASE("Logging out leaves a secret this instance could not read alone", "[OrcaCloudServiceAgent]")
|
|
{
|
|
ScopedTemporaryDir dir("orca-secret");
|
|
// Written under another encryption key, e.g. by another OS user sharing the data directory.
|
|
fs::ofstream(secret_file(dir.path())) << "v2:0000:not-a-payload-this-user-can-decrypt";
|
|
|
|
auto agent = make_file_backed_agent(dir.path());
|
|
std::string secret;
|
|
REQUIRE_FALSE(agent->load_user_secret(secret));
|
|
|
|
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");
|
|
}
|