feat(provenance,daemon): add Ed25519 signing primitives and bounded daemon describe op
This commit is contained in:
1 parent
0bde74f739
commit
21babb8c31
16 files changed
+1232
-20
No files matched your search
@@ -12,7 +12,7 @@ set_target_properties(vbs_core_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_core_tests COMMAND "$<TARGET_FILE:vbs_core_tests>" --no-color)
|
||||
|
||||
add_executable(vbs_v1_tests FullV1Tests.cpp DaemonTests.cpp)
|
||||
add_executable(vbs_v1_tests FullV1Tests.cpp DaemonTests.cpp SigningTests.cpp)
|
||||
target_include_directories(vbs_v1_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
|
||||
target_link_libraries(vbs_v1_tests PRIVATE Void::BuildCore Void::Testing)
|
||||
set_target_properties(vbs_v1_tests PROPERTIES
|
||||
|
||||
@@ -45,9 +45,91 @@ check_process(2 "" "--prefix is required" uninstall)
|
||||
check_process(2 "" "--input and --output-dir are required" gen-tests)
|
||||
check_process(0 "Usage: vbs publish " "" publish --help)
|
||||
check_process(2 "" "--registry, --name, and --version are required" publish)
|
||||
check_process(0 "Usage: vbs daemon <command>.*Commands:.*run.*status.*stop.*recover.*gc" "" daemon --help)
|
||||
check_process(0 "Usage: vbs daemon <command>.*Commands:.*run.*status.*stop.*recover.*gc.*describe" "" daemon --help)
|
||||
check_process(0 "Usage: vbs daemon run " "" daemon run --help)
|
||||
check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --help)
|
||||
check_process(2 "" "missing subcommand for 'vbs daemon'" daemon)
|
||||
|
||||
# Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over
|
||||
# the Unix socket, then stop it. The daemon is Unix-only, matching the rest of this suite.
|
||||
set(daemon_contract_root "${CMAKE_CURRENT_BINARY_DIR}/daemon_contract")
|
||||
file(REMOVE_RECURSE "${daemon_contract_root}")
|
||||
file(MAKE_DIRECTORY "${daemon_contract_root}/project")
|
||||
file(WRITE "${daemon_contract_root}/project/build.cpp" [=[#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
auto app = project.executable("app");
|
||||
app.sources({"main.cpp"});
|
||||
}
|
||||
]=])
|
||||
file(WRITE "${daemon_contract_root}/project/main.cpp" "int main() { return 0; }\n")
|
||||
|
||||
set(daemon_contract_script [=[
|
||||
set -u
|
||||
vbs="$1"
|
||||
project="$2"
|
||||
build="$3"
|
||||
out="$4"
|
||||
log="$5"
|
||||
|
||||
"$vbs" daemon run -C "$project" -B "$build" --max-requests 2 >"$log" 2>&1 &
|
||||
pid=$!
|
||||
cleanup() {
|
||||
kill "$pid" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
socket="$build/.vbs/vbs-daemon.sock"
|
||||
i=0
|
||||
while [ ! -S "$socket" ]; do
|
||||
i=$((i + 1))
|
||||
if [ "$i" -gt 400 ]; then
|
||||
echo "daemon socket did not appear" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 0.05
|
||||
done
|
||||
|
||||
"$vbs" daemon describe -C "$project" -B "$build" >"$out"
|
||||
status=$?
|
||||
|
||||
"$vbs" daemon stop -C "$project" -B "$build" >/dev/null 2>&1 || true
|
||||
i=0
|
||||
while kill -0 "$pid" 2>/dev/null; do
|
||||
i=$((i + 1))
|
||||
if [ "$i" -gt 100 ]; then
|
||||
break
|
||||
fi
|
||||
sleep 0.05
|
||||
done
|
||||
kill "$pid" 2>/dev/null || true
|
||||
wait "$pid" 2>/dev/null || true
|
||||
trap - EXIT
|
||||
exit "$status"
|
||||
]=])
|
||||
|
||||
execute_process(
|
||||
COMMAND sh -c "${daemon_contract_script}" sh "${VBS}"
|
||||
"${daemon_contract_root}/project" "${daemon_contract_root}/build"
|
||||
"${daemon_contract_root}/describe.json" "${daemon_contract_root}/daemon.log"
|
||||
RESULT_VARIABLE daemon_contract_code
|
||||
TIMEOUT 180)
|
||||
|
||||
set(daemon_contract_log "")
|
||||
if(EXISTS "${daemon_contract_root}/daemon.log")
|
||||
file(READ "${daemon_contract_root}/daemon.log" daemon_contract_log)
|
||||
endif()
|
||||
if(NOT "${daemon_contract_code}" STREQUAL "0")
|
||||
message(FATAL_ERROR "vbs daemon describe failed: exit ${daemon_contract_code}\ndaemon log=[${daemon_contract_log}]")
|
||||
endif()
|
||||
|
||||
file(READ "${daemon_contract_root}/describe.json" daemon_describe_out)
|
||||
if(NOT daemon_describe_out MATCHES "\"ok\":true" OR
|
||||
NOT daemon_describe_out MATCHES "\"op\":\"describe\"" OR
|
||||
NOT daemon_describe_out MATCHES "\"target_names\":\\[[^]]*\"app\"")
|
||||
message(FATAL_ERROR "vbs daemon describe: unexpected response [${daemon_describe_out}]")
|
||||
endif()
|
||||
message(STATUS "daemon describe response: ${daemon_describe_out}")
|
||||
check_process(0 "Usage: vbs ide <command>.*Commands:.*generate.*query" "" ide --help)
|
||||
check_process(0 "Usage: vbs ide generate " "" ide generate --help)
|
||||
check_process(0 "Usage: vbs ide query " "" ide query --help)
|
||||
@@ -59,4 +141,4 @@ execute_process(COMMAND "${VBS_REGISTRY}" --help
|
||||
if(NOT "${reg_code}" STREQUAL "0" OR NOT reg_out MATCHES "Usage: vbs-registry")
|
||||
message(FATAL_ERROR "vbs-registry --help failed: code=${reg_code}\nstdout=[${reg_out}]\nstderr=[${reg_err}]")
|
||||
endif()
|
||||
message(STATUS "37 native CLI and auto-generated Argparse help contracts verified")
|
||||
message(STATUS "CLI and auto-generated Argparse help contracts verified (including daemon describe round-trip)")
|
||||
@@ -4,15 +4,18 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -63,6 +66,42 @@ std::string str_field(const JsonObject &object, std::string_view name) {
|
||||
return text != nullptr ? *text : std::string{};
|
||||
}
|
||||
|
||||
std::optional<JsonObject>
|
||||
request_object(const std::filesystem::path &socket, std::string_view request_json,
|
||||
std::chrono::milliseconds timeout = std::chrono::seconds{120}) {
|
||||
auto response = Void::Build::Daemon::request(socket, request_json, timeout);
|
||||
if (!response) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto parsed = parse_json(*response);
|
||||
if (!parsed) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto *object = as_object(*parsed);
|
||||
if (object == nullptr) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *object;
|
||||
}
|
||||
|
||||
std::vector<std::string> string_array_field(const JsonObject &object, std::string_view name) {
|
||||
std::vector<std::string> result;
|
||||
const auto *value = field(object, name);
|
||||
if (value == nullptr) {
|
||||
return result;
|
||||
}
|
||||
const auto *array = std::get_if<JsonValue::Array>(&value->value);
|
||||
if (array == nullptr) {
|
||||
return result;
|
||||
}
|
||||
for (const auto &entry : *array) {
|
||||
if (const auto *text = std::get_if<std::string>(&entry.value)) {
|
||||
result.push_back(*text);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wait_for_path(const std::filesystem::path &path, std::chrono::milliseconds timeout) {
|
||||
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
||||
while (std::chrono::steady_clock::now() < deadline) {
|
||||
@@ -180,3 +219,220 @@ VOID_TEST(Daemon, second_create_reports_already_running) {
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(socket));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_evaluates_project_graph) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
auto app = project.executable("app");
|
||||
app.sources({"main.cpp"});
|
||||
}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "main.cpp"};
|
||||
source << "int main() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto describe =
|
||||
Void::Build::Daemon::request(socket, R"({"op":"describe"})", std::chrono::seconds{120});
|
||||
Void::Testing::require(describe.has_value());
|
||||
const auto describe_json = parse_json(*describe);
|
||||
Void::Testing::require(describe_json.has_value());
|
||||
const auto *describe_object = as_object(*describe_json);
|
||||
Void::Testing::require(describe_object != nullptr);
|
||||
Void::Testing::expect(bool_field(*describe_object, "ok"));
|
||||
Void::Testing::expect_eq(str_field(*describe_object, "op"), std::string{"describe"});
|
||||
Void::Testing::expect_eq(str_field(*describe_object, "profile"), std::string{"debug"});
|
||||
Void::Testing::expect(int_field(*describe_object, "targets") >= 1);
|
||||
Void::Testing::expect(int_field(*describe_object, "actions") >= 1);
|
||||
const auto target_names = string_array_field(*describe_object, "target_names");
|
||||
Void::Testing::expect(std::ranges::find(target_names, std::string{"app"}) !=
|
||||
target_names.end());
|
||||
|
||||
auto bad_profile = request_object(socket, R"({"op":"describe","profile":"does-not-exist"})");
|
||||
Void::Testing::require(bad_profile.has_value());
|
||||
Void::Testing::expect(!bool_field(*bad_profile, "ok", true));
|
||||
Void::Testing::expect(field(*bad_profile, "error") != nullptr);
|
||||
|
||||
auto numeric_profile = request_object(socket, R"({"op":"describe","profile":123})");
|
||||
Void::Testing::require(numeric_profile.has_value());
|
||||
Void::Testing::expect(!bool_field(*numeric_profile, "ok", true));
|
||||
Void::Testing::expect(str_field(*numeric_profile, "error").find("must be a string") !=
|
||||
std::string::npos);
|
||||
|
||||
auto empty_profile = request_object(socket, R"({"op":"describe","profile":""})");
|
||||
Void::Testing::require(empty_profile.has_value());
|
||||
Void::Testing::expect(!bool_field(*empty_profile, "ok", true));
|
||||
Void::Testing::expect(str_field(*empty_profile, "error").find("must not be empty") !=
|
||||
std::string::npos);
|
||||
|
||||
const std::string oversized_profile_request{R"({"op":"describe","profile":")" +
|
||||
std::string(129, 'p') + "\"}"};
|
||||
auto oversized_profile = request_object(socket, oversized_profile_request);
|
||||
Void::Testing::require(oversized_profile.has_value());
|
||||
Void::Testing::expect(!bool_field(*oversized_profile, "ok", true));
|
||||
Void::Testing::expect(str_field(*oversized_profile, "error").find("too long") !=
|
||||
std::string::npos);
|
||||
|
||||
auto numeric_compiler = request_object(socket, R"({"op":"describe","compiler":5})");
|
||||
Void::Testing::require(numeric_compiler.has_value());
|
||||
Void::Testing::expect(!bool_field(*numeric_compiler, "ok", true));
|
||||
Void::Testing::expect(str_field(*numeric_compiler, "error").find("must be a string") !=
|
||||
std::string::npos);
|
||||
|
||||
auto invalid_compiler = request_object(socket, R"({"op":"describe","compiler":"msvc"})");
|
||||
Void::Testing::require(invalid_compiler.has_value());
|
||||
Void::Testing::expect(!bool_field(*invalid_compiler, "ok", true));
|
||||
Void::Testing::expect(str_field(*invalid_compiler, "error").find("unknown compiler") !=
|
||||
std::string::npos);
|
||||
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(socket));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto describe = request_object(socket, R"({"op":"describe"})");
|
||||
Void::Testing::require(describe.has_value());
|
||||
Void::Testing::expect(bool_field(*describe, "ok"));
|
||||
Void::Testing::expect_eq(int_field(*describe, "targets"), std::int64_t{0});
|
||||
Void::Testing::expect_eq(int_field(*describe, "actions"), std::int64_t{0});
|
||||
Void::Testing::expect(string_array_field(*describe, "target_names").empty());
|
||||
Void::Testing::expect(field(*describe, "target_names_truncated") == nullptr);
|
||||
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(socket));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_bounds_target_names_for_large_projects) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <string>
|
||||
#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
for (int i = 0; i < 140; ++i) {
|
||||
auto target = project.executable(std::to_string(i) + std::string(240, 'a'));
|
||||
target.sources({"main.cpp"});
|
||||
}
|
||||
}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "main.cpp"};
|
||||
source << "int main() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto raw =
|
||||
Void::Build::Daemon::request(socket, R"({"op":"describe"})", std::chrono::seconds{120});
|
||||
Void::Testing::require(raw.has_value());
|
||||
// 128 names x 200 bytes plus JSON overhead stays well under 32 KiB.
|
||||
Void::Testing::expect(raw->size() < 32U * 1024U);
|
||||
const auto parsed = parse_json(*raw);
|
||||
Void::Testing::require(parsed.has_value());
|
||||
const auto *object = as_object(*parsed);
|
||||
Void::Testing::require(object != nullptr);
|
||||
Void::Testing::expect(bool_field(*object, "ok"));
|
||||
Void::Testing::expect_eq(int_field(*object, "targets"), std::int64_t{140});
|
||||
Void::Testing::expect(int_field(*object, "actions") >= 140);
|
||||
const auto names = string_array_field(*object, "target_names");
|
||||
Void::Testing::expect_eq(names.size(), std::size_t{128});
|
||||
for (const auto &name : names) {
|
||||
Void::Testing::expect(name.size() <= 200U);
|
||||
}
|
||||
Void::Testing::expect(bool_field(*object, "target_names_truncated"));
|
||||
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(socket));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_rejects_workspace_root) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream workspace{options.project_root / "workspace.cpp"};
|
||||
workspace << "void workspace(Void::Build::Workspace &workspace) {}\n";
|
||||
Void::Testing::require(workspace.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto describe = request_object(socket, R"({"op":"describe"})");
|
||||
Void::Testing::require(describe.has_value());
|
||||
Void::Testing::expect(!bool_field(*describe, "ok", true));
|
||||
Void::Testing::expect(str_field(*describe, "error").find("workspace") != std::string::npos);
|
||||
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(socket));
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::string_view kDigest =
|
||||
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
|
||||
std::string read_text(const std::filesystem::path &path) {
|
||||
std::ifstream stream{path, std::ios::binary};
|
||||
return std::string{std::istreambuf_iterator<char>{stream}, std::istreambuf_iterator<char>{}};
|
||||
}
|
||||
|
||||
void write_text(const std::filesystem::path &path, std::string_view text) {
|
||||
std::ofstream stream{path, std::ios::binary | std::ios::trunc};
|
||||
stream.write(text.data(), static_cast<std::streamsize>(text.size()));
|
||||
}
|
||||
|
||||
bool is_lower_hex(std::string_view text) {
|
||||
return std::ranges::all_of(
|
||||
text, [](char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); });
|
||||
}
|
||||
|
||||
std::string uppercase(std::string value) {
|
||||
std::ranges::transform(value, value.begin(), [](char c) {
|
||||
return static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string tampered(std::string value) {
|
||||
value.front() = value.front() == '0' ? '1' : '0';
|
||||
return value;
|
||||
}
|
||||
|
||||
Void::FileSystem::TempDir make_temp_dir() {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_signing_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
return std::move(*temp);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(Signing, canonical_package_message_is_exact_and_stable) {
|
||||
using Void::Build::Provenance::canonical_package_message;
|
||||
const std::string expected =
|
||||
"vbs-package-v1\nvoid-core@1.2.3\nsha256:" + std::string{kDigest} + "\n";
|
||||
Void::Testing::expect_eq(canonical_package_message("void-core", "1.2.3", kDigest), expected);
|
||||
Void::Testing::expect_eq(canonical_package_message("void-core", "1.2.3", kDigest), expected);
|
||||
}
|
||||
|
||||
VOID_TEST(Signing, seed_roundtrip_sign_verify_and_rejections) {
|
||||
namespace Provenance = Void::Build::Provenance;
|
||||
if (!Provenance::signing_available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto temp = make_temp_dir();
|
||||
const auto seed_path = temp.path() / "signing.seed";
|
||||
|
||||
auto generated = Provenance::generate_signing_seed(seed_path);
|
||||
Void::Testing::require(generated.has_value());
|
||||
|
||||
const std::string contents = read_text(seed_path);
|
||||
Void::Testing::expect_eq(contents.size(), std::size_t{65});
|
||||
if (contents.size() == 65) {
|
||||
Void::Testing::expect(contents.back() == '\n');
|
||||
Void::Testing::expect(is_lower_hex(std::string_view{contents}.substr(0, 64)));
|
||||
}
|
||||
|
||||
using Perms = std::filesystem::perms;
|
||||
const auto permissions = std::filesystem::status(seed_path).permissions();
|
||||
Void::Testing::expect((permissions & Perms::owner_read) != Perms::none);
|
||||
Void::Testing::expect((permissions & Perms::owner_write) != Perms::none);
|
||||
Void::Testing::expect((permissions & (Perms::group_all | Perms::others_all)) == Perms::none);
|
||||
|
||||
auto public_key = Provenance::public_key_from_seed(seed_path);
|
||||
Void::Testing::require(public_key.has_value());
|
||||
Void::Testing::expect_eq(public_key->size(), std::size_t{64});
|
||||
|
||||
auto signature = Provenance::sign_package("void-core", "1.2.3", kDigest, seed_path);
|
||||
Void::Testing::require(signature.has_value());
|
||||
Void::Testing::expect_eq(signature->size(), std::size_t{128});
|
||||
|
||||
auto verified =
|
||||
Provenance::verify_package("void-core", "1.2.3", kDigest, *signature, *public_key);
|
||||
Void::Testing::require(verified.has_value());
|
||||
Void::Testing::expect(*verified);
|
||||
|
||||
// Hex input accepts uppercase as well as lowercase.
|
||||
auto upper_verified = Provenance::verify_package("void-core", "1.2.3", kDigest,
|
||||
uppercase(*signature), uppercase(*public_key));
|
||||
Void::Testing::require(upper_verified.has_value());
|
||||
Void::Testing::expect(*upper_verified);
|
||||
|
||||
std::string other_digest{kDigest};
|
||||
other_digest.back() = other_digest.back() == '0' ? '1' : '0';
|
||||
auto digest_result =
|
||||
Provenance::verify_package("void-core", "1.2.3", other_digest, *signature, *public_key);
|
||||
Void::Testing::require(digest_result.has_value());
|
||||
Void::Testing::expect(!*digest_result);
|
||||
|
||||
auto signature_result = Provenance::verify_package("void-core", "1.2.3", kDigest,
|
||||
tampered(*signature), *public_key);
|
||||
Void::Testing::require(signature_result.has_value());
|
||||
Void::Testing::expect(!*signature_result);
|
||||
|
||||
const auto other_seed_path = temp.path() / "other.seed";
|
||||
Void::Testing::require(Provenance::generate_signing_seed(other_seed_path).has_value());
|
||||
auto other_public_key = Provenance::public_key_from_seed(other_seed_path);
|
||||
Void::Testing::require(other_public_key.has_value());
|
||||
Void::Testing::expect(*other_public_key != *public_key);
|
||||
|
||||
auto wrong_key_result =
|
||||
Provenance::verify_package("void-core", "1.2.3", kDigest, *signature, *other_public_key);
|
||||
Void::Testing::require(wrong_key_result.has_value());
|
||||
Void::Testing::expect(!*wrong_key_result);
|
||||
}
|
||||
|
||||
VOID_TEST(Signing, malformed_hex_and_seed_files_are_rejected) {
|
||||
namespace Provenance = Void::Build::Provenance;
|
||||
if (!Provenance::signing_available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto temp = make_temp_dir();
|
||||
const auto seed_path = temp.path() / "signing.seed";
|
||||
Void::Testing::require(Provenance::generate_signing_seed(seed_path).has_value());
|
||||
auto public_key = Provenance::public_key_from_seed(seed_path);
|
||||
Void::Testing::require(public_key.has_value());
|
||||
auto signature = Provenance::sign_package("void-core", "1.2.3", kDigest, seed_path);
|
||||
Void::Testing::require(signature.has_value());
|
||||
|
||||
for (const std::string_view bad_signature :
|
||||
{std::string_view{}, std::string_view{"00"}, std::string_view{std::string(128, 'z')}}) {
|
||||
auto result =
|
||||
Provenance::verify_package("void-core", "1.2.3", kDigest, bad_signature, *public_key);
|
||||
Void::Testing::expect(!result.has_value());
|
||||
}
|
||||
auto bad_key =
|
||||
Provenance::verify_package("void-core", "1.2.3", kDigest, *signature, "not-a-key");
|
||||
Void::Testing::expect(!bad_key.has_value());
|
||||
|
||||
const auto bad_seed_path = temp.path() / "bad.seed";
|
||||
write_text(bad_seed_path, std::string(63, 'a'));
|
||||
Void::Testing::expect(!Provenance::public_key_from_seed(bad_seed_path).has_value());
|
||||
|
||||
write_text(bad_seed_path, std::string(64, 'g'));
|
||||
Void::Testing::expect(!Provenance::public_key_from_seed(bad_seed_path).has_value());
|
||||
|
||||
write_text(bad_seed_path, std::string(64, 'a') + "trailing");
|
||||
Void::Testing::expect(!Provenance::public_key_from_seed(bad_seed_path).has_value());
|
||||
|
||||
// Optional trailing whitespace is accepted.
|
||||
write_text(bad_seed_path, read_text(seed_path) + " \t\r\n");
|
||||
auto whitespace_key = Provenance::public_key_from_seed(bad_seed_path);
|
||||
Void::Testing::require(whitespace_key.has_value());
|
||||
Void::Testing::expect_eq(*whitespace_key, *public_key);
|
||||
|
||||
const auto directory_path = temp.path() / "seed-directory";
|
||||
std::filesystem::create_directory(directory_path);
|
||||
Void::Testing::expect(!Provenance::public_key_from_seed(directory_path).has_value());
|
||||
Void::Testing::expect(
|
||||
!Provenance::public_key_from_seed(temp.path() / "missing.seed").has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(Signing, backend_gating_reports_openssl_requirement) {
|
||||
namespace Provenance = Void::Build::Provenance;
|
||||
if (Provenance::signing_available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto temp = make_temp_dir();
|
||||
const auto seed_path = temp.path() / "signing.seed";
|
||||
|
||||
auto generated = Provenance::generate_signing_seed(seed_path);
|
||||
Void::Testing::expect(!generated.has_value());
|
||||
if (!generated) {
|
||||
Void::Testing::expect(generated.error().message().find("OpenSSL") != std::string::npos);
|
||||
}
|
||||
|
||||
auto signed_result = Provenance::sign_package("void-core", "1.2.3", kDigest, seed_path);
|
||||
Void::Testing::expect(!signed_result.has_value());
|
||||
if (!signed_result) {
|
||||
Void::Testing::expect(signed_result.error().message().find("OpenSSL") != std::string::npos);
|
||||
}
|
||||
|
||||
auto verified_result = Provenance::verify_package("void-core", "1.2.3", kDigest,
|
||||
std::string(128, '0'), std::string(64, '0'));
|
||||
Void::Testing::expect(!verified_result.has_value());
|
||||
if (!verified_result) {
|
||||
Void::Testing::expect(verified_result.error().message().find("OpenSSL") !=
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user