feat(daemon,registry): filter watch events by prefix; answer OPTIONS
This commit is contained in:
1 parent
e7698a411d
commit
e61eff7a8f
9 files changed
+208
-11
No files matched your search
@@ -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();
|
||||
}
|
||||
Reference in new issue
Block a user