1 parent
4a92d09e63
commit
45eb2cab42
12 files changed
+991
-162
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#include "echoion/host/CoreLoader.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
int fail(const char* message)
|
||||
{
|
||||
std::cerr << message << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = std::filesystem::temp_directory_path() /
|
||||
("echoion-core-reload-" + std::to_string(::getpid()));
|
||||
std::filesystem::create_directories(root);
|
||||
const auto cleanup = [&root] {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(root, ec);
|
||||
};
|
||||
|
||||
::setenv("XDG_CONFIG_HOME", root.c_str(), 1);
|
||||
::setenv("XDG_CACHE_HOME", root.c_str(), 1);
|
||||
::setenv("HOME", root.c_str(), 1);
|
||||
const auto ytDlp = root / ".local/share/echoion/yt-dlp/yt-dlp";
|
||||
std::filesystem::create_directories(ytDlp.parent_path());
|
||||
{
|
||||
std::ofstream output{ytDlp};
|
||||
output << "#!/bin/sh\necho 2026.01.01\n";
|
||||
}
|
||||
std::filesystem::permissions(ytDlp,
|
||||
std::filesystem::perms::owner_read |
|
||||
std::filesystem::perms::owner_write |
|
||||
std::filesystem::perms::owner_exec);
|
||||
const auto config = root / "config.json";
|
||||
{
|
||||
std::ofstream output{config};
|
||||
output << R"({
|
||||
"network": {"rpcEnabled": false},
|
||||
"web": {"enabled": false},
|
||||
"features": {"enableAutoUpdateCheck": false},
|
||||
"advanced": {"cacheEnabled": false}
|
||||
})";
|
||||
}
|
||||
|
||||
const auto corePath = root / "Echoion.ts";
|
||||
std::filesystem::copy_file(ECHOION_TEST_CORE_PATH, corePath);
|
||||
|
||||
Echoion::Host::CoreLoader loader;
|
||||
loader.setConfigPath(config);
|
||||
if (auto result = loader.load(corePath); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
const auto before = loader.getCore();
|
||||
if (!before) {
|
||||
cleanup();
|
||||
return fail("Core missing after initial load");
|
||||
}
|
||||
if (auto result = loader.hotReload(corePath); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
const auto after = loader.getCore();
|
||||
if (!after || after.get() == before.get()) {
|
||||
cleanup();
|
||||
return fail("Core instance was not transactionally replaced");
|
||||
}
|
||||
|
||||
const auto invalid = root / "Echoion.invalid";
|
||||
{
|
||||
std::ofstream output{invalid, std::ios::binary};
|
||||
output << "not a shared library";
|
||||
}
|
||||
std::filesystem::rename(invalid, corePath);
|
||||
if (auto result = loader.hotReload(corePath); result) {
|
||||
cleanup();
|
||||
return fail("invalid replacement unexpectedly activated");
|
||||
}
|
||||
const auto retained = loader.getCore();
|
||||
if (!retained || retained.get() != after.get() || !retained->isInitialized()) {
|
||||
cleanup();
|
||||
return fail("running Core was not retained after failed activation");
|
||||
}
|
||||
if (auto result = loader.unload(); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "echoion/standalone/EventCallbackGate.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
Echoion::Standalone::EventCallbackGate gate;
|
||||
std::mutex mutex;
|
||||
std::condition_variable enteredCv;
|
||||
std::condition_variable releaseCv;
|
||||
bool entered = false;
|
||||
bool release = false;
|
||||
std::atomic<int> calls{0};
|
||||
auto lifetime = std::make_shared<int>(42);
|
||||
std::weak_ptr<int> observedLifetime = lifetime;
|
||||
|
||||
gate.add([&, lifetime](const Echoion::Api::PluginEvent&) {
|
||||
++calls;
|
||||
std::unique_lock lock(mutex);
|
||||
entered = true;
|
||||
enteredCv.notify_all();
|
||||
releaseCv.wait(lock, [&] { return release; });
|
||||
});
|
||||
lifetime.reset();
|
||||
|
||||
Echoion::Api::PluginEvent event;
|
||||
auto dispatch = std::async(std::launch::async, [&] { gate.dispatch(event); });
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
enteredCv.wait(lock, [&] { return entered; });
|
||||
}
|
||||
|
||||
auto quiesce = std::async(std::launch::async, [&] { gate.quiesce(); });
|
||||
assert(quiesce.wait_for(std::chrono::milliseconds{30}) ==
|
||||
std::future_status::timeout);
|
||||
assert(!observedLifetime.expired());
|
||||
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
release = true;
|
||||
}
|
||||
releaseCv.notify_all();
|
||||
dispatch.get();
|
||||
quiesce.get();
|
||||
assert(observedLifetime.expired());
|
||||
|
||||
gate.dispatch(event);
|
||||
assert(calls == 1);
|
||||
|
||||
gate.add([&](const Echoion::Api::PluginEvent&) { ++calls; });
|
||||
gate.dispatch(event);
|
||||
assert(calls == 2);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "echoion/standalone/ReleaseManifest.hpp"
|
||||
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
auto directory = Void::FileSystem::TempDir::open("echoion-manifest-test");
|
||||
if (!directory) {
|
||||
std::cerr << directory.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
const auto manifestPath = directory->path() / "pending.json";
|
||||
const std::string traversal = R"({
|
||||
"version":"bad",
|
||||
"executable":"../echoiond",
|
||||
"core":"release/Echoion.ts",
|
||||
"sha256":{"executable":"x","core":"y"}
|
||||
})";
|
||||
if (auto written = Void::FileSystem::atomic_write(manifestPath, traversal);
|
||||
!written) {
|
||||
std::cerr << written.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (Echoion::Standalone::ReleaseManifest::load(manifestPath)) {
|
||||
std::cerr << "path traversal manifest was accepted\n";
|
||||
return 1;
|
||||
}
|
||||
if (auto written = Void::FileSystem::atomic_write(manifestPath, "{}");
|
||||
!written) return 1;
|
||||
if (Echoion::Standalone::ReleaseManifest::load(manifestPath)) {
|
||||
std::cerr << "incomplete manifest was accepted\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
stage_script=$1
|
||||
validator=$2
|
||||
root=$(mktemp -d)
|
||||
trap 'rm -rf -- "$root"' EXIT
|
||||
|
||||
printf '#!/bin/sh\nexit 0\n' > "$root/source-echoiond"
|
||||
chmod 0755 "$root/source-echoiond"
|
||||
printf 'test core\n' > "$root/source-core.ts"
|
||||
|
||||
"$stage_script" "$root/releases" 1.2.3 \
|
||||
"$root/source-echoiond" "$root/source-core.ts"
|
||||
|
||||
manifest="$root/releases/pending-release.json"
|
||||
test -x "$root/releases/1.2.3/echoiond"
|
||||
test -f "$root/releases/1.2.3/Echoion.ts"
|
||||
grep -q '"version": "1.2.3"' "$manifest"
|
||||
grep -q '"executable": "1.2.3/echoiond"' "$manifest"
|
||||
grep -q "$(sha256sum "$root/releases/1.2.3/echoiond" | cut -d' ' -f1)" "$manifest"
|
||||
"$validator" --validate-release "$manifest"
|
||||
|
||||
printf 'tampered\n' >> "$root/releases/1.2.3/Echoion.ts"
|
||||
if "$validator" --validate-release "$manifest" >/dev/null 2>&1; then
|
||||
echo "tampered Core artifact was accepted" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if "$stage_script" "$root/releases" '../unsafe' \
|
||||
"$root/source-echoiond" "$root/source-core.ts" >/dev/null 2>&1; then
|
||||
echo "unsafe version was accepted" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user