feat(package,daemon): revoke registry tokens; allow daemon deps updates
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s

This commit is contained in:
faumaray committed 2026-12-04 07:20:06 +03:00
1 parent eb35bb6b6e
commit c7d2662cf2
11 files changed
+309 -13

No files matched your search

+2 -1
View File
@@ -51,7 +51,8 @@ check_process(0 "Usage: vbs binaries <command>.*Commands:.*list.*fetch" "" binar
check_process(0 "Usage: vbs binaries list " "" binaries list --help)
check_process(0 "Usage: vbs releases list " "" releases list --help)
check_process(0 "Usage: vbs tokens list " "" tokens list --help)
check_process(2 "" "vbs tokens list: --registry is required" tokens list)
check_process(2 "" "vbs tokens: --registry is required" tokens list)
check_process(0 "Usage: vbs tokens revoke .*--token-id" "" tokens revoke --help)
check_process(2 "" "--registry and --name are required" releases list)
check_process(0 "Usage: vbs releases show " "" releases show --help)
check_process(2 "" "--registry, --name, and --version are required" releases show)
+171
View File
@@ -1,4 +1,5 @@
#include <Void/Build/Daemon/Daemon.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Platform/Host.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Data/StrictJson.hpp>
@@ -455,6 +456,23 @@ void build(Void::Build::Project &project) {
Void::Testing::expect(str_field(*invalid_offline, "error").find("boolean") !=
std::string::npos);
auto update_deps =
request_object(socket, R"({"op":"deps","update":true})", std::chrono::seconds{120});
Void::Testing::require(update_deps.has_value());
Void::Testing::expect(bool_field(*update_deps, "ok"));
const auto *update_entries = field(*update_deps, "entries");
Void::Testing::require(update_entries != nullptr);
const auto *update_array = std::get_if<JsonValue::Array>(&update_entries->value);
Void::Testing::require(update_array != nullptr && !update_array->empty());
const auto *update_first = std::get_if<JsonObject>(&update_array->front().value);
Void::Testing::require(update_first != nullptr);
Void::Testing::expect_eq(str_field(*update_first, "alias"), std::string{"helper"});
auto invalid_update = request_object(socket, R"({"op":"deps","update":"yes"})");
Void::Testing::require(invalid_update.has_value());
Void::Testing::expect(!bool_field(*invalid_update, "ok", true));
Void::Testing::expect(str_field(*invalid_update, "error").find("boolean") != std::string::npos);
auto build = request_object(socket, R"({"op":"build"})", std::chrono::seconds{120});
Void::Testing::require(build.has_value());
Void::Testing::expect(bool_field(*build, "ok"));
@@ -517,6 +535,159 @@ void build(Void::Build::Project &project) {
Void::Testing::expect(run_result.has_value());
}
VOID_TEST(Daemon, deps_update_flag_is_validated_and_accepted) {
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 default_deps = request_object(socket, R"({"op":"deps"})", std::chrono::seconds{120});
Void::Testing::require(default_deps.has_value());
Void::Testing::expect(bool_field(*default_deps, "ok"));
const auto *default_entries = field(*default_deps, "entries");
Void::Testing::require(default_entries != nullptr);
const auto *default_array = std::get_if<JsonValue::Array>(&default_entries->value);
Void::Testing::require(default_array != nullptr && default_array->empty());
auto update_deps =
request_object(socket, R"({"op":"deps","update":true})", std::chrono::seconds{120});
Void::Testing::require(update_deps.has_value());
Void::Testing::expect(bool_field(*update_deps, "ok"));
const auto *update_entries = field(*update_deps, "entries");
Void::Testing::require(update_entries != nullptr);
const auto *update_array = std::get_if<JsonValue::Array>(&update_entries->value);
Void::Testing::require(update_array != nullptr && update_array->empty());
auto invalid_update = request_object(socket, R"({"op":"deps","update":"yes"})");
Void::Testing::require(invalid_update.has_value());
Void::Testing::expect(!bool_field(*invalid_update, "ok", true));
Void::Testing::expect(
str_field(*invalid_update, "error").find("\"update\" must be a boolean") !=
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());
}
// Proves the `update` flag reaches ResolveOptions::allow_upgrade: a pinned package that is fully
// cached resolves offline by default, but must force a registry query when update=true.
VOID_TEST(Daemon, deps_update_bypasses_pinned_lock_offline) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());
const auto options = make_options(temp->path());
const auto write_descriptor = [&](bool with_dependency) {
std::ofstream descriptor{options.project_root / "build.cpp"};
descriptor << "#include <Void/Build.hpp>\n\n"
"void build(Void::Build::Project &project) {\n";
if (with_dependency) {
descriptor << " project.dependency(\"remote\")\n"
" .package(\"remote-pkg\", \"^1.0\")\n"
" .registry(\"http://127.0.0.1:1\");\n";
}
descriptor << " auto app = project.executable(\"app\");\n"
" app.sources({\"main.cpp\"});\n"
"}\n";
Void::Testing::require(descriptor.good());
};
write_descriptor(false);
{
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}));
// Ask the daemon for the context key it uses for this profile instead of hard-coding it.
auto baseline = request_object(socket, R"({"op":"deps"})", std::chrono::seconds{120});
Void::Testing::require(baseline.has_value());
Void::Testing::expect(bool_field(*baseline, "ok"));
const std::string context_key = str_field(*baseline, "context_key");
Void::Testing::require(!context_key.empty());
write_descriptor(true);
// Pin the package in vbs.lock and pre-populate its extracted cache entry, so offline
// resolution can succeed without any network access while the pin is honored.
const std::string cached_sha(64, 'a');
const auto cached_source =
options.build_root / ".vbs" / "cache" / "packages" / cached_sha / "src";
std::filesystem::create_directories(cached_source);
Void::Build::Package::LockContextRecord record;
record.context_key = context_key;
record.profile_name = str_field(*baseline, "profile");
record.machine_role = "target";
Void::Build::Package::LockedSourceEntry entry;
entry.alias = "remote";
entry.source_kind = "package";
entry.registry_authority = "http://127.0.0.1:1";
entry.package_name = "remote-pkg";
entry.version = "1.0.0";
entry.sha256 = cached_sha;
record.entries.push_back(std::move(entry));
auto published = Void::Build::Package::publish_lock_context_cas(
options.project_root / "vbs.lock", "", record);
Void::Testing::require(published.has_value());
auto pinned =
request_object(socket, R"({"op":"deps","offline":true})", std::chrono::seconds{120});
Void::Testing::require(pinned.has_value());
Void::Testing::expect(bool_field(*pinned, "ok"));
const auto *pinned_entries = field(*pinned, "entries");
Void::Testing::require(pinned_entries != nullptr);
const auto *pinned_array = std::get_if<JsonValue::Array>(&pinned_entries->value);
Void::Testing::require(pinned_array != nullptr && !pinned_array->empty());
// update=true discards the pinned lock, so offline resolution must now fail while trying to
// reach the registry; success here would mean allow_upgrade was never set.
auto upgraded = request_object(socket, R"({"op":"deps","offline":true,"update":true})",
std::chrono::seconds{120});
Void::Testing::require(upgraded.has_value());
Void::Testing::expect(!bool_field(*upgraded, "ok", true));
Void::Testing::expect(
str_field(*upgraded, "error").find("offline mode cannot query live package registry") !=
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_TEST(Daemon, ide_query_serves_workspace_targets_and_compdb) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());
+47
View File
@@ -1331,6 +1331,53 @@ target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include
Void::Testing::expect(tokens_res->stdout_data.find(*tok) == std::string::npos);
}
// Revoke a second token through the CLI and observe it in the listing.
auto extra_token = (*svc)->create_token("ci_pub", "extra", {"read"});
Void::Testing::require(extra_token.has_value());
tokens_list.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
auto second_list = Platform::run_supervised(tokens_list);
Void::Testing::require(second_list.has_value() && second_list->succeeded());
std::string extra_id;
{
std::size_t pos = 0;
const std::string &out = second_list->stdout_data;
while (pos < out.size()) {
const auto nl = out.find('\n', pos);
const std::string line = out.substr(pos, nl == std::string::npos ? std::string::npos : nl - pos);
if (line.find(" extra ") != std::string::npos) {
extra_id = line.substr(0, line.find(' '));
}
if (nl == std::string::npos) {
break;
}
pos = nl + 1;
}
}
Void::Testing::require(!extra_id.empty());
Platform::ProcessRequest revoke_req = tokens_list;
revoke_req.arguments = {"tokens", "revoke", "--registry", reg_url, "--token-id", extra_id};
auto revoke_res = Platform::run_supervised(revoke_req);
Void::Testing::expect(revoke_res.has_value() && revoke_res->succeeded());
auto final_list = Platform::run_supervised(tokens_list);
Void::Testing::require(final_list.has_value() && final_list->succeeded());
bool saw_revoked = false;
{
std::size_t pos = 0;
const std::string &out = final_list->stdout_data;
while (pos < out.size()) {
const auto nl = out.find('\n', pos);
const std::string line = out.substr(pos, nl == std::string::npos ? std::string::npos : nl - pos);
if (line.starts_with(extra_id) && line.find("revoked") != std::string::npos) {
saw_revoked = true;
}
if (nl == std::string::npos) {
break;
}
pos = nl + 1;
}
}
Void::Testing::expect(saw_revoked);
Platform::ProcessRequest releases_list;
releases_list.executable = vbs_bin;
releases_list.arguments = {"releases", "list", "--registry", reg_url, "--name", "hello-pkg"};