feat(cli,registry): verify signed artifacts offline; attach download filenames
This commit is contained in:
1 parent
da7e8233ce
commit
af735c28ff
5 files changed
+122
No files matched your search
@@ -79,6 +79,22 @@ std::optional<bool> extract_json_bool(std::string_view json, const std::string &
|
||||
return b ? std::optional<bool>{*b} : std::nullopt;
|
||||
}
|
||||
|
||||
void expect_attachment_disposition(const std::map<std::string, std::string, std::less<>> &headers,
|
||||
std::string_view expected_filename) {
|
||||
const auto it = headers.find("content-disposition");
|
||||
Void::Testing::expect(it != headers.end());
|
||||
if (it == headers.end()) {
|
||||
return;
|
||||
}
|
||||
const std::string &value = it->second;
|
||||
Void::Testing::expect(value.starts_with("attachment; filename=\""));
|
||||
Void::Testing::expect(value.find("filename=\"" + std::string{expected_filename} + "\"") !=
|
||||
std::string::npos);
|
||||
Void::Testing::expect(value.find('\r') == std::string::npos);
|
||||
Void::Testing::expect(value.find('\n') == std::string::npos);
|
||||
Void::Testing::expect(std::ranges::count(value, '"') % 2 == 0);
|
||||
}
|
||||
|
||||
std::filesystem::path locate_vbs_binary() {
|
||||
std::error_code ec;
|
||||
if (const auto self_exe = Platform::current_executable_path(); self_exe) {
|
||||
@@ -631,6 +647,9 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
|
||||
"/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);
|
||||
if (dl) {
|
||||
expect_attachment_disposition(dl->headers, "secret-pkg-1.0.0.tar");
|
||||
}
|
||||
(*svc2)->stop_http();
|
||||
}
|
||||
}
|
||||
@@ -1009,6 +1028,7 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
|
||||
Void::Testing::expect(downloaded.has_value() && downloaded->status == 200);
|
||||
if (downloaded) {
|
||||
Void::Testing::expect(downloaded->body == artifact);
|
||||
expect_attachment_disposition(downloaded->headers, "demo-bin-1.0.0-" + variant_id + ".bin");
|
||||
}
|
||||
auto etag_head = send_loopback_http(port, "GET", binary_path + "/download");
|
||||
Void::Testing::expect(etag_head.has_value() && etag_head->status == 200);
|
||||
@@ -1032,6 +1052,7 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
|
||||
Void::Testing::expect(
|
||||
ranged->headers.at("content-range").find("/" + std::to_string(artifact.size())) !=
|
||||
std::string::npos);
|
||||
expect_attachment_disposition(ranged->headers, "demo-bin-1.0.0-" + variant_id + ".bin");
|
||||
}
|
||||
auto unsatisfiable =
|
||||
send_loopback_http(port, "GET", binary_path + "/download", {{"Range", "bytes=999999-"}});
|
||||
@@ -1042,6 +1063,22 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
|
||||
Void::Testing::expect(head_binary->body.empty());
|
||||
Void::Testing::expect_eq(head_binary->headers.at("content-length"),
|
||||
std::to_string(artifact.size()));
|
||||
expect_attachment_disposition(head_binary->headers,
|
||||
"demo-bin-1.0.0-" + variant_id + ".bin");
|
||||
}
|
||||
|
||||
// A SemVer build tag is not a safe filename byte, so the header sanitizes it instead of
|
||||
// reflecting it verbatim.
|
||||
const std::string build_version = "1.0.0+build.5";
|
||||
auto build_publish = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/demo-bin/" + build_version,
|
||||
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *source_sha}}, *source_bytes);
|
||||
Void::Testing::expect(build_publish.has_value() && build_publish->status == 201);
|
||||
auto build_download =
|
||||
send_loopback_http(port, "GET", "/api/v1/packages/demo-bin/" + build_version + "/download");
|
||||
Void::Testing::expect(build_download.has_value() && build_download->status == 200);
|
||||
if (build_download) {
|
||||
expect_attachment_disposition(build_download->headers, "demo-bin-1.0.0_build.5.tar");
|
||||
}
|
||||
|
||||
auto conflict = send_loopback_http(
|
||||
|
||||
Reference in new issue
Block a user