Fix daily build: Empty URIs should return a 404 (#4215)

This commit is contained in:
Eddy Ashton 2022-09-12 11:59:04 +01:00 коммит произвёл GitHub
Родитель 26784844d6
Коммит 63f5f1d5c3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -1 +1 @@
Canary!!
Canary!!!

Просмотреть файл

@ -120,7 +120,12 @@ namespace ccf::endpoints
EndpointRegistry::Metrics& EndpointRegistry::get_metrics_for_request(
const std::string& method_, const std::string& verb)
{
auto method = method_.substr(method_.find_first_not_of('/'));
auto substr_start = method_.find_first_not_of('/');
if (substr_start == std::string::npos)
{
substr_start = 0;
}
auto method = method_.substr(substr_start);
return metrics[method][verb];
}

Просмотреть файл

@ -545,15 +545,18 @@ TEST_CASE("process with signatures")
SUBCASE("missing rpc")
{
constexpr auto rpc_name = "/this_rpc_doesnt_exist";
const auto invalid_call = create_simple_request(rpc_name);
const auto serialized_call = invalid_call.build_request();
auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
for (const std::string& rpc_name :
{"", "/", "/this_rpc_doesnt_exist", "/this/rpc/doesnt/exist"})
{
const auto invalid_call = create_simple_request(rpc_name);
const auto serialized_call = invalid_call.build_request();
auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
const auto serialized_response = rpc_ctx->serialise_response();
auto response = parse_response(serialized_response);
REQUIRE(response.status == HTTP_STATUS_NOT_FOUND);
frontend.process(rpc_ctx);
const auto serialized_response = rpc_ctx->serialise_response();
auto response = parse_response(serialized_response);
REQUIRE(response.status == HTTP_STATUS_NOT_FOUND);
}
}
SUBCASE("endpoint does not require signature")

Просмотреть файл

@ -1457,6 +1457,16 @@ def test_rekey(network, args):
return network
@reqs.description("Test empty URI behaviour")
def test_empty_path(network, args):
primary, _ = network.find_primary()
with primary.client() as c:
r = c.get("/")
assert r.status_code == http.HTTPStatus.NOT_FOUND
r = c.post("/")
assert r.status_code == http.HTTPStatus.NOT_FOUND
@reqs.description("Test UDP echo endpoint")
@reqs.at_least_n_nodes(1)
def test_udp_echo(network, args):
@ -1550,6 +1560,7 @@ def run(args):
test_historical_query_range(network, args)
test_view_history(network, args)
test_metrics(network, args)
test_empty_path(network, args)
# BFT does not handle re-keying yet
if args.consensus == "CFT":
test_liveness(network, args)