feat(daemon,registry): filter watch events by prefix; answer OPTIONS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 7s

This commit is contained in:
faumaray committed 2026-12-04 06:30:05 +03:00
1 parent e7698a411d
commit e61eff7a8f
9 files changed
+208 -11

No files matched your search

+12 -1
View File
@@ -704,8 +704,19 @@ VOID_TEST(Daemon, watch_poll_reports_changed_paths) {
std::this_thread::sleep_for(std::chrono::milliseconds{50});
bool saw_probe = false;
bool non_matching_prefix_seen = false;
for (int attempt = 0; attempt < 100 && !saw_probe; ++attempt) {
auto poll = request_object(socket, R"({"op":"watch_poll"})");
if (!non_matching_prefix_seen) {
// A non-matching prefix must not consume the buffered event.
auto non_matching = request_object(
socket, R"({"op":"watch_poll","prefix":"/nonexistent-prefix/"})");
Void::Testing::require(non_matching.has_value());
Void::Testing::expect(string_array_field(*non_matching, "changed").empty());
non_matching_prefix_seen = true;
}
auto poll = request_object(
socket, std::format(R"({{"op":"watch_poll","prefix":{}}})",
Void::Build::Util::json_quote(options.project_root.string())));
Void::Testing::require(poll.has_value());
for (const auto &path : string_array_field(*poll, "changed")) {
if (path.find("probe.txt") != std::string::npos) {
+65
View File
@@ -134,6 +134,14 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
auto trav = send_loopback_http(port, "GET", "/../CMakeLists.txt");
Void::Testing::expect(trav.has_value() && trav->status == 403);
// OPTIONS preflight advertises the supported API methods with a bodyless 204.
auto options_resp = send_loopback_http(port, "OPTIONS", "/api/v1/packages");
Void::Testing::expect(options_resp.has_value() && options_resp->status == 204);
if (options_resp) {
Void::Testing::expect(options_resp->headers.contains("allow"));
Void::Testing::expect(options_resp->headers.at("allow").find("GET") != std::string::npos);
}
// 2. Build a valid deterministic package tar and publish as Publisher Alice.
const auto pkg_src = tmp / "pkg_src";
(void)Platform::atomic_write_file(pkg_src / "build.cpp",
@@ -1626,3 +1634,60 @@ VOID_TEST(RegistryTests, registry_release_detail_fields_signature_404_and_privat
(*svc)->stop_http();
}
// OPTIONS preflight: metadata and download routes answer 204 + Allow from the path shape alone,
// without authentication or a published release.
VOID_TEST(RegistryTests, options_preflight_metadata_and_download_endpoints) {
Void::FileSystem::TempDir tmp{"vbs_reg_options_"};
RegistryConfig cfg;
cfg.data_dir = tmp / "data";
cfg.bind_address = "127.0.0.1";
cfg.port = 0;
cfg.bootstrap_admin_user = "admin";
cfg.bootstrap_admin_password = "admin_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::require((*svc)->start_http().has_value());
const auto port = (*svc)->bound_port();
const auto expect_options = [port](const std::string &path, const std::string &expected_allow) {
auto resp = send_loopback_http(port, "OPTIONS", path);
Void::Testing::require(resp.has_value());
Void::Testing::expect_eq(static_cast<int>(resp->status), 204);
Void::Testing::expect(resp->body.empty());
Void::Testing::expect(resp->headers.contains("allow"));
if (resp->headers.contains("allow")) {
Void::Testing::expect_eq(resp->headers.at("allow"), expected_allow);
}
};
expect_options("/api/v1/packages", "GET, HEAD, OPTIONS");
expect_options("/api/v1/packages/demo-pkg", "GET, HEAD, PATCH, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/owners", "GET, HEAD, PUT, POST, DELETE, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0", "GET, HEAD, PUT, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/download", "GET, HEAD, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries", "GET, HEAD, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64",
"GET, HEAD, PUT, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64/download",
"GET, HEAD, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/yank", "POST, OPTIONS");
expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64/yank", "POST, OPTIONS");
// Preflight never demands authentication, even for a private package's download route.
expect_options("/api/v1/packages/secret-pkg/1.0.0/download", "GET, HEAD, OPTIONS");
// Unknown API shapes keep the existing 404 behaviour.
auto unknown = send_loopback_http(port, "OPTIONS", "/api/v1/does-not-exist");
Void::Testing::expect(unknown.has_value() && unknown->status == 404);
// The OPTIONS branch must not regress ordinary GET routing.
auto list = send_loopback_http(port, "GET", "/api/v1/packages");
Void::Testing::expect(list.has_value() && list->status == 200);
(*svc)->stop_http();
}