feat(registry,cli): RFC 7232 conditional requests; require trusted verify keys
This commit is contained in:
1 parent
27d909fdad
commit
ea6ac852e7
9 files changed
+138
-6
No files matched your search
@@ -60,6 +60,11 @@ check_process(0 "Usage: vbs compdb-entries " "" compdb-entries --help)
|
||||
check_process(1 "" "no compilation database is published" compdb-entries --project
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/no-lock-project")
|
||||
check_process(2 "" "--name, --version, --file, --signature, and --public-key are required" verify)
|
||||
check_process(1 "" "public key is not trusted" verify --name demo --version 1.0.0
|
||||
--file CMakeLists.txt
|
||||
--signature 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
--public-key 0000000000000000000000000000000000000000000000000000000000000000
|
||||
--trusted-public-key aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
|
||||
check_process(1 "" "" verify --name demo --version 1.0.0 --file CMakeLists.txt
|
||||
--signature 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
--public-key 0000000000000000000000000000000000000000000000000000000000000000)
|
||||
|
||||
+26
-3
@@ -2237,9 +2237,21 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(std::filesystem::exists(str_field(*installed, "manifest")));
|
||||
const auto installed_files = string_array_field(*installed, "installed_files");
|
||||
Void::Testing::require(!installed_files.empty());
|
||||
Void::Testing::expect(std::filesystem::exists(installed_files.front()));
|
||||
Void::Testing::expect(installed_files.size() <=
|
||||
static_cast<std::size_t>(int_field(*installed, "files")));
|
||||
Void::Testing::expect_eq(installed_files.size(),
|
||||
static_cast<std::size_t>(int_field(*installed, "files")));
|
||||
Void::Testing::expect(!bool_field(*installed, "installed_files_truncated"));
|
||||
const auto prefix_abs = std::filesystem::weakly_canonical(prefix);
|
||||
for (const auto &file : installed_files) {
|
||||
const std::filesystem::path path{file};
|
||||
Void::Testing::expect(!file.empty());
|
||||
Void::Testing::expect(path.is_absolute());
|
||||
Void::Testing::expect(std::filesystem::is_regular_file(path));
|
||||
const auto relative = path.lexically_relative(prefix_abs);
|
||||
Void::Testing::expect(!relative.empty());
|
||||
if (!relative.empty()) {
|
||||
Void::Testing::expect(relative.native().rfind("..", 0) != 0);
|
||||
}
|
||||
}
|
||||
Void::Testing::require(missing_prefix.has_value());
|
||||
Void::Testing::expect(!bool_field(*missing_prefix, "ok", true));
|
||||
|
||||
@@ -2254,6 +2266,14 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(bool_field(*installed_no_cmake, "ok"));
|
||||
Void::Testing::expect(int_field(*installed_no_cmake, "files") >= 1);
|
||||
Void::Testing::expect(std::filesystem::exists(prefix_no_cmake / "bin" / "app"));
|
||||
const auto installed_files_no_cmake =
|
||||
string_array_field(*installed_no_cmake, "installed_files");
|
||||
Void::Testing::require(!installed_files_no_cmake.empty());
|
||||
for (const auto &file : installed_files_no_cmake) {
|
||||
Void::Testing::expect(std::filesystem::exists(file));
|
||||
Void::Testing::expect(!file.ends_with("Config.cmake"));
|
||||
Void::Testing::expect(!file.ends_with("Targets.cmake"));
|
||||
}
|
||||
bool has_cmake_config = false;
|
||||
for (const auto &entry : std::filesystem::recursive_directory_iterator(prefix_no_cmake)) {
|
||||
if (entry.is_regular_file() && entry.path().filename().string().ends_with("Config.cmake")) {
|
||||
@@ -2295,6 +2315,9 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(bool_field(*uninstalled, "ok"));
|
||||
Void::Testing::expect(int_field(*uninstalled, "removed") >= 1);
|
||||
Void::Testing::expect(!std::filesystem::exists(prefix / "bin" / "app"));
|
||||
for (const auto &file : installed_files) {
|
||||
Void::Testing::expect(!std::filesystem::exists(file));
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, install_request_component_filters_installed_files) {
|
||||
|
||||
@@ -1021,6 +1021,40 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
|
||||
std::string::npos);
|
||||
Void::Testing::expect(binary_detail->body.find("\"download_url\":") != std::string::npos);
|
||||
}
|
||||
// The binary detail response is ETag-validated: matching (strong, weak, list or `*`)
|
||||
// If-None-Match values yield a bodyless 304, while a stale validator returns the full 200.
|
||||
if (binary_detail) {
|
||||
Void::Testing::expect_eq(binary_detail->headers.at("cache-control"),
|
||||
std::string{"no-cache"});
|
||||
const auto etag_it = binary_detail->headers.find("etag");
|
||||
Void::Testing::expect(etag_it != binary_detail->headers.end());
|
||||
if (etag_it != binary_detail->headers.end()) {
|
||||
const std::string &etag = etag_it->second;
|
||||
auto not_modified =
|
||||
send_loopback_http(port, "GET", binary_path, {{"If-None-Match", etag}});
|
||||
Void::Testing::expect(not_modified.has_value() && not_modified->status == 304);
|
||||
if (not_modified) {
|
||||
Void::Testing::expect(not_modified->body.empty());
|
||||
Void::Testing::expect_eq(not_modified->headers.at("etag"), etag);
|
||||
Void::Testing::expect_eq(not_modified->headers.at("cache-control"),
|
||||
std::string{"no-cache"});
|
||||
}
|
||||
auto weak =
|
||||
send_loopback_http(port, "GET", binary_path, {{"If-None-Match", "W/" + etag}});
|
||||
Void::Testing::expect(weak.has_value() && weak->status == 304);
|
||||
auto list_match = send_loopback_http(port, "GET", binary_path,
|
||||
{{"If-None-Match", "\"stale\", " + etag}});
|
||||
Void::Testing::expect(list_match.has_value() && list_match->status == 304);
|
||||
auto wildcard = send_loopback_http(port, "GET", binary_path, {{"If-None-Match", "*"}});
|
||||
Void::Testing::expect(wildcard.has_value() && wildcard->status == 304);
|
||||
auto stale =
|
||||
send_loopback_http(port, "GET", binary_path, {{"If-None-Match", "\"stale\""}});
|
||||
Void::Testing::expect(stale.has_value() && stale->status == 200);
|
||||
if (stale) {
|
||||
Void::Testing::expect_eq(stale->body, binary_detail->body);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto missing_binary = send_loopback_http(port, "GET", binary_path + "-missing");
|
||||
Void::Testing::expect(missing_binary.has_value() && missing_binary->status == 404);
|
||||
|
||||
|
||||
Reference in new issue
Block a user