1720 lines
86 KiB
C++
1720 lines
86 KiB
C++
#include <Void/Build/BootstrapConfig.hpp>
|
|
#include <Void/Build/Package/Archive.hpp>
|
|
#include <Void/Build/Package/Fetch.hpp>
|
|
#include <Void/Build/Package/RegistryClient.hpp>
|
|
#include <Void/Build/Platform/FileOps.hpp>
|
|
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
|
#include <Void/Build/Provenance/Signing.hpp>
|
|
#include <Void/Build/Provenance/Verification.hpp>
|
|
#include <Void/Build/Registry/HttpServer.hpp>
|
|
#include <Void/Build/Registry/RegistryService.hpp>
|
|
#include <Void/Build/State/StateStore.hpp>
|
|
#include <Void/Build/Util/Sha256.hpp>
|
|
#include <Void/Data/StrictJson.hpp>
|
|
#include <Void/System/Path.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <optional>
|
|
#include <span>
|
|
|
|
using namespace Void::Build;
|
|
using namespace Void::Build::Registry;
|
|
|
|
namespace {
|
|
|
|
std::string extract_session_cookie(const std::vector<std::string> &set_cookies) {
|
|
for (const auto &sc : set_cookies) {
|
|
if (sc.starts_with("vbs_session=")) {
|
|
const auto semi = sc.find(';');
|
|
return sc.substr(0, semi);
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
std::string extract_json_str(std::string_view json, const std::string &key) {
|
|
auto parsed = Void::Json::Strict::parse(json);
|
|
if (!parsed)
|
|
return {};
|
|
const auto *obj = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
|
if (!obj)
|
|
return {};
|
|
const auto it = obj->find(key);
|
|
if (it == obj->end())
|
|
return {};
|
|
const auto *s = std::get_if<std::string>(&it->second.value);
|
|
return s ? *s : std::string{};
|
|
}
|
|
|
|
std::optional<std::int64_t> extract_json_int(std::string_view json, const std::string &key) {
|
|
auto parsed = Void::Json::Strict::parse(json);
|
|
if (!parsed)
|
|
return std::nullopt;
|
|
const auto *obj = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
|
if (!obj)
|
|
return std::nullopt;
|
|
const auto it = obj->find(key);
|
|
if (it == obj->end())
|
|
return std::nullopt;
|
|
const auto *n = std::get_if<std::int64_t>(&it->second.value);
|
|
return n ? std::optional<std::int64_t>{*n} : std::nullopt;
|
|
}
|
|
|
|
std::optional<bool> extract_json_bool(std::string_view json, const std::string &key) {
|
|
auto parsed = Void::Json::Strict::parse(json);
|
|
if (!parsed)
|
|
return std::nullopt;
|
|
const auto *obj = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
|
if (!obj)
|
|
return std::nullopt;
|
|
const auto it = obj->find(key);
|
|
if (it == obj->end())
|
|
return std::nullopt;
|
|
const auto *b = std::get_if<bool>(&it->second.value);
|
|
return b ? std::optional<bool>{*b} : std::nullopt;
|
|
}
|
|
|
|
std::filesystem::path locate_vbs_binary() {
|
|
std::error_code ec;
|
|
if (const auto self_exe = Platform::current_executable_path(); self_exe) {
|
|
const auto sibling = self_exe->parent_path() / "vbs";
|
|
if (std::filesystem::exists(sibling, ec)) {
|
|
return sibling;
|
|
}
|
|
}
|
|
if (!Bootstrap::binary_dir.empty()) {
|
|
return std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs";
|
|
}
|
|
return {};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_restore) {
|
|
Void::FileSystem::TempDir tmp{"vbs_reg_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
cfg.bind_address = "127.0.0.1";
|
|
cfg.port = 0; // Ephemeral port!
|
|
cfg.bootstrap_admin_user = "admin";
|
|
cfg.bootstrap_admin_password = "admin_secret_password";
|
|
|
|
auto svc = RegistryService::open(cfg);
|
|
Void::Testing::expect(svc.has_value());
|
|
if (!svc)
|
|
return;
|
|
|
|
Void::Testing::expect(
|
|
(*svc)->create_user("pub_alice", "alice_pass", Role::Publisher).has_value());
|
|
Void::Testing::expect((*svc)->create_user("read_bob", "bob_pass", Role::Reader).has_value());
|
|
auto alice_tok = (*svc)->create_token("pub_alice", "ci", {"read", "publish"});
|
|
auto bob_tok = (*svc)->create_token("read_bob", "ro", {"read"});
|
|
Void::Testing::expect(alice_tok.has_value() && bob_tok.has_value());
|
|
if (!alice_tok || !bob_tok)
|
|
return;
|
|
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
Void::Testing::expect(port > 0);
|
|
|
|
// 1. Static web UI assets served with security headers; path traversal blocked!
|
|
auto idx = send_loopback_http(port, "GET", "/");
|
|
Void::Testing::expect(idx.has_value() && idx->status == 200);
|
|
if (idx) {
|
|
Void::Testing::expect(idx->headers.contains("content-security-policy"));
|
|
Void::Testing::expect_eq(idx->headers.at("x-frame-options"), std::string{"DENY"});
|
|
Void::Testing::expect(idx->body.find("VoidBuildSystem Registry") != std::string::npos);
|
|
}
|
|
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",
|
|
"void build(Void::Build::Project&){}\n", false);
|
|
const auto tar1 = tmp / "p1.tar";
|
|
auto sha1 = Package::create_source_package(pkg_src, tar1, 0);
|
|
Void::Testing::expect(sha1.has_value());
|
|
auto bytes1 = Void::FileSystem::read_file(tar1);
|
|
Void::Testing::expect(bytes1.has_value());
|
|
if (!sha1 || !bytes1)
|
|
return;
|
|
|
|
// Reader Bob CANNOT publish (403)!
|
|
auto bob_pub = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *bob_tok}, {"X-Content-SHA256", *sha1}}, *bytes1);
|
|
Void::Testing::expect(bob_pub.has_value() && bob_pub->status == 403);
|
|
|
|
// Wrong SHA-256 rejected (400)!
|
|
auto bad_sha = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", std::string(64, '0')}},
|
|
*bytes1);
|
|
Void::Testing::expect(bad_sha.has_value() && bad_sha->status == 400);
|
|
|
|
// Malicious non-tar / traversal upload rejected (422)!
|
|
auto bad_tar =
|
|
send_loopback_http(port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok}}, "not a valid tar archive");
|
|
Void::Testing::expect(bad_tar.has_value() && bad_tar->status == 422);
|
|
|
|
// Valid private package publish by Alice -> 201 Created!
|
|
auto pub_ok = send_loopback_http(port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok},
|
|
{"X-Content-SHA256", *sha1},
|
|
{"X-Package-Private", "true"},
|
|
{"X-Package-Description", "<script>alert('xss')</script>"}},
|
|
*bytes1);
|
|
Void::Testing::expect(pub_ok.has_value() && pub_ok->status == 201);
|
|
|
|
// Signature metadata is stored and served verbatim (the registry is not a trust authority).
|
|
const std::string release_signature(128, 'a');
|
|
const std::string release_public_key(64, 'b');
|
|
auto signed_pub = send_loopback_http(port, "PUT", "/api/v1/packages/signed-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok},
|
|
{"X-Content-SHA256", *sha1},
|
|
{"X-Package-Signature", release_signature},
|
|
{"X-Package-Public-Key", release_public_key}},
|
|
*bytes1);
|
|
Void::Testing::expect(signed_pub.has_value() && signed_pub->status == 201);
|
|
auto signed_detail = send_loopback_http(port, "GET", "/api/v1/packages/signed-pkg",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(signed_detail.has_value() && signed_detail->status == 200);
|
|
if (signed_detail) {
|
|
Void::Testing::expect(signed_detail->body.find(release_signature) != std::string::npos);
|
|
Void::Testing::expect(signed_detail->body.find(release_public_key) != std::string::npos);
|
|
}
|
|
auto bad_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/bad-sig-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok},
|
|
{"X-Content-SHA256", *sha1},
|
|
{"X-Package-Signature", std::string(127, 'a')},
|
|
{"X-Package-Public-Key", release_public_key}},
|
|
*bytes1);
|
|
Void::Testing::expect(bad_sig_pub.has_value() && bad_sig_pub->status == 400);
|
|
auto half_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/half-sig-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok},
|
|
{"X-Content-SHA256", *sha1},
|
|
{"X-Package-Signature", release_signature}},
|
|
*bytes1);
|
|
Void::Testing::expect(half_sig_pub.has_value() && half_sig_pub->status == 400);
|
|
|
|
// Mutable metadata: an owner can patch the description; invalid updates are rejected.
|
|
// A private package keeps anonymous search totals unchanged for later assertions.
|
|
auto meta_pub = send_loopback_http(port, "PUT", "/api/v1/packages/meta-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok},
|
|
{"X-Content-SHA256", *sha1},
|
|
{"X-Package-Private", "true"}},
|
|
*bytes1);
|
|
Void::Testing::expect(meta_pub.has_value() && meta_pub->status == 201);
|
|
auto patched = send_loopback_http(
|
|
port, "PATCH", "/api/v1/packages/meta-pkg",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"Content-Type", "application/json"}},
|
|
"{\"description\":\"patched description\"}");
|
|
Void::Testing::expect(patched.has_value() && patched->status == 200);
|
|
auto patched_detail = send_loopback_http(port, "GET", "/api/v1/packages/meta-pkg",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(patched_detail.has_value() && patched_detail->status == 200);
|
|
if (patched_detail) {
|
|
Void::Testing::expect(patched_detail->body.find("patched description") !=
|
|
std::string::npos);
|
|
}
|
|
auto patch_no_auth = send_loopback_http(port, "PATCH", "/api/v1/packages/meta-pkg", {},
|
|
"{\"description\":\"x\"}");
|
|
Void::Testing::expect(patch_no_auth.has_value() && patch_no_auth->status == 401);
|
|
auto patch_non_owner = send_loopback_http(
|
|
port, "PATCH", "/api/v1/packages/meta-pkg",
|
|
{{"Authorization", "Bearer " + *bob_tok}, {"Content-Type", "application/json"}},
|
|
"{\"description\":\"x\"}");
|
|
Void::Testing::expect(patch_non_owner.has_value() && patch_non_owner->status == 403);
|
|
auto patch_empty = send_loopback_http(
|
|
port, "PATCH", "/api/v1/packages/meta-pkg",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"Content-Type", "application/json"}}, "{}");
|
|
Void::Testing::expect(patch_empty.has_value() && patch_empty->status == 400);
|
|
auto patch_bad_private = send_loopback_http(
|
|
port, "PATCH", "/api/v1/packages/meta-pkg",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"Content-Type", "application/json"}},
|
|
"{\"private\":\"yes\"}");
|
|
Void::Testing::expect(patch_bad_private.has_value() && patch_bad_private->status == 400);
|
|
|
|
// Package ownership management (bearer tokens are not ambient browser credentials).
|
|
auto owner_pkg_pub = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/owner-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", *sha1}}, *bytes1);
|
|
Void::Testing::expect(owner_pkg_pub.has_value() && owner_pkg_pub->status == 201);
|
|
auto owners = send_loopback_http(port, "GET", "/api/v1/packages/owner-pkg/owners",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(owners.has_value() && owners->status == 200);
|
|
if (owners) {
|
|
Void::Testing::expect(owners->body.find("pub_alice") != std::string::npos);
|
|
}
|
|
// The RegistryClient helper parses the owners endpoint and surfaces a missing package.
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
|
auto client_owners =
|
|
Package::fetch_package_owners(reg_url, "owner-pkg", Package::RegistryAuth{*alice_tok});
|
|
Void::Testing::require(client_owners.has_value());
|
|
Void::Testing::expect(std::ranges::find(*client_owners, std::string{"pub_alice"}) !=
|
|
client_owners->end());
|
|
auto missing_owners =
|
|
Package::fetch_package_owners(reg_url, "missing-pkg", Package::RegistryAuth{*alice_tok});
|
|
Void::Testing::expect(!missing_owners.has_value());
|
|
if (!missing_owners) {
|
|
Void::Testing::expect(missing_owners.error().message().find("404") != std::string::npos);
|
|
}
|
|
// Private packages require read permission, so anonymous access is rejected.
|
|
auto denied_owners =
|
|
Package::fetch_package_owners(reg_url, "secret-pkg", Package::RegistryAuth{});
|
|
Void::Testing::expect(!denied_owners.has_value());
|
|
if (!denied_owners) {
|
|
Void::Testing::expect(denied_owners.error().message().find("401") != std::string::npos);
|
|
}
|
|
auto add_owner = send_loopback_http(port, "PUT", "/api/v1/packages/owner-pkg/owners/read_bob",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::require(add_owner.has_value());
|
|
Void::Testing::expect_eq(static_cast<int>(add_owner->status), 200);
|
|
// The helper reflects subsequent ownership changes.
|
|
auto updated_owners =
|
|
Package::fetch_package_owners(reg_url, "owner-pkg", Package::RegistryAuth{*alice_tok});
|
|
Void::Testing::require(updated_owners.has_value());
|
|
Void::Testing::expect(std::ranges::find(*updated_owners, std::string{"pub_alice"}) !=
|
|
updated_owners->end());
|
|
Void::Testing::expect(std::ranges::find(*updated_owners, std::string{"read_bob"}) !=
|
|
updated_owners->end());
|
|
auto add_unknown = send_loopback_http(port, "PUT", "/api/v1/packages/owner-pkg/owners/ghost",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(add_unknown.has_value() && add_unknown->status == 404);
|
|
// A reader who was added as an owner still lacks publish authority, so cannot mutate.
|
|
auto reader_remove =
|
|
send_loopback_http(port, "DELETE", "/api/v1/packages/owner-pkg/owners/pub_alice",
|
|
{{"Authorization", "Bearer " + *bob_tok}});
|
|
Void::Testing::expect(reader_remove.has_value() && reader_remove->status == 403);
|
|
auto remove_added =
|
|
send_loopback_http(port, "DELETE", "/api/v1/packages/owner-pkg/owners/read_bob",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(remove_added.has_value() && remove_added->status == 200);
|
|
// The last remaining owner cannot be removed.
|
|
auto remove_last =
|
|
send_loopback_http(port, "DELETE", "/api/v1/packages/owner-pkg/owners/pub_alice",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(remove_last.has_value() && remove_last->status == 409);
|
|
|
|
// Unauthenticated access to private package MUST fail (401)!
|
|
auto anon_priv = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg");
|
|
Void::Testing::expect(anon_priv.has_value() && anon_priv->status == 401);
|
|
auto anon_dl = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg/1.0.0/download");
|
|
Void::Testing::expect(anon_dl.has_value() && anon_dl->status == 401);
|
|
|
|
// HEAD returns the GET headers (including Content-Length) without a body.
|
|
auto head_dl = send_loopback_http(port, "HEAD", "/api/v1/packages/secret-pkg/1.0.0/download",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(head_dl.has_value() && head_dl->status == 200);
|
|
if (head_dl) {
|
|
Void::Testing::expect(head_dl->body.empty());
|
|
Void::Testing::expect(head_dl->headers.contains("content-length"));
|
|
Void::Testing::expect(head_dl->headers.at("content-length") != "0");
|
|
Void::Testing::expect(head_dl->headers.contains("x-content-sha256"));
|
|
}
|
|
|
|
// Idempotent same-bytes republish -> 200 OK!
|
|
auto idemp = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", *sha1}}, *bytes1);
|
|
Void::Testing::expect(idemp.has_value() && idemp->status == 200);
|
|
|
|
// Different bytes for SAME immutable release -> 409 Conflict!
|
|
(void)Platform::atomic_write_file(pkg_src / "extra.txt", "changed", false);
|
|
const auto tar2 = tmp / "p2.tar";
|
|
auto sha2 = Package::create_source_package(pkg_src, tar2, 0);
|
|
auto bytes2 = Void::FileSystem::read_file(tar2);
|
|
auto conflict = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", *sha2}}, *bytes2);
|
|
Void::Testing::expect(conflict.has_value() && conflict->status == 409);
|
|
|
|
// 3. Browser session login (HttpOnly cookie) + CSRF rejection without header + valid CSRF yank!
|
|
auto login = send_loopback_http(
|
|
port, "POST", "/api/v1/auth/login", {{"Content-Type", "application/json"}},
|
|
"{\"username\":\"admin\",\"password\":\"admin_secret_password\"}");
|
|
Void::Testing::expect(login.has_value() && login->status == 200);
|
|
if (!login)
|
|
return;
|
|
const auto cookie = extract_session_cookie(login->set_cookies);
|
|
const auto csrf = extract_json_str(login->body, "csrf_token");
|
|
Void::Testing::expect(!cookie.empty() && !csrf.empty());
|
|
Void::Testing::expect(login->set_cookies[0].find("HttpOnly") != std::string::npos);
|
|
Void::Testing::expect(login->set_cookies[0].find("SameSite=Strict") != std::string::npos);
|
|
|
|
// Mutation with session cookie WITHOUT X-CSRF-Token -> 403 CSRF rejected!
|
|
auto no_csrf = send_loopback_http(port, "POST", "/api/v1/packages/secret-pkg/1.0.0/yank",
|
|
{{"Cookie", cookie}}, "{\"yanked\":true}");
|
|
Void::Testing::expect(no_csrf.has_value() && no_csrf->status == 403);
|
|
|
|
// Mutation WITH valid X-CSRF-Token -> 200 OK!
|
|
auto with_csrf =
|
|
send_loopback_http(port, "POST", "/api/v1/packages/secret-pkg/1.0.0/yank",
|
|
{{"Cookie", cookie}, {"X-CSRF-Token", csrf}}, "{\"yanked\":true}");
|
|
Void::Testing::expect(with_csrf.has_value() && with_csrf->status == 200);
|
|
|
|
// Audit log contains zero secrets (no passwords or bearer tokens)!
|
|
auto audit = send_loopback_http(port, "GET", "/api/v1/audit", {{"Cookie", cookie}});
|
|
Void::Testing::expect(audit.has_value() && audit->status == 200);
|
|
if (audit) {
|
|
Void::Testing::expect(audit->body.find("admin_secret_password") == std::string::npos);
|
|
Void::Testing::expect(audit->body.find(*alice_tok) == std::string::npos);
|
|
Void::Testing::expect(audit->body.find("\"total\":") != std::string::npos);
|
|
}
|
|
auto filtered_audit = send_loopback_http(port, "GET", "/api/v1/audit?limit=1&action=package",
|
|
{{"Cookie", cookie}});
|
|
Void::Testing::expect(filtered_audit.has_value() && filtered_audit->status == 200);
|
|
if (filtered_audit) {
|
|
Void::Testing::expect(filtered_audit->body.find("\"limit\":1") != std::string::npos);
|
|
std::size_t action_occurrences = 0;
|
|
for (std::size_t pos = filtered_audit->body.find("\"action\":"); pos != std::string::npos;
|
|
pos = filtered_audit->body.find("\"action\":", pos + 1)) {
|
|
++action_occurrences;
|
|
}
|
|
Void::Testing::expect(action_occurrences == 1);
|
|
}
|
|
auto bad_audit_limit =
|
|
send_loopback_http(port, "GET", "/api/v1/audit?limit=5000", {{"Cookie", cookie}});
|
|
Void::Testing::expect(bad_audit_limit.has_value() && bad_audit_limit->status == 400);
|
|
|
|
// Package search pagination: bounded page plus total/limit/offset envelope.
|
|
auto page = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=0");
|
|
Void::Testing::expect(page.has_value() && page->status == 200);
|
|
if (page) {
|
|
Void::Testing::expect(page->body.find("\"total\":") != std::string::npos);
|
|
Void::Testing::expect(page->body.find("\"limit\":1") != std::string::npos);
|
|
std::size_t name_occurrences = 0;
|
|
for (std::size_t pos = page->body.find("\"name\":"); pos != std::string::npos;
|
|
pos = page->body.find("\"name\":", pos + 1)) {
|
|
++name_occurrences;
|
|
}
|
|
Void::Testing::expect(name_occurrences == 1);
|
|
}
|
|
|
|
const auto first_package_name = [](const std::string &body) {
|
|
const std::string key = "\"name\":\"";
|
|
const auto start = body.find(key);
|
|
if (start == std::string::npos) {
|
|
return std::string{};
|
|
}
|
|
const auto value_start = start + key.size();
|
|
const auto end = body.find('"', value_start);
|
|
return end == std::string::npos ? std::string{}
|
|
: body.substr(value_start, end - value_start);
|
|
};
|
|
const auto envelope_value = [](const std::string &body, const std::string &key) {
|
|
const std::string token = "\"" + key + "\":";
|
|
const auto start = body.find(token);
|
|
if (start == std::string::npos) {
|
|
return std::string{};
|
|
}
|
|
const auto value_start = start + token.size();
|
|
const auto end = body.find_first_of(",}", value_start);
|
|
return body.substr(value_start, end - value_start);
|
|
};
|
|
const auto count_occurrences = [](const std::string &body, const std::string &token) {
|
|
std::size_t count = 0;
|
|
for (std::size_t pos = body.find(token); pos != std::string::npos;
|
|
pos = body.find(token, pos + 1)) {
|
|
++count;
|
|
}
|
|
return count;
|
|
};
|
|
|
|
// Offset pagination moves to a different package while preserving the total.
|
|
auto page_first = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=0");
|
|
auto page_second = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=1");
|
|
Void::Testing::expect(page_first.has_value() && page_first->status == 200);
|
|
Void::Testing::expect(page_second.has_value() && page_second->status == 200);
|
|
if (page_first && page_second) {
|
|
const auto first_name = first_package_name(page_first->body);
|
|
const auto second_name = first_package_name(page_second->body);
|
|
Void::Testing::expect(!first_name.empty() && !second_name.empty());
|
|
Void::Testing::expect(first_name != second_name);
|
|
Void::Testing::expect_eq(envelope_value(page_first->body, "total"), std::string{"2"});
|
|
Void::Testing::expect_eq(envelope_value(page_first->body, "limit"), std::string{"1"});
|
|
Void::Testing::expect_eq(envelope_value(page_first->body, "offset"), std::string{"0"});
|
|
Void::Testing::expect_eq(envelope_value(page_second->body, "total"), std::string{"2"});
|
|
Void::Testing::expect_eq(envelope_value(page_second->body, "limit"), std::string{"1"});
|
|
Void::Testing::expect_eq(envelope_value(page_second->body, "offset"), std::string{"1"});
|
|
Void::Testing::expect(count_occurrences(page_first->body, "\"name\":") == 1);
|
|
Void::Testing::expect(count_occurrences(page_second->body, "\"name\":") == 1);
|
|
}
|
|
|
|
// Search filtering matches the package name...
|
|
auto name_search =
|
|
send_loopback_http(port, "GET", "/api/v1/packages?q=secret", {{"Cookie", cookie}});
|
|
Void::Testing::expect(name_search.has_value() && name_search->status == 200);
|
|
if (name_search) {
|
|
Void::Testing::expect(name_search->body.find("secret-pkg") != std::string::npos);
|
|
Void::Testing::expect(name_search->body.find("demo-pkg") == std::string::npos);
|
|
Void::Testing::expect(name_search->body.find("\"total\":") != std::string::npos);
|
|
}
|
|
auto public_name_search = send_loopback_http(port, "GET", "/api/v1/packages?q=signed");
|
|
Void::Testing::expect(public_name_search.has_value() && public_name_search->status == 200);
|
|
if (public_name_search) {
|
|
Void::Testing::expect(public_name_search->body.find("signed-pkg") != std::string::npos);
|
|
Void::Testing::expect(public_name_search->body.find("\"total\":1") != std::string::npos);
|
|
std::size_t name_occurrences = 0;
|
|
for (std::size_t pos = public_name_search->body.find("\"name\":"); pos != std::string::npos;
|
|
pos = public_name_search->body.find("\"name\":", pos + 1)) {
|
|
++name_occurrences;
|
|
}
|
|
Void::Testing::expect(name_occurrences == 1);
|
|
}
|
|
// ...and the package description.
|
|
auto description_search =
|
|
send_loopback_http(port, "GET", "/api/v1/packages?q=alert", {{"Cookie", cookie}});
|
|
Void::Testing::expect(description_search.has_value() && description_search->status == 200);
|
|
if (description_search) {
|
|
Void::Testing::expect(description_search->body.find("secret-pkg") != std::string::npos);
|
|
Void::Testing::expect(description_search->body.find("\"total\":1") != std::string::npos);
|
|
}
|
|
// A query matching neither a name nor a description yields an empty page.
|
|
auto no_match_search = send_loopback_http(port, "GET", "/api/v1/packages?q=does-not-exist");
|
|
Void::Testing::expect(no_match_search.has_value() && no_match_search->status == 200);
|
|
if (no_match_search) {
|
|
Void::Testing::expect(no_match_search->body.find("\"packages\":[]") != std::string::npos);
|
|
Void::Testing::expect(no_match_search->body.find("\"total\":0") != std::string::npos);
|
|
}
|
|
|
|
// An offset past the last package yields an empty page with the total intact.
|
|
auto far_page = send_loopback_http(port, "GET", "/api/v1/packages?offset=99");
|
|
Void::Testing::expect(far_page.has_value() && far_page->status == 200);
|
|
if (far_page) {
|
|
Void::Testing::expect(far_page->body.find("\"packages\":[]") != std::string::npos);
|
|
Void::Testing::expect_eq(envelope_value(far_page->body, "total"), std::string{"2"});
|
|
Void::Testing::expect_eq(envelope_value(far_page->body, "offset"), std::string{"99"});
|
|
}
|
|
for (const std::string bad_offset_url :
|
|
{"/api/v1/packages?offset=abc", "/api/v1/packages?offset=-1",
|
|
"/api/v1/packages?offset=1000001"}) {
|
|
auto bad_offset = send_loopback_http(port, "GET", bad_offset_url);
|
|
Void::Testing::expect(bad_offset.has_value() && bad_offset->status == 400);
|
|
if (bad_offset) {
|
|
Void::Testing::expect(bad_offset->body.find("invalid_offset") != std::string::npos);
|
|
}
|
|
}
|
|
// Admin statistics endpoint reports aggregate counts and an ETag.
|
|
auto stats = send_loopback_http(port, "GET", "/api/v1/stats", {{"Cookie", cookie}});
|
|
Void::Testing::expect(stats.has_value() && stats->status == 200);
|
|
if (stats) {
|
|
Void::Testing::expect(stats->body.find("\"packages\":") != std::string::npos);
|
|
Void::Testing::expect(stats->body.find("\"releases\":") != std::string::npos);
|
|
Void::Testing::expect(stats->body.find("\"users\":") != std::string::npos);
|
|
Void::Testing::expect(stats->headers.contains("etag"));
|
|
}
|
|
auto stats_non_admin = send_loopback_http(port, "GET", "/api/v1/stats",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(stats_non_admin.has_value() && stats_non_admin->status == 403);
|
|
|
|
auto bad_limit_text = send_loopback_http(port, "GET", "/api/v1/packages?limit=abc");
|
|
Void::Testing::expect(bad_limit_text.has_value() && bad_limit_text->status == 400);
|
|
if (bad_limit_text) {
|
|
Void::Testing::expect(bad_limit_text->body.find("invalid_limit") != std::string::npos);
|
|
}
|
|
|
|
auto bad_limit = send_loopback_http(port, "GET", "/api/v1/packages?limit=501");
|
|
Void::Testing::expect(bad_limit.has_value() && bad_limit->status == 400);
|
|
|
|
// 4. Consistent backup & restore into a brand-new registry instance preserves releases &
|
|
// download!
|
|
const auto backup_dir = tmp / "backup";
|
|
Void::Testing::expect((*svc)->backup_to(backup_dir).has_value());
|
|
(*svc)->stop_http();
|
|
|
|
RegistryConfig cfg2 = cfg;
|
|
cfg2.data_dir = tmp / "restored_data";
|
|
cfg2.bootstrap_admin_password.clear();
|
|
auto svc2 = RegistryService::open(cfg2);
|
|
Void::Testing::expect(svc2.has_value());
|
|
if (svc2) {
|
|
Void::Testing::expect((*svc2)->restore_from(backup_dir).has_value());
|
|
Void::Testing::expect((*svc2)->start_http().has_value());
|
|
auto dl = send_loopback_http((*svc2)->bound_port(), "GET",
|
|
"/api/v1/packages/secret-pkg/1.0.0/download",
|
|
{{"Authorization", "Bearer " + *alice_tok}});
|
|
Void::Testing::expect(dl.has_value() && dl->status == 200 && dl->body == *bytes1);
|
|
(*svc2)->stop_http();
|
|
}
|
|
}
|
|
|
|
// Track D1: shared HTTP content-addressed action cache blob/record round-trip across stores.
|
|
VOID_TEST(RegistryTests, shared_remote_action_cache_blob_and_record_roundtrip) {
|
|
Void::FileSystem::TempDir tmp{"vbs_remote_cas_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_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::expect((*svc)->create_user("ci_cache", "ci_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("ci_cache", "cas", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok) {
|
|
return;
|
|
}
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
|
|
State::RemoteCacheConfig remote;
|
|
remote.url = "http://127.0.0.1:" + std::to_string(port);
|
|
remote.bearer_token = *tok;
|
|
|
|
Void::FileSystem::TempDir store_tmp{"vbs_remote_store_"};
|
|
auto store = State::StateStore::open(store_tmp / ".vbs");
|
|
Void::Testing::expect(store.has_value());
|
|
if (!store) {
|
|
return;
|
|
}
|
|
store->configure_remote_cache(remote);
|
|
|
|
const auto artifact = tmp / "remote_obj.o";
|
|
(void)Platform::atomic_write_file(artifact, "REMOTE_CACHE_OBJECT_BYTES", false);
|
|
auto blob = store->store_blob_from_file(artifact);
|
|
Void::Testing::expect(blob.has_value());
|
|
if (!blob) {
|
|
return;
|
|
}
|
|
Void::Testing::expect(store->publish_remote_blob(blob->sha256).has_value());
|
|
|
|
// A fresh, empty store downloads and SHA-256 verifies the blob from the shared cache.
|
|
Void::FileSystem::TempDir store2_tmp{"vbs_remote_store2_"};
|
|
auto store2 = State::StateStore::open(store2_tmp / ".vbs");
|
|
Void::Testing::expect(store2.has_value());
|
|
if (!store2) {
|
|
return;
|
|
}
|
|
store2->configure_remote_cache(remote);
|
|
Void::Testing::expect(!store2->verify_blob(blob->sha256).value_or(true));
|
|
auto ensured = store2->ensure_remote_blob(blob->sha256);
|
|
Void::Testing::expect(ensured.has_value() && *ensured);
|
|
Void::Testing::expect(store2->verify_blob(blob->sha256).value_or(false));
|
|
|
|
// Action record round-trip by portable key.
|
|
const std::string key = Util::sha256_hex("portable-action-key");
|
|
const std::string record = "{\"schema_version\":1,\"action_key\":\"" + key + "\"}";
|
|
Void::Testing::expect(store->publish_remote_action(key, record).has_value());
|
|
auto fetched = store2->fetch_remote_action(key);
|
|
Void::Testing::expect(fetched.has_value() && fetched->has_value() && **fetched == record);
|
|
|
|
// Unauthenticated CAS reads are rejected.
|
|
auto anon = send_loopback_http(port, "GET", "/api/v1/cas/blobs/" + blob->sha256);
|
|
Void::Testing::expect(anon.has_value() && anon->status == 401);
|
|
(*svc)->stop_http();
|
|
}
|
|
|
|
// Track D1 acceptance: a cold build populates the shared CAS, then a second clean build
|
|
// directory is a 100% verified cache hit and its binary runs.
|
|
VOID_TEST(RegistryTests, shared_remote_cache_cold_populates_then_clean_build_all_hits) {
|
|
const auto vbs_bin = locate_vbs_binary();
|
|
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
|
|
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
|
|
return;
|
|
}
|
|
|
|
Void::FileSystem::TempDir tmp{"vbs_remote_accept_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_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::expect((*svc)->create_user("ci_cache", "ci_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("ci_cache", "accept", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok) {
|
|
return;
|
|
}
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string((*svc)->bound_port());
|
|
|
|
const auto proj = tmp / "proj";
|
|
(void)Platform::atomic_write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
|
void build(Void::Build::Project &p) {
|
|
p.executable("cache_app").sources({"src/main.cpp"});
|
|
}
|
|
)cpp",
|
|
false);
|
|
(void)Platform::atomic_write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n",
|
|
false);
|
|
|
|
auto run_build = [&](const std::filesystem::path &build_dir) {
|
|
Platform::ProcessRequest req;
|
|
req.executable = vbs_bin;
|
|
req.arguments = {"build", "--project", proj.string(),
|
|
"--build-dir", build_dir.string(), "--remote-cache",
|
|
reg_url, "--jobs", "4"};
|
|
req.environment.set_vars["VBS_REMOTE_CACHE_TOKEN"] = *tok;
|
|
return Platform::run_supervised(req);
|
|
};
|
|
|
|
auto first = run_build(tmp / "build_a");
|
|
Void::Testing::expect(first.has_value() && first->succeeded());
|
|
if (first) {
|
|
Void::Testing::expect(first->stdout_data.find("built (0 executed") == std::string::npos);
|
|
}
|
|
|
|
auto second = run_build(tmp / "build_b");
|
|
Void::Testing::expect(second.has_value() && second->succeeded());
|
|
if (second) {
|
|
Void::Testing::expect(second->stdout_data.find("built (0 executed") != std::string::npos);
|
|
}
|
|
|
|
Platform::ProcessRequest run_req;
|
|
run_req.executable = tmp / "build_b" / "profiles" / "debug" / "out" / "bin" / "cache_app";
|
|
auto run_res = Platform::run_supervised(run_req);
|
|
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
|
|
(*svc)->stop_http();
|
|
}
|
|
|
|
VOID_TEST(RegistryTests, binary_variant_distribution_downloads_and_verifies) {
|
|
if (!Provenance::signing_available()) {
|
|
return;
|
|
}
|
|
Void::FileSystem::TempDir tmp{"vbs_bin_dist_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
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::expect((*svc)->create_user("bin_pub", "bin_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("bin_pub", "publish", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok) {
|
|
return;
|
|
}
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
|
|
|
const auto pkg_src = tmp / "bin_pkg";
|
|
(void)Platform::atomic_write_file(pkg_src / "payload.bin", "BINARY_VARIANT_PAYLOAD", false);
|
|
const auto tar = tmp / "bin.tar";
|
|
auto sha = Package::create_source_package(pkg_src, tar, 0);
|
|
Void::Testing::require(sha.has_value());
|
|
auto bytes = Void::FileSystem::read_file(tar);
|
|
Void::Testing::require(bytes.has_value());
|
|
auto published = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/demo-bin/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *sha}}, *bytes);
|
|
Void::Testing::require(published.has_value() && published->status == 201);
|
|
|
|
const auto seed_path = tmp / "binary.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());
|
|
|
|
Package::BinaryVariantMeta variant;
|
|
variant.variant_id = "demo-bin-1.0.0-linux-x86_64";
|
|
variant.os = "Linux";
|
|
variant.architecture = "x86_64";
|
|
variant.compiler_family = "gcc";
|
|
variant.compiler_abi = "gcc-16";
|
|
variant.stdlib_abi = "libstdc++";
|
|
variant.linkage = "static";
|
|
variant.lto_mode = "off";
|
|
variant.dependency_closure_hash = "closure";
|
|
variant.sha256 = *sha;
|
|
variant.download_url = reg_url + "/api/v1/packages/demo-bin/1.0.0/download";
|
|
|
|
const std::string message =
|
|
Provenance::canonical_binary_message(variant.variant_id, variant.sha256);
|
|
auto signature = Provenance::sign_message(
|
|
std::as_bytes(std::span<const char>{message.data(), message.size()}), seed_path);
|
|
Void::Testing::require(signature.has_value());
|
|
variant.signature = *signature;
|
|
variant.public_key = *public_key;
|
|
|
|
Package::BinaryCompatibilityKey key;
|
|
key.os = variant.os;
|
|
key.architecture = variant.architecture;
|
|
key.compiler_family = variant.compiler_family;
|
|
key.compiler_abi = variant.compiler_abi;
|
|
key.stdlib_abi = variant.stdlib_abi;
|
|
key.linkage = variant.linkage;
|
|
key.lto_mode = variant.lto_mode;
|
|
key.dependency_closure_hash = variant.dependency_closure_hash;
|
|
|
|
Package::BinaryFetchOptions options{tmp / "binary_cache", {*public_key}};
|
|
auto fetched = Package::materialize_binary_variant(key, {variant}, options);
|
|
Void::Testing::require(fetched.has_value());
|
|
auto downloaded =
|
|
Void::FileSystem::read_file(tmp / "binary_cache" / "binaries" / variant.sha256);
|
|
Void::Testing::require(downloaded.has_value());
|
|
Void::Testing::expect(*downloaded == *bytes);
|
|
|
|
// Cached artifacts are reused without contacting the registry.
|
|
(*svc)->stop_http();
|
|
auto cached = Package::materialize_binary_variant(key, {variant}, options);
|
|
Void::Testing::expect(cached.has_value());
|
|
|
|
// A digest mismatch fails closed instead of materializing unverified bytes.
|
|
auto tampered = variant;
|
|
tampered.sha256 = std::string(64, '0');
|
|
auto mismatched = Package::materialize_binary_variant(key, {tampered}, options);
|
|
Void::Testing::expect(!mismatched.has_value());
|
|
}
|
|
|
|
VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materialize) {
|
|
if (!Provenance::signing_available()) {
|
|
return;
|
|
}
|
|
Void::FileSystem::TempDir tmp{"vbs_reg_binary_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
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::expect((*svc)->create_user("bin_pub", "bin_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("bin_pub", "publish", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok) {
|
|
return;
|
|
}
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
|
|
|
// The binary variant belongs to an existing source release.
|
|
const auto pkg_src = tmp / "src_pkg";
|
|
(void)Platform::atomic_write_file(pkg_src / "payload.txt", "SOURCE_PAYLOAD", false);
|
|
const auto tar = tmp / "src.tar";
|
|
auto source_sha = Package::create_source_package(pkg_src, tar, 0);
|
|
Void::Testing::require(source_sha.has_value());
|
|
auto source_bytes = Void::FileSystem::read_file(tar);
|
|
Void::Testing::require(source_bytes.has_value());
|
|
auto src_pub = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/demo-bin/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *source_sha}}, *source_bytes);
|
|
Void::Testing::require(src_pub.has_value() && src_pub->status == 201);
|
|
|
|
const std::string artifact = "PREBUILT_BINARY_VARIANT_BYTES";
|
|
const std::string artifact_sha = Util::sha256_hex(artifact);
|
|
const std::string variant_id = "linux-x86_64-gcc16-static";
|
|
const std::string binary_path = "/api/v1/packages/demo-bin/1.0.0/binaries/" + variant_id;
|
|
|
|
auto unauthorized = send_loopback_http(port, "PUT", binary_path,
|
|
{{"X-Content-SHA256", artifact_sha}}, artifact);
|
|
Void::Testing::expect(unauthorized.has_value() && unauthorized->status == 401);
|
|
|
|
const auto seed_path = tmp / "binary.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());
|
|
const std::string message = Provenance::canonical_binary_message(variant_id, artifact_sha);
|
|
auto signature = Provenance::sign_message(
|
|
std::as_bytes(std::span<const char>{message.data(), message.size()}), seed_path);
|
|
Void::Testing::require(signature.has_value());
|
|
|
|
auto bad_signature = send_loopback_http(port, "PUT", binary_path,
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", artifact_sha},
|
|
{"X-Binary-Signature", std::string(127, 'a')},
|
|
{"X-Binary-Public-Key", *public_key}},
|
|
artifact);
|
|
Void::Testing::expect(bad_signature.has_value() && bad_signature->status == 400);
|
|
|
|
auto published = send_loopback_http(port, "PUT", binary_path,
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", artifact_sha},
|
|
{"X-Binary-Signature", *signature},
|
|
{"X-Binary-Public-Key", *public_key}},
|
|
artifact);
|
|
Void::Testing::expect(published.has_value() && published->status == 201);
|
|
|
|
auto detail = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin");
|
|
Void::Testing::expect(detail.has_value() && detail->status == 200);
|
|
if (detail) {
|
|
Void::Testing::expect(detail->body.find(variant_id) != std::string::npos);
|
|
Void::Testing::expect(detail->body.find(artifact_sha) != std::string::npos);
|
|
}
|
|
|
|
auto release_detail = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin/1.0.0");
|
|
Void::Testing::expect(release_detail.has_value() && release_detail->status == 200);
|
|
if (release_detail) {
|
|
Void::Testing::expect(release_detail->body.find("\"version\":\"1.0.0\"") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(release_detail->body.find(variant_id) != std::string::npos);
|
|
}
|
|
auto missing_release = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin/9.9.9");
|
|
Void::Testing::expect(missing_release.has_value() && missing_release->status == 404);
|
|
|
|
// Conditional requests: the ETag of a read response enables a bodyless 304.
|
|
if (release_detail) {
|
|
const auto etag_it = release_detail->headers.find("etag");
|
|
Void::Testing::expect(etag_it != release_detail->headers.end());
|
|
if (etag_it != release_detail->headers.end()) {
|
|
auto not_modified = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin/1.0.0",
|
|
{{"If-None-Match", etag_it->second}});
|
|
Void::Testing::expect(not_modified.has_value() && not_modified->status == 304);
|
|
if (not_modified) {
|
|
Void::Testing::expect(not_modified->body.empty());
|
|
}
|
|
}
|
|
}
|
|
if (missing_release) {
|
|
Void::Testing::expect(missing_release->body.find("release not found") != std::string::npos);
|
|
}
|
|
auto missing_package = send_loopback_http(port, "GET", "/api/v1/packages/no-such-pkg/1.0.0");
|
|
Void::Testing::expect(missing_package.has_value() && missing_package->status == 404);
|
|
if (missing_package) {
|
|
Void::Testing::expect(missing_package->body.find("package not found") != std::string::npos);
|
|
}
|
|
|
|
auto listed = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin/1.0.0/binaries");
|
|
Void::Testing::expect(listed.has_value() && listed->status == 200);
|
|
if (listed) {
|
|
Void::Testing::expect(listed->body.find(variant_id) != std::string::npos);
|
|
Void::Testing::expect(listed->body.find("\"yanked\":false") != std::string::npos);
|
|
}
|
|
|
|
auto binary_detail = send_loopback_http(port, "GET", binary_path);
|
|
Void::Testing::expect(binary_detail.has_value() && binary_detail->status == 200);
|
|
if (binary_detail) {
|
|
Void::Testing::expect(binary_detail->body.find("\"variant_id\":\"" + variant_id + "\"") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(binary_detail->body.find("\"signature\":\"" + *signature + "\"") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(binary_detail->body.find("\"download_url\":") != std::string::npos);
|
|
}
|
|
auto missing_binary = send_loopback_http(port, "GET", binary_path + "-missing");
|
|
Void::Testing::expect(missing_binary.has_value() && missing_binary->status == 404);
|
|
|
|
auto downloaded = send_loopback_http(port, "GET", binary_path + "/download");
|
|
Void::Testing::expect(downloaded.has_value() && downloaded->status == 200);
|
|
if (downloaded) {
|
|
Void::Testing::expect(downloaded->body == artifact);
|
|
}
|
|
auto etag_head = send_loopback_http(port, "GET", binary_path + "/download");
|
|
Void::Testing::expect(etag_head.has_value() && etag_head->status == 200);
|
|
if (etag_head) {
|
|
const auto etag_it = etag_head->headers.find("etag");
|
|
Void::Testing::expect(etag_it != etag_head->headers.end());
|
|
if (etag_it != etag_head->headers.end()) {
|
|
auto cached = send_loopback_http(port, "GET", binary_path + "/download",
|
|
{{"If-None-Match", etag_it->second}});
|
|
Void::Testing::expect(cached.has_value() && cached->status == 304);
|
|
if (cached) {
|
|
Void::Testing::expect(cached->body.empty());
|
|
}
|
|
}
|
|
}
|
|
auto ranged =
|
|
send_loopback_http(port, "GET", binary_path + "/download", {{"Range", "bytes=0-3"}});
|
|
Void::Testing::expect(ranged.has_value() && ranged->status == 206);
|
|
if (ranged) {
|
|
Void::Testing::expect_eq(ranged->body, artifact.substr(0, 4));
|
|
Void::Testing::expect(
|
|
ranged->headers.at("content-range").find("/" + std::to_string(artifact.size())) !=
|
|
std::string::npos);
|
|
}
|
|
auto unsatisfiable =
|
|
send_loopback_http(port, "GET", binary_path + "/download", {{"Range", "bytes=999999-"}});
|
|
Void::Testing::expect(unsatisfiable.has_value() && unsatisfiable->status == 416);
|
|
auto head_binary = send_loopback_http(port, "HEAD", binary_path + "/download");
|
|
Void::Testing::expect(head_binary.has_value() && head_binary->status == 200);
|
|
if (head_binary) {
|
|
Void::Testing::expect(head_binary->body.empty());
|
|
Void::Testing::expect_eq(head_binary->headers.at("content-length"),
|
|
std::to_string(artifact.size()));
|
|
}
|
|
|
|
auto conflict = send_loopback_http(
|
|
port, "PUT", binary_path,
|
|
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", Util::sha256_hex("different")}},
|
|
"different");
|
|
Void::Testing::expect(conflict.has_value() && conflict->status == 409);
|
|
|
|
// Binary yank requires authentication (bearer tokens are not CSRF-exempt).
|
|
auto bin_yank =
|
|
send_loopback_http(port, "POST", binary_path + "/yank", {}, "{\"yanked\":true}");
|
|
Void::Testing::expect(bin_yank.has_value() && bin_yank->status == 401);
|
|
|
|
// The registry-served artifact materializes through the signed binary-variant path.
|
|
Package::BinaryVariantMeta variant;
|
|
variant.variant_id = variant_id;
|
|
variant.os = "Linux";
|
|
variant.architecture = "x86_64";
|
|
variant.compiler_family = "gcc";
|
|
variant.compiler_abi = "gcc-16";
|
|
variant.stdlib_abi = "libstdc++";
|
|
variant.linkage = "static";
|
|
variant.lto_mode = "off";
|
|
variant.dependency_closure_hash = "closure";
|
|
variant.sha256 = artifact_sha;
|
|
variant.download_url = reg_url + binary_path + "/download";
|
|
variant.signature = *signature;
|
|
variant.public_key = *public_key;
|
|
|
|
Package::BinaryCompatibilityKey key;
|
|
key.os = variant.os;
|
|
key.architecture = variant.architecture;
|
|
key.compiler_family = variant.compiler_family;
|
|
key.compiler_abi = variant.compiler_abi;
|
|
key.stdlib_abi = variant.stdlib_abi;
|
|
key.linkage = variant.linkage;
|
|
key.lto_mode = variant.lto_mode;
|
|
key.dependency_closure_hash = variant.dependency_closure_hash;
|
|
|
|
Package::BinaryFetchOptions options{tmp / "binary_cache", {*public_key}};
|
|
auto materialized = Package::materialize_binary_variant(key, {variant}, options);
|
|
Void::Testing::require(materialized.has_value());
|
|
auto cached = Void::FileSystem::read_file(tmp / "binary_cache" / "binaries" / artifact_sha);
|
|
Void::Testing::require(cached.has_value());
|
|
Void::Testing::expect(*cached == artifact);
|
|
|
|
// Client API: publish a signed variant and list it back.
|
|
const auto client_artifact = tmp / "client-artifact.bin";
|
|
(void)Platform::atomic_write_file(client_artifact, "CLIENT_BINARY_ARTIFACT", false);
|
|
Package::BinaryPublishOptions binary_publish;
|
|
binary_publish.registry_url = reg_url;
|
|
binary_publish.package_name = "demo-bin";
|
|
binary_publish.version = "1.0.0";
|
|
binary_publish.variant_id = "client-variant";
|
|
binary_publish.artifact_path = client_artifact;
|
|
binary_publish.signing_seed_path = seed_path;
|
|
binary_publish.auth = Package::RegistryAuth{*tok};
|
|
auto client_sha = Package::publish_binary_variant(binary_publish);
|
|
Void::Testing::require(client_sha.has_value());
|
|
|
|
auto variants =
|
|
Package::fetch_binary_variants(reg_url, "demo-bin", "1.0.0", Package::RegistryAuth{*tok});
|
|
Void::Testing::require(variants.has_value());
|
|
bool found_client_variant = false;
|
|
for (const auto &info : *variants) {
|
|
if (info.variant_id == "client-variant") {
|
|
found_client_variant = true;
|
|
Void::Testing::expect(info.sha256 == *client_sha);
|
|
Void::Testing::expect(info.signature.has_value());
|
|
Void::Testing::expect(info.public_key.has_value());
|
|
}
|
|
}
|
|
Void::Testing::expect(found_client_variant);
|
|
|
|
// Authenticated session + CSRF allows yanking the variant; the detail JSON reflects it.
|
|
auto yank_login = send_loopback_http(port, "POST", "/api/v1/auth/login",
|
|
{{"Content-Type", "application/json"}},
|
|
"{\"username\":\"admin\",\"password\":\"admin_pw\"}");
|
|
Void::Testing::require(yank_login.has_value() && yank_login->status == 200);
|
|
const auto yank_cookie = extract_session_cookie(yank_login->set_cookies);
|
|
const auto yank_csrf = extract_json_str(yank_login->body, "csrf_token");
|
|
Void::Testing::expect(!yank_cookie.empty() && !yank_csrf.empty());
|
|
auto session_yank = send_loopback_http(port, "POST", binary_path + "/yank",
|
|
{{"Cookie", yank_cookie}, {"X-CSRF-Token", yank_csrf}},
|
|
"{\"yanked\":true}");
|
|
Void::Testing::expect(session_yank.has_value() && session_yank->status == 200);
|
|
auto after_yank = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin",
|
|
{{"Authorization", "Bearer " + *tok}});
|
|
Void::Testing::expect(after_yank.has_value() && after_yank->status == 200);
|
|
if (after_yank) {
|
|
const auto variant_pos = after_yank->body.find(variant_id);
|
|
Void::Testing::expect(variant_pos != std::string::npos);
|
|
if (variant_pos != std::string::npos) {
|
|
Void::Testing::expect(after_yank->body.find("\"yanked\":true", variant_pos) !=
|
|
std::string::npos);
|
|
}
|
|
}
|
|
auto variants_after_yank =
|
|
Package::fetch_binary_variants(reg_url, "demo-bin", "1.0.0", Package::RegistryAuth{*tok});
|
|
Void::Testing::require(variants_after_yank.has_value());
|
|
Void::Testing::expect(std::ranges::none_of(
|
|
*variants_after_yank, [&](const auto &info) { return info.variant_id == variant_id; }));
|
|
auto variants_with_yanked = Package::fetch_binary_variants(reg_url, "demo-bin", "1.0.0",
|
|
Package::RegistryAuth{*tok}, true);
|
|
Void::Testing::require(variants_with_yanked.has_value());
|
|
bool saw_yanked = false;
|
|
for (const auto &info : *variants_with_yanked) {
|
|
if (info.variant_id == variant_id) {
|
|
saw_yanked = true;
|
|
Void::Testing::expect(info.yanked);
|
|
}
|
|
}
|
|
Void::Testing::expect(saw_yanked);
|
|
|
|
(*svc)->stop_http();
|
|
}
|
|
|
|
VOID_TEST(RegistryTests, private_binary_variant_download_requires_auth) {
|
|
if (!Provenance::signing_available()) {
|
|
return;
|
|
}
|
|
Void::FileSystem::TempDir tmp{"vbs_priv_binary_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
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::expect(
|
|
(*svc)->create_user("priv_pub", "priv_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("priv_pub", "publish", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok) {
|
|
return;
|
|
}
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
|
|
|
const auto pkg_src = tmp / "priv_pkg";
|
|
(void)Platform::atomic_write_file(pkg_src / "payload.txt", "PRIVATE_SOURCE", false);
|
|
const auto tar = tmp / "priv.tar";
|
|
auto source_sha = Package::create_source_package(pkg_src, tar, 0);
|
|
Void::Testing::require(source_sha.has_value());
|
|
auto source_bytes = Void::FileSystem::read_file(tar);
|
|
Void::Testing::require(source_bytes.has_value());
|
|
auto src_pub = send_loopback_http(port, "PUT", "/api/v1/packages/priv-bin/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", *source_sha},
|
|
{"X-Package-Private", "true"}},
|
|
*source_bytes);
|
|
Void::Testing::require(src_pub.has_value() && src_pub->status == 201);
|
|
|
|
const std::string artifact = "PRIVATE_BINARY_BYTES";
|
|
const std::string artifact_sha = Util::sha256_hex(artifact);
|
|
const std::string variant_id = "private-variant";
|
|
const std::string binary_path = "/api/v1/packages/priv-bin/1.0.0/binaries/" + variant_id;
|
|
const auto seed_path = tmp / "private.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());
|
|
const std::string message = Provenance::canonical_binary_message(variant_id, artifact_sha);
|
|
auto signature = Provenance::sign_message(
|
|
std::as_bytes(std::span<const char>{message.data(), message.size()}), seed_path);
|
|
Void::Testing::require(signature.has_value());
|
|
auto bin_pub = send_loopback_http(port, "PUT", binary_path,
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", artifact_sha},
|
|
{"X-Binary-Signature", *signature},
|
|
{"X-Binary-Public-Key", *public_key}},
|
|
artifact);
|
|
Void::Testing::require(bin_pub.has_value() && bin_pub->status == 201);
|
|
|
|
const std::string download_url = reg_url + binary_path + "/download";
|
|
auto anonymous = send_loopback_http(port, "GET", binary_path + "/download");
|
|
Void::Testing::expect(anonymous.has_value() && anonymous->status == 401);
|
|
|
|
const auto dest = tmp / "private-binary.bin";
|
|
auto downloaded = Package::download_binary_artifact(download_url, artifact_sha, dest,
|
|
Package::RegistryAuth{*tok});
|
|
Void::Testing::require(downloaded.has_value());
|
|
auto bytes = Void::FileSystem::read_file(dest);
|
|
Void::Testing::require(bytes.has_value());
|
|
Void::Testing::expect(*bytes == artifact);
|
|
|
|
Package::BinaryVariantMeta variant;
|
|
variant.variant_id = variant_id;
|
|
variant.os = "Linux";
|
|
variant.architecture = "x86_64";
|
|
variant.compiler_family = "gcc";
|
|
variant.compiler_abi = "gcc-16";
|
|
variant.stdlib_abi = "libstdc++";
|
|
variant.linkage = "static";
|
|
variant.lto_mode = "off";
|
|
variant.dependency_closure_hash = "closure";
|
|
variant.sha256 = artifact_sha;
|
|
variant.download_url = download_url;
|
|
variant.signature = *signature;
|
|
variant.public_key = *public_key;
|
|
|
|
Package::BinaryCompatibilityKey key;
|
|
key.os = variant.os;
|
|
key.architecture = variant.architecture;
|
|
key.compiler_family = variant.compiler_family;
|
|
key.compiler_abi = variant.compiler_abi;
|
|
key.stdlib_abi = variant.stdlib_abi;
|
|
key.linkage = variant.linkage;
|
|
key.lto_mode = variant.lto_mode;
|
|
key.dependency_closure_hash = variant.dependency_closure_hash;
|
|
|
|
Package::BinaryFetchOptions options{tmp / "private_cache", {*public_key}, *tok};
|
|
auto materialized = Package::materialize_binary_variant(key, {variant}, options);
|
|
Void::Testing::require(materialized.has_value());
|
|
auto cached = Void::FileSystem::read_file(tmp / "private_cache" / "binaries" / artifact_sha);
|
|
Void::Testing::require(cached.has_value());
|
|
Void::Testing::expect(*cached == artifact);
|
|
|
|
(*svc)->stop_http();
|
|
}
|
|
|
|
// End-to-end live client <-> server test: `vbs publish` -> `vbs deps resolve` -> `vbs build
|
|
// --locked`!
|
|
VOID_TEST(RegistryTests, cli_publish_deps_resolve_and_locked_build_against_live_registry) {
|
|
const auto vbs_bin = locate_vbs_binary();
|
|
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
|
|
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
|
|
return;
|
|
}
|
|
|
|
Void::FileSystem::TempDir tmp{"vbs_reg_e2e_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "reg_data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
cfg.bind_address = "127.0.0.1";
|
|
cfg.port = 0;
|
|
cfg.bootstrap_admin_user = "admin";
|
|
cfg.bootstrap_admin_password = "admin_e2e_password";
|
|
|
|
auto svc = RegistryService::open(cfg);
|
|
Void::Testing::expect(svc.has_value());
|
|
if (!svc)
|
|
return;
|
|
Void::Testing::expect((*svc)->create_user("ci_pub", "ci_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("ci_pub", "publish", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok)
|
|
return;
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string((*svc)->bound_port());
|
|
|
|
// 1. Create a real CMake library package and publish 1.0.0 and 1.1.0 via `vbs publish` CLI!
|
|
const auto pkg_dir = tmp / "hello_pkg";
|
|
(void)Platform::atomic_write_file(pkg_dir / "CMakeLists.txt", R"cmake(
|
|
cmake_minimum_required(VERSION 3.20)
|
|
project(hello_pkg LANGUAGES CXX)
|
|
add_library(hello_pkg STATIC src/hello.cpp)
|
|
target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
)cmake",
|
|
false);
|
|
(void)Platform::atomic_write_file(pkg_dir / "include" / "hello_pkg.hpp",
|
|
"#pragma once\nint hello_pkg_value();\n", false);
|
|
(void)Platform::atomic_write_file(
|
|
pkg_dir / "src" / "hello.cpp",
|
|
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 10; }\n", false);
|
|
|
|
Platform::ProcessRequest pub1;
|
|
pub1.executable = vbs_bin;
|
|
pub1.arguments = {"publish", "--project", pkg_dir.string(), "--registry",
|
|
reg_url, "--name", "hello-pkg", "--version",
|
|
"1.0.0", "--description", "Live E2E package"};
|
|
pub1.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto r1 = Platform::run_supervised(pub1);
|
|
Void::Testing::expect(r1.has_value() && r1->succeeded());
|
|
|
|
// Publish 1.1.0 returning 42 so solver (^1.0) selects 1.1.0!
|
|
(void)Platform::atomic_write_file(
|
|
pkg_dir / "src" / "hello.cpp",
|
|
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 42; }\n", false);
|
|
Platform::ProcessRequest pub2 = pub1;
|
|
pub2.arguments[8] = "1.1.0";
|
|
auto r2 = Platform::run_supervised(pub2);
|
|
Void::Testing::expect(r2.has_value() && r2->succeeded());
|
|
|
|
// 1b. Binary variant CLI: publish, list, and fetch the artifact.
|
|
const auto binary_artifact = tmp / "binary_artifact.bin";
|
|
(void)Platform::atomic_write_file(binary_artifact, "CLI_BINARY_VARIANT_BYTES", false);
|
|
Platform::ProcessRequest bin_pub;
|
|
bin_pub.executable = vbs_bin;
|
|
bin_pub.arguments = {"publish-binary",
|
|
"--registry",
|
|
reg_url,
|
|
"--name",
|
|
"hello-pkg",
|
|
"--version",
|
|
"1.1.0",
|
|
"--variant",
|
|
"cli-variant",
|
|
"--file",
|
|
binary_artifact.string()};
|
|
bin_pub.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto bin_pub_res = Platform::run_supervised(bin_pub);
|
|
Void::Testing::expect(bin_pub_res.has_value() && bin_pub_res->succeeded());
|
|
|
|
Platform::ProcessRequest bin_list;
|
|
bin_list.executable = vbs_bin;
|
|
bin_list.arguments = {"binaries", "list", "--registry", reg_url,
|
|
"--name", "hello-pkg", "--version", "1.1.0"};
|
|
bin_list.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto bin_list_res = Platform::run_supervised(bin_list);
|
|
Void::Testing::expect(bin_list_res.has_value() && bin_list_res->succeeded());
|
|
if (bin_list_res) {
|
|
Void::Testing::expect(bin_list_res->stdout_data.find("cli-variant") != std::string::npos);
|
|
Void::Testing::expect(bin_list_res->stdout_data.find("unsigned") != std::string::npos);
|
|
}
|
|
|
|
const auto fetched_artifact = tmp / "fetched_binary.bin";
|
|
Platform::ProcessRequest bin_fetch;
|
|
bin_fetch.executable = vbs_bin;
|
|
bin_fetch.arguments = {"binaries", "fetch", "--registry", reg_url,
|
|
"--name", "hello-pkg", "--version", "1.1.0",
|
|
"--variant", "cli-variant", "--output", fetched_artifact.string()};
|
|
bin_fetch.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto bin_fetch_res = Platform::run_supervised(bin_fetch);
|
|
Void::Testing::expect(bin_fetch_res.has_value() && bin_fetch_res->succeeded());
|
|
auto fetched_bytes = Void::FileSystem::read_file(fetched_artifact);
|
|
Void::Testing::require(fetched_bytes.has_value());
|
|
Void::Testing::expect(*fetched_bytes == "CLI_BINARY_VARIANT_BYTES");
|
|
|
|
// An unsigned variant cannot satisfy a trusted-key requirement.
|
|
Platform::ProcessRequest trusted_fetch;
|
|
trusted_fetch.executable = vbs_bin;
|
|
trusted_fetch.arguments = {"binaries",
|
|
"fetch",
|
|
"--registry",
|
|
reg_url,
|
|
"--name",
|
|
"hello-pkg",
|
|
"--version",
|
|
"1.1.0",
|
|
"--variant",
|
|
"cli-variant",
|
|
"--output",
|
|
(tmp / "trusted_binary.bin").string(),
|
|
"--trusted-public-key",
|
|
std::string(64, 'a')};
|
|
trusted_fetch.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto trusted_binary_res = Platform::run_supervised(trusted_fetch);
|
|
Void::Testing::expect(trusted_binary_res.has_value() && !trusted_binary_res->succeeded());
|
|
|
|
Platform::ProcessRequest tokens_list;
|
|
tokens_list.executable = vbs_bin;
|
|
tokens_list.arguments = {"tokens", "list", "--registry", reg_url};
|
|
tokens_list.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto tokens_res = Platform::run_supervised(tokens_list);
|
|
Void::Testing::expect(tokens_res.has_value() && tokens_res->succeeded());
|
|
if (tokens_res) {
|
|
Void::Testing::expect(tokens_res->stdout_data.find("ci_pub") != std::string::npos);
|
|
Void::Testing::expect(tokens_res->stdout_data.find("active") != std::string::npos);
|
|
// The plaintext secret must never be listed.
|
|
Void::Testing::expect(tokens_res->stdout_data.find(*tok) == std::string::npos);
|
|
}
|
|
|
|
Platform::ProcessRequest releases_list;
|
|
releases_list.executable = vbs_bin;
|
|
releases_list.arguments = {"releases", "list", "--registry", reg_url, "--name", "hello-pkg"};
|
|
releases_list.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto releases_res = Platform::run_supervised(releases_list);
|
|
Void::Testing::expect(releases_res.has_value() && releases_res->succeeded());
|
|
if (releases_res) {
|
|
Void::Testing::expect(releases_res->stdout_data.find("1.0.0") != std::string::npos);
|
|
Void::Testing::expect(releases_res->stdout_data.find("1.1.0") != std::string::npos);
|
|
Void::Testing::expect(releases_res->stdout_data.find("active") != std::string::npos);
|
|
}
|
|
|
|
// `vbs releases show` prints the release detail fetched from the live registry.
|
|
std::string release_sha;
|
|
if (r2) {
|
|
const auto sha_pos = r2->stdout_data.find("sha256=");
|
|
if (sha_pos != std::string::npos) {
|
|
release_sha = r2->stdout_data.substr(sha_pos + 7, 64);
|
|
}
|
|
}
|
|
Void::Testing::expect(!release_sha.empty());
|
|
|
|
Platform::ProcessRequest releases_show;
|
|
releases_show.executable = vbs_bin;
|
|
releases_show.arguments = {"releases", "show", "--registry", reg_url,
|
|
"--name", "hello-pkg", "--version", "1.1.0"};
|
|
releases_show.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto releases_show_res = Platform::run_supervised(releases_show);
|
|
Void::Testing::expect(releases_show_res.has_value() && releases_show_res->succeeded());
|
|
if (releases_show_res) {
|
|
Void::Testing::expect(releases_show_res->stdout_data.find("version=1.1.0") !=
|
|
std::string::npos);
|
|
if (!release_sha.empty()) {
|
|
Void::Testing::expect(releases_show_res->stdout_data.find("sha256=" + release_sha) !=
|
|
std::string::npos);
|
|
}
|
|
Void::Testing::expect(releases_show_res->stdout_data.find("binaries=") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
// An unknown release version fails instead of printing a bogus detail line.
|
|
Platform::ProcessRequest releases_show_missing = releases_show;
|
|
releases_show_missing.arguments.back() = "9.9.9";
|
|
auto releases_show_missing_res = Platform::run_supervised(releases_show_missing);
|
|
Void::Testing::expect(releases_show_missing_res.has_value() &&
|
|
!releases_show_missing_res->succeeded());
|
|
|
|
// 2. Create a consumer project declaring `.package("hello-pkg", "^1.0").registry(reg_url)`.
|
|
const auto cons_dir = tmp / "consumer";
|
|
const auto cons_build = tmp / "consumer_build";
|
|
(void)Platform::atomic_write_file(cons_dir / "build.cpp",
|
|
"#include <Void/Build.hpp>\n"
|
|
"void build(Void::Build::Project &p) {\n"
|
|
" auto dep = p.dependency(\"hello\")\n"
|
|
" .package(\"hello-pkg\", \"^1.0\")\n"
|
|
" .registry(\"" +
|
|
reg_url +
|
|
"\");\n"
|
|
" p.executable(\"reg_consumer\")\n"
|
|
" .sources({\"src/main.cpp\"})\n"
|
|
" .link(dep.target(\"hello_pkg\"));\n"
|
|
"}\n",
|
|
false);
|
|
(void)Platform::atomic_write_file(
|
|
cons_dir / "src" / "main.cpp",
|
|
"#include \"hello_pkg.hpp\"\nint main() { return hello_pkg_value() == 42 ? 0 : 1; }\n",
|
|
false);
|
|
|
|
// 3. Resolve dependencies into vbs.lock against the live registry!
|
|
Platform::ProcessRequest deps_req;
|
|
deps_req.executable = vbs_bin;
|
|
deps_req.arguments = {"deps", "resolve", "--project", cons_dir.string(),
|
|
"--build-dir", cons_build.string()};
|
|
deps_req.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
|
auto deps_res = Platform::run_supervised(deps_req);
|
|
Void::Testing::expect(deps_res.has_value() && deps_res->succeeded());
|
|
|
|
auto lock_text = Void::FileSystem::read_file(cons_dir / "vbs.lock");
|
|
Void::Testing::expect(lock_text.has_value());
|
|
if (lock_text) {
|
|
Void::Testing::expect(lock_text->find("\"version\":\"1.1.0\"") != std::string::npos);
|
|
Void::Testing::expect(lock_text->find("\"source_kind\":\"package\"") != std::string::npos);
|
|
Void::Testing::expect(lock_text->find(*tok) == std::string::npos); // Zero token leaks!
|
|
}
|
|
|
|
// 4. Build in --locked mode and execute the consumer binary!
|
|
Platform::ProcessRequest bld_req;
|
|
bld_req.executable = vbs_bin;
|
|
bld_req.arguments = {"build", "--project", cons_dir.string(),
|
|
"--build-dir", cons_build.string(), "--locked"};
|
|
auto bld_res = Platform::run_supervised(bld_req);
|
|
Void::Testing::expect(bld_res.has_value() && bld_res->succeeded());
|
|
|
|
Platform::ProcessRequest run_req;
|
|
run_req.executable = cons_build / "profiles" / "debug" / "out" / "bin" / "reg_consumer";
|
|
auto run_res = Platform::run_supervised(run_req);
|
|
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
|
|
|
|
// 5. Requiring a trusted key must fail closed for the unsigned locked package.
|
|
Platform::ProcessRequest trusted_req = bld_req;
|
|
trusted_req.arguments.push_back("--trusted-public-key");
|
|
trusted_req.arguments.push_back(std::string(64, 'a'));
|
|
auto trusted_res = Platform::run_supervised(trusted_req);
|
|
Void::Testing::expect(trusted_res.has_value() && !trusted_res->succeeded());
|
|
if (trusted_res) {
|
|
Void::Testing::expect(trusted_res->stderr_data.find("not signed by a trusted key") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
// 6. With the OpenSSL backend, publish a signed release and require its trusted key.
|
|
if (Provenance::signing_available()) {
|
|
const auto seed_path = tmp / "publish.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());
|
|
|
|
(void)Platform::atomic_write_file(
|
|
pkg_dir / "src" / "hello.cpp",
|
|
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 7; }\n", false);
|
|
Platform::ProcessRequest pub3 = pub1;
|
|
pub3.arguments[8] = "1.2.0";
|
|
pub3.arguments.push_back("--signing-key");
|
|
pub3.arguments.push_back(seed_path.string());
|
|
auto r3 = Platform::run_supervised(pub3);
|
|
Void::Testing::expect(r3.has_value() && r3->succeeded());
|
|
|
|
Platform::ProcessRequest update_req = deps_req;
|
|
update_req.arguments[1] = "update";
|
|
auto update_res = Platform::run_supervised(update_req);
|
|
Void::Testing::expect(update_res.has_value() && update_res->succeeded());
|
|
|
|
Platform::ProcessRequest signed_build = bld_req;
|
|
signed_build.arguments.push_back("--trusted-public-key");
|
|
signed_build.arguments.push_back(*public_key);
|
|
auto signed_res = Platform::run_supervised(signed_build);
|
|
Void::Testing::expect(signed_res.has_value() && signed_res->succeeded());
|
|
|
|
Platform::ProcessRequest wrong_key_build = bld_req;
|
|
wrong_key_build.arguments.push_back("--trusted-public-key");
|
|
wrong_key_build.arguments.push_back(std::string(64, 'a'));
|
|
auto wrong_key_res = Platform::run_supervised(wrong_key_build);
|
|
Void::Testing::expect(wrong_key_res.has_value() && !wrong_key_res->succeeded());
|
|
}
|
|
|
|
(*svc)->stop_http();
|
|
}
|
|
|
|
VOID_TEST(RegistryTests, registry_release_detail_fields_signature_404_and_private_auth) {
|
|
Void::FileSystem::TempDir tmp{"vbs_release_detail_"};
|
|
RegistryConfig cfg;
|
|
cfg.data_dir = tmp / "data";
|
|
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
|
cfg.bind_address = "127.0.0.1";
|
|
cfg.port = 0;
|
|
cfg.bootstrap_admin_user = "admin";
|
|
cfg.bootstrap_admin_password = "admin_secret_password";
|
|
|
|
auto svc = RegistryService::open(cfg);
|
|
Void::Testing::expect(svc.has_value());
|
|
if (!svc)
|
|
return;
|
|
|
|
Void::Testing::expect(
|
|
(*svc)->create_user("detail_pub", "detail_pass", Role::Publisher).has_value());
|
|
auto tok = (*svc)->create_token("detail_pub", "detail", {"read", "publish"});
|
|
Void::Testing::expect(tok.has_value());
|
|
if (!tok)
|
|
return;
|
|
|
|
Void::Testing::expect((*svc)->start_http().has_value());
|
|
const auto port = (*svc)->bound_port();
|
|
Void::Testing::expect(port > 0);
|
|
|
|
const auto pkg_src = tmp / "detail_pkg";
|
|
(void)Platform::atomic_write_file(pkg_src / "payload.txt", "RELEASE_DETAIL_PAYLOAD", false);
|
|
const auto tar = tmp / "detail.tar";
|
|
auto sha = Package::create_source_package(pkg_src, tar, 0);
|
|
Void::Testing::require(sha.has_value());
|
|
auto bytes = Void::FileSystem::read_file(tar);
|
|
Void::Testing::require(bytes.has_value());
|
|
auto published = send_loopback_http(
|
|
port, "PUT", "/api/v1/packages/detail-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *sha}}, *bytes);
|
|
Void::Testing::require(published.has_value() && published->status == 201);
|
|
|
|
// Release detail serves the immutable release record and its binary summaries.
|
|
auto detail = send_loopback_http(port, "GET", "/api/v1/packages/detail-pkg/1.0.0");
|
|
Void::Testing::expect(detail.has_value() && detail->status == 200);
|
|
if (detail) {
|
|
Void::Testing::expect_eq(extract_json_str(detail->body, "name"), std::string{"detail-pkg"});
|
|
Void::Testing::expect_eq(extract_json_str(detail->body, "version"), std::string{"1.0.0"});
|
|
Void::Testing::expect_eq(extract_json_str(detail->body, "sha256"), *sha);
|
|
Void::Testing::expect_eq(extract_json_str(detail->body, "publisher"),
|
|
std::string{"detail_pub"});
|
|
const auto size_bytes = extract_json_int(detail->body, "size_bytes");
|
|
Void::Testing::require(size_bytes.has_value());
|
|
Void::Testing::expect_eq(*size_bytes, static_cast<std::int64_t>(bytes->size()));
|
|
const auto published_epoch = extract_json_int(detail->body, "published_epoch");
|
|
Void::Testing::require(published_epoch.has_value());
|
|
Void::Testing::expect(*published_epoch > 0);
|
|
const auto yanked = extract_json_bool(detail->body, "yanked");
|
|
Void::Testing::require(yanked.has_value());
|
|
Void::Testing::expect(!*yanked);
|
|
Void::Testing::expect(detail->body.find("\"binaries\":[]") != std::string::npos);
|
|
// An unsigned release omits the signature metadata keys entirely.
|
|
Void::Testing::expect(detail->body.find("\"signature\"") == std::string::npos);
|
|
Void::Testing::expect(detail->body.find("\"public_key\"") == std::string::npos);
|
|
}
|
|
|
|
// The RegistryClient helper parses the same payload and maps a missing release to not_found.
|
|
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
|
auto client_detail =
|
|
Package::fetch_release_detail(reg_url, "detail-pkg", "1.0.0", Package::RegistryAuth{*tok});
|
|
Void::Testing::require(client_detail.has_value());
|
|
Void::Testing::expect_eq(client_detail->name, std::string{"detail-pkg"});
|
|
Void::Testing::expect_eq(client_detail->version, std::string{"1.0.0"});
|
|
Void::Testing::expect_eq(client_detail->sha256, *sha);
|
|
Void::Testing::expect_eq(client_detail->size_bytes, static_cast<std::uint64_t>(bytes->size()));
|
|
Void::Testing::expect_eq(client_detail->binary_count, std::size_t{0});
|
|
Void::Testing::expect(!client_detail->yanked);
|
|
auto missing_client =
|
|
Package::fetch_release_detail(reg_url, "detail-pkg", "9.9.9", Package::RegistryAuth{*tok});
|
|
Void::Testing::expect(!missing_client.has_value());
|
|
if (!missing_client) {
|
|
Void::Testing::expect(missing_client.error().message().find("404") != std::string::npos);
|
|
}
|
|
|
|
// Signature metadata is stored and served verbatim (the registry is not a trust authority).
|
|
const std::string release_signature(128, 'a');
|
|
const std::string release_public_key(64, 'b');
|
|
auto signed_published =
|
|
send_loopback_http(port, "PUT", "/api/v1/packages/signed-detail-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", *sha},
|
|
{"X-Package-Signature", release_signature},
|
|
{"X-Package-Public-Key", release_public_key}},
|
|
*bytes);
|
|
Void::Testing::require(signed_published.has_value() && signed_published->status == 201);
|
|
|
|
auto signed_detail =
|
|
send_loopback_http(port, "GET", "/api/v1/packages/signed-detail-pkg/1.0.0");
|
|
Void::Testing::expect(signed_detail.has_value() && signed_detail->status == 200);
|
|
if (signed_detail) {
|
|
Void::Testing::expect_eq(extract_json_str(signed_detail->body, "signature"),
|
|
release_signature);
|
|
Void::Testing::expect_eq(extract_json_str(signed_detail->body, "public_key"),
|
|
release_public_key);
|
|
}
|
|
|
|
// Yanking a release is reflected in its detail (admin session cookie + CSRF token).
|
|
auto login = send_loopback_http(
|
|
port, "POST", "/api/v1/auth/login", {{"Content-Type", "application/json"}},
|
|
"{\"username\":\"admin\",\"password\":\"admin_secret_password\"}");
|
|
Void::Testing::require(login.has_value() && login->status == 200);
|
|
const auto cookie = extract_session_cookie(login->set_cookies);
|
|
const auto csrf = extract_json_str(login->body, "csrf_token");
|
|
Void::Testing::require(!cookie.empty() && !csrf.empty());
|
|
auto yank = send_loopback_http(port, "POST", "/api/v1/packages/signed-detail-pkg/1.0.0/yank",
|
|
{{"Cookie", cookie}, {"X-CSRF-Token", csrf}});
|
|
Void::Testing::expect(yank.has_value() && yank->status == 200);
|
|
auto yanked_detail =
|
|
send_loopback_http(port, "GET", "/api/v1/packages/signed-detail-pkg/1.0.0");
|
|
Void::Testing::expect(yanked_detail.has_value() && yanked_detail->status == 200);
|
|
if (yanked_detail) {
|
|
const auto yanked = extract_json_bool(yanked_detail->body, "yanked");
|
|
Void::Testing::require(yanked.has_value());
|
|
Void::Testing::expect(*yanked);
|
|
}
|
|
|
|
// Private releases require read access: anonymous 401, no-read principal 403, reader 200.
|
|
auto private_published =
|
|
send_loopback_http(port, "PUT", "/api/v1/packages/private-detail-pkg/1.0.0",
|
|
{{"Authorization", "Bearer " + *tok},
|
|
{"X-Content-SHA256", *sha},
|
|
{"X-Package-Private", "true"}},
|
|
*bytes);
|
|
Void::Testing::require(private_published.has_value() && private_published->status == 201);
|
|
|
|
Void::Testing::expect(
|
|
(*svc)->create_user("detail_noread", "noread_pass", Role::Reader).has_value());
|
|
auto noread_tok = (*svc)->create_token("detail_noread", "noread", {});
|
|
Void::Testing::expect(noread_tok.has_value());
|
|
if (!noread_tok)
|
|
return;
|
|
Void::Testing::expect(
|
|
(*svc)->create_user("detail_reader", "reader_pass", Role::Reader).has_value());
|
|
auto reader_tok = (*svc)->create_token("detail_reader", "read", {"read"});
|
|
Void::Testing::expect(reader_tok.has_value());
|
|
if (!reader_tok)
|
|
return;
|
|
|
|
const std::string private_path = "/api/v1/packages/private-detail-pkg/1.0.0";
|
|
auto anonymous_private = send_loopback_http(port, "GET", private_path);
|
|
Void::Testing::expect(anonymous_private.has_value() && anonymous_private->status == 401);
|
|
auto forbidden_private =
|
|
send_loopback_http(port, "GET", private_path, {{"Authorization", "Bearer " + *noread_tok}});
|
|
Void::Testing::expect(forbidden_private.has_value() && forbidden_private->status == 403);
|
|
auto owner_private =
|
|
send_loopback_http(port, "GET", private_path, {{"Authorization", "Bearer " + *tok}});
|
|
Void::Testing::expect(owner_private.has_value() && owner_private->status == 200);
|
|
if (owner_private) {
|
|
Void::Testing::expect_eq(extract_json_str(owner_private->body, "name"),
|
|
std::string{"private-detail-pkg"});
|
|
Void::Testing::expect_eq(extract_json_str(owner_private->body, "version"),
|
|
std::string{"1.0.0"});
|
|
Void::Testing::expect_eq(extract_json_str(owner_private->body, "sha256"), *sha);
|
|
const auto size_bytes = extract_json_int(owner_private->body, "size_bytes");
|
|
Void::Testing::require(size_bytes.has_value());
|
|
Void::Testing::expect_eq(*size_bytes, static_cast<std::int64_t>(bytes->size()));
|
|
}
|
|
auto reader_private =
|
|
send_loopback_http(port, "GET", private_path, {{"Authorization", "Bearer " + *reader_tok}});
|
|
Void::Testing::expect(reader_private.has_value() && reader_private->status == 200);
|
|
|
|
// The client surfaces the registry's 401 as a permission_denied system error.
|
|
auto anonymous_client = Package::fetch_release_detail(reg_url, "private-detail-pkg", "1.0.0",
|
|
Package::RegistryAuth{});
|
|
Void::Testing::expect(!anonymous_client.has_value());
|
|
if (!anonymous_client) {
|
|
const auto &error = anonymous_client.error();
|
|
Void::Testing::expect_eq(error.code().domain, Void::Result::kSystemErrorDomain);
|
|
Void::Testing::expect_eq(
|
|
error.code().value,
|
|
static_cast<std::int32_t>(Void::System::SystemErrorCode::permission_denied));
|
|
Void::Testing::expect(error.message().find("401") != std::string::npos);
|
|
}
|
|
|
|
(*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();
|
|
}
|