mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-02 13:20:59 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
459e51a666 | ||
|
|
c1fe6e74b4 | ||
|
|
92d30fbc55 | ||
|
|
3384daa6bc | ||
|
|
6842d9c778 | ||
|
|
1a5bc8982d | ||
|
|
2a9cb32c1f |
@@ -1301,6 +1301,54 @@ if (WIN32)
|
||||
endif()
|
||||
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
|
||||
include(InstallRequiredSystemLibraries)
|
||||
|
||||
# CMake 3.31 does not recognize the v145 toolset shipped with VS 2026.
|
||||
# The Windows ARM64 build is pinned to CMake 3.31 for its assembler
|
||||
# support, so the runtime collector can leave this list without the CRT.
|
||||
# Pick up the target-architecture redistributable directly in that case.
|
||||
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
|
||||
set(_orca_has_msvcp140 FALSE)
|
||||
set(_orca_has_vcruntime140 FALSE)
|
||||
foreach (_runtime IN LISTS CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
|
||||
get_filename_component(_runtime_name "${_runtime}" NAME)
|
||||
if (_runtime_name STREQUAL "msvcp140.dll")
|
||||
set(_orca_has_msvcp140 TRUE)
|
||||
elseif (_runtime_name STREQUAL "vcruntime140.dll")
|
||||
set(_orca_has_vcruntime140 TRUE)
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
if (NOT _orca_has_msvcp140 OR NOT _orca_has_vcruntime140)
|
||||
file(GLOB _orca_arm64_crt_dirs
|
||||
"$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/Redist/MSVC/*/arm64/Microsoft.VC*.CRT")
|
||||
if (NOT _orca_arm64_crt_dirs)
|
||||
message(FATAL_ERROR
|
||||
"CMake did not collect the ARM64 MSVC runtime, and no ARM64 CRT redistributable directory was found.")
|
||||
endif ()
|
||||
# Multiple Visual Studio servicing versions can coexist; take the
|
||||
# newest matching redistributable directory.
|
||||
list(SORT _orca_arm64_crt_dirs ORDER DESCENDING)
|
||||
list(GET _orca_arm64_crt_dirs 0 _orca_arm64_crt_dir)
|
||||
file(GLOB _orca_arm64_crt_dlls "${_orca_arm64_crt_dir}/*.dll")
|
||||
list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${_orca_arm64_crt_dlls})
|
||||
endif ()
|
||||
|
||||
# Catch a bad VS layout or an incomplete redistributable before CPack
|
||||
# can silently emit an installer that fails on a clean ARM64 machine.
|
||||
set(_orca_has_msvcp140 FALSE)
|
||||
set(_orca_has_vcruntime140 FALSE)
|
||||
foreach (_runtime IN LISTS CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
|
||||
get_filename_component(_runtime_name "${_runtime}" NAME)
|
||||
if (_runtime_name STREQUAL "msvcp140.dll")
|
||||
set(_orca_has_msvcp140 TRUE)
|
||||
elseif (_runtime_name STREQUAL "vcruntime140.dll")
|
||||
set(_orca_has_vcruntime140 TRUE)
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (NOT _orca_has_msvcp140 OR NOT _orca_has_vcruntime140)
|
||||
message(FATAL_ERROR "The ARM64 installer must contain msvcp140.dll and vcruntime140.dll.")
|
||||
endif ()
|
||||
endif ()
|
||||
install (PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ".")
|
||||
elseif (SLIC3R_FHS)
|
||||
# CMAKE_INSTALL_FULL_DATAROOTDIR: read-only architecture-independent data root (share)
|
||||
|
||||
Vendored
+11
-1
@@ -151,6 +151,12 @@ elseif(APPLE)
|
||||
# the post-install -add_rpath below.
|
||||
set(_python_ldflags "${_python_arch_flags} -Wl,-headerpad_max_install_names")
|
||||
|
||||
# The macOS 27 SDK declares pipe2() and dup3() as available from macOS 27, so
|
||||
# configure finds them and CPython 3.12 calls them without a runtime check.
|
||||
# Below a macOS 27 deployment target they are weak-linked and resolve to NULL
|
||||
# on older systems, where os.pipe() then segfaults -- in `make install`
|
||||
# (compileall, ensurepip) and in the shipped app alike. Every configure below
|
||||
# keeps the pipe()/dup2() fallbacks (python/cpython#153711).
|
||||
if(IS_CROSS_COMPILE)
|
||||
set(_python_build_tgt --build=${_python_build_arch}-apple-darwin --host=${_python_host_arch}-apple-darwin)
|
||||
set(_python_build_arch_flags "-arch ${_python_build_arch_flag} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
||||
@@ -174,7 +180,8 @@ elseif(APPLE)
|
||||
--enable-shared \
|
||||
--without-static-libpython \
|
||||
--disable-test-modules \
|
||||
--build=${_python_build_arch}-apple-darwin && \
|
||||
--build=${_python_build_arch}-apple-darwin \
|
||||
ac_cv_func_pipe2=no ac_cv_func_dup3=no && \
|
||||
make -j${NPROC} python && \
|
||||
cd '<SOURCE_DIR>' && \
|
||||
env \
|
||||
@@ -191,6 +198,7 @@ elseif(APPLE)
|
||||
--without-static-libpython \
|
||||
--with-openssl='${DESTDIR}' \
|
||||
--disable-test-modules \
|
||||
ac_cv_func_pipe2=no ac_cv_func_dup3=no \
|
||||
${_python_build_tgt} \
|
||||
--with-build-python='${_python_build_python}' \
|
||||
py_cv_module__tkinter=n/a"
|
||||
@@ -213,6 +221,8 @@ elseif(APPLE)
|
||||
--with-openssl=${DESTDIR}
|
||||
--disable-test-modules
|
||||
${_python_build_tgt}
|
||||
ac_cv_func_pipe2=no
|
||||
ac_cv_func_dup3=no
|
||||
# Tcl/Tk 9.0 (e.g. from Homebrew) is incompatible with CPython 3.12's
|
||||
# _tkinter; OrcaSlicer's embedded Python does not need tkinter anyway.
|
||||
py_cv_module__tkinter=n/a
|
||||
|
||||
@@ -1692,9 +1692,9 @@ void Layer::make_ironing()
|
||||
ironing_params.just_infill = false;
|
||||
// ORCA: Get filament-specific overrides if configured, otherwise use process values
|
||||
size_t extruder_idx = ironing_params.extruder - 1;
|
||||
ironing_params.line_spacing = (!config.filament_ironing_spacing.is_nil(extruder_idx)
|
||||
ironing_params.line_spacing = std::max(IRONING_SPACING_MIN, !config.filament_ironing_spacing.is_nil(extruder_idx)
|
||||
? config.filament_ironing_spacing.get_at(extruder_idx)
|
||||
: config.ironing_spacing);
|
||||
: config.ironing_spacing.value);
|
||||
ironing_params.inset = (!config.filament_ironing_inset.is_nil(extruder_idx)
|
||||
? config.filament_ironing_inset.get_at(extruder_idx)
|
||||
: config.ironing_inset);
|
||||
|
||||
@@ -22,6 +22,9 @@ void FillConcentric::_fill_surface_single(
|
||||
|
||||
coord_t min_spacing = scale_(this->spacing) * params.multiline;
|
||||
coord_t distance = coord_t(min_spacing / params.density);
|
||||
// A non-positive step never shrinks the region, so the inset loop below would not end.
|
||||
if (min_spacing <= 0 || distance <= 0)
|
||||
return;
|
||||
|
||||
if (params.density > 0.9999f && !params.dont_adjust) {
|
||||
distance = this->_adjust_solid_spacing(bounding_box.size()(0), distance);
|
||||
@@ -108,6 +111,8 @@ void FillConcentric::_fill_surface_single(const FillParams& params,
|
||||
// no rotation is supported for this infill pattern
|
||||
Point bbox_size = expolygon.contour.bounding_box().size();
|
||||
coord_t min_spacing = scaled<coord_t>(this->spacing);
|
||||
if (min_spacing <= 0)
|
||||
return;
|
||||
|
||||
if (params.density > 0.9999f && !params.dont_adjust) {
|
||||
coord_t loops_count = std::max(bbox_size.x(), bbox_size.y()) / min_spacing + 1;
|
||||
|
||||
@@ -180,6 +180,10 @@ enum class IroningType {
|
||||
Count,
|
||||
};
|
||||
|
||||
// Smallest usable ironing line spacing. Anything tighter yields an unprintable number of lines,
|
||||
// and zero stops the fillers from making progress.
|
||||
constexpr double IRONING_SPACING_MIN = 0.05;
|
||||
|
||||
//BBS
|
||||
enum class WallInfillOrder {
|
||||
InnerOuterInfill,
|
||||
|
||||
@@ -64,7 +64,7 @@ struct SupportParameters {
|
||||
|
||||
this->ironing = object_config.support_ironing;
|
||||
this->ironing_flow = support_material_interface_flow.with_height(support_material_interface_flow.height() * 0.01 * object_config.support_ironing_flow.value);
|
||||
this->ironing_spacing = object_config.support_ironing_spacing;
|
||||
this->ironing_spacing = std::max(IRONING_SPACING_MIN, object_config.support_ironing_spacing.value);
|
||||
this->ironing_pattern = object_config.support_ironing_pattern;
|
||||
|
||||
// Calculate a minimum support layer height as a minimum over all extruders, but not smaller than 10um.
|
||||
|
||||
@@ -212,6 +212,30 @@ void ConfigManipulation::check_filament_max_volumetric_speed(DynamicPrintConfig
|
||||
|
||||
}
|
||||
|
||||
void ConfigManipulation::check_filament_ironing_spacing(DynamicPrintConfig *config)
|
||||
{
|
||||
const auto *opt = config->option<ConfigOptionFloatsNullable>("filament_ironing_spacing");
|
||||
if (opt == nullptr)
|
||||
return;
|
||||
std::vector<double> values = opt->values;
|
||||
bool reset = false;
|
||||
for (size_t i = 0; i < values.size(); ++i)
|
||||
if (!opt->is_nil(i) && values[i] < IRONING_SPACING_MIN) {
|
||||
values[i] = 0.1;
|
||||
reset = true;
|
||||
}
|
||||
if (!reset)
|
||||
return;
|
||||
const wxString msg_text = _(L("Ironing spacing too small\nIt has been reset to 0.1"));
|
||||
MessageDialog dialog(nullptr, msg_text, "", wxICON_WARNING | wxOK);
|
||||
DynamicPrintConfig new_conf = *config;
|
||||
is_msg_dlg_already_exist = true;
|
||||
dialog.ShowModal();
|
||||
new_conf.set_key_value("filament_ironing_spacing", new ConfigOptionFloatsNullable(values));
|
||||
apply(config, &new_conf);
|
||||
is_msg_dlg_already_exist = false;
|
||||
}
|
||||
|
||||
void ConfigManipulation::check_chamber_temperature(DynamicPrintConfig* config)
|
||||
{
|
||||
bool support_chamber_temp_control=GUI::wxGetApp().preset_bundle->printers.get_selected_preset().config.opt_bool("support_chamber_temp_control");
|
||||
@@ -334,7 +358,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
|
||||
}
|
||||
|
||||
//BBS: ironing_spacing shouldn't be too small or equal to zero
|
||||
if (config->opt_float("ironing_spacing") < 0.05)
|
||||
if (config->opt_float("ironing_spacing") < IRONING_SPACING_MIN)
|
||||
{
|
||||
const wxString msg_text = _(L("Ironing spacing too small\nIt has been reset to 0.1"));
|
||||
MessageDialog dialog(nullptr, msg_text, "", wxICON_WARNING | wxOK);
|
||||
@@ -345,7 +369,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
|
||||
apply(config, &new_conf);
|
||||
is_msg_dlg_already_exist = false;
|
||||
}
|
||||
if (config->opt_float("support_ironing_spacing") < 0.05)
|
||||
if (config->opt_float("support_ironing_spacing") < IRONING_SPACING_MIN)
|
||||
{
|
||||
const wxString msg_text = _(L("Ironing spacing too small\nIt has been reset to 0.1"));
|
||||
MessageDialog dialog(nullptr, msg_text, "", wxICON_WARNING | wxOK);
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
void check_nozzle_temperature_initial_layer_range(DynamicPrintConfig* config, unsigned int variant_index);
|
||||
void check_adaptive_pressure_advance_model(DynamicPrintConfig* config);
|
||||
void check_filament_max_volumetric_speed(DynamicPrintConfig *config);
|
||||
void check_filament_ironing_spacing(DynamicPrintConfig *config);
|
||||
void check_chamber_temperature(DynamicPrintConfig* config);
|
||||
void check_chamber_minimal_temperature(DynamicPrintConfig* config);
|
||||
bool check_layer_height(DynamicPrintConfig* config);
|
||||
|
||||
@@ -4911,6 +4911,7 @@ void TabFilament::update()
|
||||
return; // ys_FIXME
|
||||
|
||||
m_config_manipulation.check_filament_max_volumetric_speed(m_config);
|
||||
m_config_manipulation.check_filament_ironing_spacing(m_config);
|
||||
|
||||
m_update_cnt++;
|
||||
|
||||
|
||||
@@ -819,7 +819,9 @@ int OrcaCloudServiceAgent::user_logout(bool request)
|
||||
}
|
||||
}
|
||||
|
||||
clear_session();
|
||||
// An explicit logout also wipes the backend the token storage option is not using, so a token
|
||||
// stranded by switching that option cannot sign the account back in later.
|
||||
clear_session(/*all_backends=*/request);
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1604,7 +1606,9 @@ void OrcaCloudServiceAgent::persist_user_secret(const std::string& secret)
|
||||
}
|
||||
}
|
||||
|
||||
(void) stored;
|
||||
if (stored) {
|
||||
secret_stored = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool OrcaCloudServiceAgent::load_user_secret(std::string& out_secret)
|
||||
@@ -1644,6 +1648,7 @@ bool OrcaCloudServiceAgent::load_user_secret(std::string& out_secret)
|
||||
}
|
||||
|
||||
if (integrity_ok && aes256gcm_decrypt(encoded_payload, key, plain) && !plain.empty()) {
|
||||
secret_stored = true;
|
||||
out_secret = plain;
|
||||
// Upgrade legacy payloads to signed format
|
||||
if (payload.rfind("v2:", 0) != 0) {
|
||||
@@ -1661,6 +1666,7 @@ bool OrcaCloudServiceAgent::load_user_secret(std::string& out_secret)
|
||||
if (store.Load(SECRET_STORE_SERVICE, username, secret) && secret.IsOk()) {
|
||||
out_secret.assign(static_cast<const char*>(secret.GetData()), secret.GetSize());
|
||||
if (!out_secret.empty()) {
|
||||
secret_stored = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1670,11 +1676,20 @@ bool OrcaCloudServiceAgent::load_user_secret(std::string& out_secret)
|
||||
return false;
|
||||
}
|
||||
|
||||
void OrcaCloudServiceAgent::clear_user_secret()
|
||||
void OrcaCloudServiceAgent::clear_user_secret(bool all_backends)
|
||||
{
|
||||
wxSecretStore store = wxSecretStore::GetDefault();
|
||||
if (store.IsOk()) {
|
||||
store.Delete(SECRET_STORE_SERVICE);
|
||||
// Nothing this process loaded or saved: leave the store alone. Deleting would only cost a
|
||||
// keychain round trip (or a hang while the keychain is unresponsive) and could remove a
|
||||
// login another instance just saved.
|
||||
if (!secret_stored.exchange(false) && !all_backends) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (all_backends || !m_use_encrypted_token_file) {
|
||||
wxSecretStore store = wxSecretStore::GetDefault();
|
||||
if (store.IsOk()) {
|
||||
store.Delete(SECRET_STORE_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
compute_fallback_path();
|
||||
@@ -2023,13 +2038,13 @@ bool OrcaCloudServiceAgent::set_user_session(const json& session_json, bool noti
|
||||
return success;
|
||||
}
|
||||
|
||||
void OrcaCloudServiceAgent::clear_session()
|
||||
void OrcaCloudServiceAgent::clear_session(bool all_backends)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(session_mutex);
|
||||
session = SessionInfo{};
|
||||
}
|
||||
clear_user_secret();
|
||||
clear_user_secret(all_backends);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -326,7 +326,7 @@ public:
|
||||
|
||||
void persist_user_secret(const std::string& secret);
|
||||
bool load_user_secret(std::string& out_secret);
|
||||
void clear_user_secret();
|
||||
void clear_user_secret(bool all_backends = false);
|
||||
|
||||
// Token refresh helpers
|
||||
bool refresh_if_expiring(std::chrono::seconds skew, const std::string& reason);
|
||||
@@ -344,7 +344,7 @@ public:
|
||||
bool persist = true);
|
||||
// Accepts either nested Orca cloud / GoTrue session JSON or flat WebView token JSON.
|
||||
bool set_user_session(const nlohmann::json& session_json, bool notify_login = true);
|
||||
void clear_session();
|
||||
void clear_session(bool all_backends = false);
|
||||
|
||||
static std::string generate_uuid_for_setting_id(const std::string& name, const std::string& user_id = "");
|
||||
|
||||
@@ -413,6 +413,11 @@ private:
|
||||
// Member variables - auth state
|
||||
PkceBundle pkce_bundle;
|
||||
std::string secret_fallback_path;
|
||||
// Set once this process has read a secret from the store or written one. Unless the user logs
|
||||
// out explicitly, clear_user_secret() only touches the store while it is set, so a logged-out
|
||||
// instance (the GUI polls the login status every 2 s) makes no keychain calls and cannot wipe
|
||||
// a login another instance saved.
|
||||
std::atomic_bool secret_stored{false};
|
||||
SessionHandler session_handler;
|
||||
OnLoginCompleteHandler on_login_complete_handler;
|
||||
SessionInfo session;
|
||||
|
||||
@@ -748,6 +748,61 @@ TEST_CASE("A region with ironing turned off is never ironed", "[Fill]")
|
||||
REQUIRE(Layer::choose_ironing_extruder(cfg, spiral_mode, /*is_topmost_layer=*/true) == -1);
|
||||
}
|
||||
|
||||
// Ironing path count and total length in mm, over the whole object.
|
||||
static std::pair<size_t, double> ironing_extent(const Print &print)
|
||||
{
|
||||
size_t paths = 0;
|
||||
double length = 0.;
|
||||
for (const Layer *layer : print.objects().front()->layers())
|
||||
for (const LayerRegion *region : layer->regions())
|
||||
for (const ExtrusionEntity *entity : region->fills.flatten().entities)
|
||||
if (ironing_role(entity->role())) {
|
||||
++paths;
|
||||
length += unscale<double>(entity->length());
|
||||
}
|
||||
return {paths, length};
|
||||
}
|
||||
|
||||
TEST_CASE("Ironing spacing below the minimum irons at the minimum spacing", "[Fill]")
|
||||
{
|
||||
const std::string pattern = GENERATE("rectilinear", "concentric");
|
||||
const bool via_filament = GENERATE(false, true);
|
||||
const double spacing = GENERATE(0., 0.001);
|
||||
CAPTURE(pattern, via_filament, spacing);
|
||||
|
||||
auto ironing_for = [&pattern, via_filament](double spacing) {
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({{"ironing_type", "top"},
|
||||
{"ironing_pattern", pattern},
|
||||
{"layer_height", 0.2}});
|
||||
// The filament override replaces the process spacing, which stays at a usable value.
|
||||
if (via_filament)
|
||||
config.set_deserialize_strict({{"ironing_spacing", 0.1}, {"filament_ironing_spacing", spacing}});
|
||||
else
|
||||
config.set_deserialize_strict({{"ironing_spacing", spacing}});
|
||||
Print print;
|
||||
Slic3r::Test::init_and_process_print({Slic3r::Test::cube(20)}, print, config);
|
||||
return ironing_extent(print);
|
||||
};
|
||||
|
||||
const std::pair<size_t, double> clamped = ironing_for(spacing);
|
||||
const std::pair<size_t, double> minimum = ironing_for(IRONING_SPACING_MIN);
|
||||
REQUIRE(minimum.first > 0);
|
||||
CHECK(clamped.first == minimum.first);
|
||||
CHECK_THAT(clamped.second, Catch::Matchers::WithinRel(minimum.second, 1e-9));
|
||||
}
|
||||
|
||||
TEST_CASE("Concentric fill at zero spacing returns without paths", "[Fill]")
|
||||
{
|
||||
std::unique_ptr<Fill> filler(Fill::new_from_type(ipConcentric));
|
||||
filler->spacing = 0.;
|
||||
filler->bounding_box = BoundingBox(Point(0, 0), Point::new_scale(10, 10));
|
||||
FillParams params;
|
||||
params.density = 1.f;
|
||||
Surface surface(stTop, ExPolygon({Point(0, 0), Point::new_scale(10, 0), Point::new_scale(10, 10), Point::new_scale(0, 10)}));
|
||||
CHECK(filler->fill_surface(&surface, params).empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Solid infill direction offsets every layer when no template is set", "[Fill]")
|
||||
{
|
||||
auto angles_for = [](int direction) {
|
||||
|
||||
@@ -13,6 +13,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_prebuild_queue.cpp
|
||||
test_staged_build.cpp
|
||||
test_network_versions.cpp
|
||||
test_orca_cloud_agent.cpp
|
||||
test_action_source.cpp
|
||||
test_plugin_host_api.cpp
|
||||
# Exercise seam enums and predicates through the embedded Python host API.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <memory.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <pybind11/embed.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
@@ -25,8 +26,15 @@ void ensure_python_initialized()
|
||||
config.parse_argv = 0;
|
||||
|
||||
const auto python_home = boost::dll::program_location().parent_path() / "python";
|
||||
#ifdef _WIN32
|
||||
const auto stdlib = python_home / "Lib";
|
||||
#else
|
||||
const auto stdlib = python_home / "lib" /
|
||||
("python" + std::to_string(PY_MAJOR_VERSION) + "." + std::to_string(PY_MINOR_VERSION));
|
||||
#endif
|
||||
|
||||
if (boost::filesystem::exists(python_home)) {
|
||||
// Only a real runtime: a stray python/ folder (packages a test left behind) is not a home.
|
||||
if (boost::filesystem::exists(stdlib / "encodings")) {
|
||||
const std::string home = python_home.string();
|
||||
const PyStatus status = PyConfig_SetBytesString(&config, &config.home, home.c_str());
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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; }
|
||||
|
||||
} // 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())));
|
||||
}
|
||||
@@ -38,6 +38,9 @@ namespace {
|
||||
// before this destructor's shutdown() runs.
|
||||
struct ScopedPluginManager
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log,
|
||||
// which would otherwise land in the working directory.
|
||||
ScopedDataDir python_data_dir{"plugin-python"};
|
||||
bool initialized = PluginManager::instance().initialize();
|
||||
|
||||
~ScopedPluginManager()
|
||||
|
||||
@@ -31,6 +31,9 @@ namespace {
|
||||
// same as any other plugin.
|
||||
struct ScopedManagerShutdown
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log,
|
||||
// which would otherwise land in the working directory.
|
||||
ScopedDataDir python_data_dir{"plugin-python"};
|
||||
bool initialized = PluginManager::instance().initialize();
|
||||
|
||||
~ScopedManagerShutdown()
|
||||
|
||||
@@ -42,6 +42,9 @@ namespace {
|
||||
// Declare this FIRST in a test so it is destroyed last.
|
||||
struct ScopedPluginManager
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log,
|
||||
// which would otherwise land in the working directory.
|
||||
ScopedDataDir python_data_dir{"plugin-python"};
|
||||
bool initialized = false;
|
||||
|
||||
ScopedPluginManager() { initialized = PluginManager::instance().initialize(); }
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "plugin_test_utils.hpp"
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace Slic3r;
|
||||
|
||||
@@ -21,6 +23,9 @@ namespace {
|
||||
// into Python unless PythonInterpreter::instance() reports initialized.
|
||||
struct ScopedPluginManager
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log,
|
||||
// which would otherwise land in the working directory.
|
||||
ScopedDataDir python_data_dir{"plugin-python"};
|
||||
bool initialized = PluginManager::instance().initialize();
|
||||
|
||||
~ScopedPluginManager()
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace {
|
||||
|
||||
struct ScopedPluginManager
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log,
|
||||
// which would otherwise land in the working directory.
|
||||
ScopedDataDir python_data_dir{"plugin-python"};
|
||||
bool initialized = false;
|
||||
|
||||
ScopedPluginManager() { initialized = PluginManager::instance().initialize(); }
|
||||
|
||||
Reference in New Issue
Block a user