fix(package): never include the archive in itself; extend release-detail tests
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 9s

This commit is contained in:
faumaray committed 2026-12-04 05:04:44 +03:00
1 parent 691560a369
commit 2c4eeba945
7 files changed
+258 -1

No files matched your search

+8
View File
@@ -572,6 +572,14 @@ VOID_TEST(FullV1Tests, archive_security_determinism_binary_abi_and_redaction) {
Void::Testing::expect(!std::filesystem::exists(out_dir / ".git" / "HEAD"));
Void::Testing::expect(!std::filesystem::exists(out_dir / ".env"));
// An archive written inside the project never contains itself on a later run.
const auto inner_tar = proj / "dist" / "pkg.tar";
Void::Testing::expect(Package::create_source_package(proj, inner_tar, 0).has_value());
Void::Testing::expect(Package::create_source_package(proj, inner_tar, 0).has_value());
const auto inner_out = tmp / "inner_extracted";
Void::Testing::expect(Package::extract_safe_tar(inner_tar, inner_out).has_value());
Void::Testing::expect(!std::filesystem::exists(inner_out / "dist" / "pkg.tar"));
// Malicious tar rejection: path traversal, absolute path, symlink, duplicate path, quota.
const auto trav_tar = tmp / "trav.tar";
write_raw_tar(trav_tar, {{"../escape.txt", '0', "evil"}});
+220
View File
@@ -19,6 +19,7 @@
#include <algorithm>
#include <cstring>
#include <fstream>
#include <optional>
#include <span>
using namespace Void::Build;
@@ -50,6 +51,34 @@ std::string extract_json_str(std::string_view json, const std::string &key) {
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) {
@@ -784,6 +813,14 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
}
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);
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);
@@ -1310,3 +1347,186 @@ target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include
(*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();
}