Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtropets committed Feb 7, 2025
1 parent 969cd93 commit 5f45eab
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 113 deletions.
2 changes: 1 addition & 1 deletion include/ccf/ds/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ namespace std
#define JSON_FIELD_FOR_JSON_FINAL(TYPE, FIELD) \
ccf::JsonField<decltype(TYPE::FIELD)> \
{ \
# FIELD \
#FIELD \
}

/** Defines from_json, to_json, fill_json_schema, schema_name and
Expand Down
8 changes: 4 additions & 4 deletions include/ccf/receipt.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ namespace ccf
void add_schema_components(
T& helper, nlohmann::json& schema, const ProofReceipt::Components* comp)
{
helper.template add_schema_component<decltype(
ProofReceipt::Components::write_set_digest)>();
helper.template add_schema_component<decltype(
ProofReceipt::Components::claims_digest)>();
helper.template add_schema_component<
decltype(ProofReceipt::Components::write_set_digest)>();
helper.template add_schema_component<
decltype(ProofReceipt::Components::claims_digest)>();

fill_json_schema(schema, comp);
}
Expand Down
20 changes: 20 additions & 0 deletions scripts/setup-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.

set -ex

tdnf -y install \
vim \
clang-tools-extra \
python-pip

pip install cmakelang

# shellcheck
curl -L https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz \
--output shellcheck.tar.gz
mkdir -p shellcheck-dir
tar -xvf shellcheck.tar.gz -C shellcheck-dir
mv shellcheck-dir/shellcheck-stable/shellcheck /usr/local/bin/shellcheck
rm -rf shellcheck-dir shellcheck.tar.gz
8 changes: 4 additions & 4 deletions src/clients/perf/perf_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ namespace client
return r.status == HTTP_STATUS_OK;
}

virtual void pre_creation_hook(){};
virtual void post_creation_hook(){};
virtual void pre_creation_hook() {};
virtual void post_creation_hook() {};

virtual void pre_timing_body_hook(){};
virtual void post_timing_body_hook(){};
virtual void pre_timing_body_hook() {};
virtual void post_timing_body_hook() {};

virtual timing::Results call_raw_batch(
std::shared_ptr<RpcTlsClient>& connection, const PreparedTxs& txs)
Expand Down
3 changes: 2 additions & 1 deletion src/ds/test/oversized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ TEST_CASE("Reconstruction" * doctest::test_suite("oversized"))
MessageStream ms{ascending, 0, 0};

while (!write_more(ms, fragment_size))
{}
{
}

REQUIRE(complete_messages == complete_prior + 1);
}
Expand Down
6 changes: 4 additions & 2 deletions src/enclave/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ extern "C"
}

while (num_pending_threads != 0)
{}
{
}

LOG_INFO_FMT("All threads are ready!");

Expand All @@ -325,7 +326,8 @@ extern "C"
auto s = e.load()->run_main();
while (num_complete_threads !=
threading::ThreadMessaging::instance().thread_count() - 1)
{}
{
}
threading::ThreadMessaging::shutdown();
return s;
}
Expand Down
8 changes: 4 additions & 4 deletions src/js/extensions/ccf/kv_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace ccf::js::extensions::kvhelpers
{
using KVMap = ::ccf::kv::untyped::Map;

using ROHandleGetter =
KVMap::ReadOnlyHandle* (*)(js::core::Context& jsctx, JSValueConst this_val);
using RWHandleGetter =
KVMap::Handle* (*)(js::core::Context& jsctx, JSValueConst this_val);
using ROHandleGetter = KVMap::ReadOnlyHandle* (*)(js::core::Context& jsctx,
JSValueConst this_val);
using RWHandleGetter = KVMap::Handle* (*)(js::core::Context& jsctx,
JSValueConst this_val);

#define JS_KV_PERMISSION_ERROR_HELPER(C_FUNC_NAME, JS_METHOD_NAME) \
static JSValue C_FUNC_NAME( \
Expand Down
12 changes: 6 additions & 6 deletions src/node/receipt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ namespace ccf
{
required.push_back("claims_digest");
properties["claims_digest"] = ds::openapi::components_ref_object(
ds::json::schema_name<decltype(
ProofReceipt::Components::claims_digest)>());
ds::json::schema_name<
decltype(ProofReceipt::Components::claims_digest)>());

required.push_back("commit_evidence");
properties["commit_evidence"] = ds::openapi::components_ref_object(
ds::json::schema_name<decltype(
ProofReceipt::Components::commit_evidence)>());
ds::json::schema_name<
decltype(ProofReceipt::Components::commit_evidence)>());

required.push_back("write_set_digest");
properties["write_set_digest"] = ds::openapi::components_ref_object(
ds::json::schema_name<decltype(
ProofReceipt::Components::write_set_digest)>());
ds::json::schema_name<
decltype(ProofReceipt::Components::write_set_digest)>());
}

schema["required"] = required;
Expand Down
176 changes: 89 additions & 87 deletions src/node/rpc/test/frontend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,18 @@ nlohmann::json parse_response_body(const vector<uint8_t>& body)
}

// callers used throughout
auto user_caller = kp -> self_sign("CN=name", valid_from, valid_to);
auto user_caller_der = ccf::crypto::make_verifier(user_caller) -> cert_der();
auto user_caller = kp->self_sign("CN=name", valid_from, valid_to);
auto user_caller_der = ccf::crypto::make_verifier(user_caller)->cert_der();

auto member_caller_der = ccf::crypto::make_verifier(member_cert) -> cert_der();
auto member_caller_der = ccf::crypto::make_verifier(member_cert)->cert_der();

auto node_caller = kp -> self_sign("CN=node", valid_from, valid_to);
auto node_caller_der = ccf::crypto::make_verifier(node_caller) -> cert_der();
auto node_caller = kp->self_sign("CN=node", valid_from, valid_to);
auto node_caller_der = ccf::crypto::make_verifier(node_caller)->cert_der();

auto kp_other = ccf::crypto::make_key_pair();
auto invalid_caller = kp_other -> self_sign("CN=name", valid_from, valid_to);
auto invalid_caller = kp_other->self_sign("CN=name", valid_from, valid_to);
auto invalid_caller_der =
ccf::crypto::make_verifier(invalid_caller) -> cert_der();
ccf::crypto::make_verifier(invalid_caller)->cert_der();

auto anonymous_caller_der = std::vector<uint8_t>();

Expand Down Expand Up @@ -659,102 +659,104 @@ TEST_CASE("JsonWrappedEndpointFunction")
NetworkState network;
prepare_callers(network);
TestJsonWrappedEndpointFunction frontend(*network.tables);
{{INFO("Calling echo, with params in body");
auto echo_call = create_simple_request("/echo");
const nlohmann::json j_body = {
{"data", {"nested", "Some string"}}, {"other", "Another string"}};
const auto serialized_body = j_body.dump();
echo_call.set_body(serialized_body);
const auto serialized_call = echo_call.build_request();

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);

const auto response_body = parse_response_body(response.body);
CHECK(response_body == j_body);
}

{
INFO("Calling echo_query, with params in query");
auto echo_call = create_simple_request("/echo_parsed_query");
const std::map<std::string, std::string> query_params = {
{"foo", "helloworld"},
{"bar", "1"},
{"fooz", "\"2\""},
{"baz", "\"awkward\"\"escapes"}};
for (const auto& [k, v] : query_params)
{
echo_call.set_query_param(k, v);
}
{
INFO("Calling echo, with params in body");
auto echo_call = create_simple_request("/echo");
const nlohmann::json j_body = {
{"data", {"nested", "Some string"}}, {"other", "Another string"}};
const auto serialized_body = j_body.dump();
echo_call.set_body(serialized_body);
const auto serialized_call = echo_call.build_request();

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);

const auto serialized_call = echo_call.build_request();
const auto response_body = parse_response_body(response.body);
CHECK(response_body == j_body);
}

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);
{
INFO("Calling echo_query, with params in query");
auto echo_call = create_simple_request("/echo_parsed_query");
const std::map<std::string, std::string> query_params = {
{"foo", "helloworld"},
{"bar", "1"},
{"fooz", "\"2\""},
{"baz", "\"awkward\"\"escapes"}};
for (const auto& [k, v] : query_params)
{
echo_call.set_query_param(k, v);
}

const auto response_body = parse_response_body(response.body);
const auto response_map = response_body.get<decltype(query_params)>();
CHECK(response_map == query_params);
}
const auto serialized_call = echo_call.build_request();

{
INFO("Calling get_caller");
const auto get_caller = create_simple_request("/get_caller");
const auto serialized_call = get_caller.build_request();
auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);
const auto response_body = parse_response_body(response.body);
const auto response_map = response_body.get<decltype(query_params)>();
CHECK(response_map == query_params);
}

const UserId response_body = parse_response_body(response.body);
CHECK(response_body == user_id);
}
}
{
INFO("Calling get_caller");
const auto get_caller = create_simple_request("/get_caller");
const auto serialized_call = get_caller.build_request();

{
INFO("Calling failable, without failing");
auto dont_fail = create_simple_request("/failable");
const auto serialized_call = dont_fail.build_request();
auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == HTTP_STATUS_OK);
}
const UserId response_body = parse_response_body(response.body);
CHECK(response_body == user_id);
}
}

{
for (const auto err : {
HTTP_STATUS_INTERNAL_SERVER_ERROR,
HTTP_STATUS_BAD_REQUEST,
(ccf::http_status)418 // Teapot
})
{
INFO("Calling failable, with error");
const auto msg = fmt::format("An error message about {}", err);
auto fail = create_simple_request("/failable");
const nlohmann::json j_body = {
{"error", {{"code", err}, {"message", msg}}}};
const auto serialized_body = j_body.dump();
fail.set_body(serialized_body);
const auto serialized_call = fail.build_request();
INFO("Calling failable, without failing");
auto dont_fail = create_simple_request("/failable");
const auto serialized_call = dont_fail.build_request();

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == err);
CHECK(
response.headers[ccf::http::headers::CONTENT_TYPE] ==
ccf::http::headervalues::contenttype::JSON);
const std::string body_s(response.body.begin(), response.body.end());
auto body_j = nlohmann::json::parse(body_s);
CHECK(body_j["error"]["message"] == msg);
CHECK(response.status == HTTP_STATUS_OK);
}

{
for (const auto err : {
HTTP_STATUS_INTERNAL_SERVER_ERROR,
HTTP_STATUS_BAD_REQUEST,
(ccf::http_status)418 // Teapot
})
{
INFO("Calling failable, with error");
const auto msg = fmt::format("An error message about {}", err);
auto fail = create_simple_request("/failable");
const nlohmann::json j_body = {
{"error", {{"code", err}, {"message", msg}}}};
const auto serialized_body = j_body.dump();
fail.set_body(serialized_body);
const auto serialized_call = fail.build_request();

auto rpc_ctx = ccf::make_rpc_context(user_session, serialized_call);
frontend.process(rpc_ctx);
auto response = parse_response(rpc_ctx->serialise_response());
CHECK(response.status == err);
CHECK(
response.headers[ccf::http::headers::CONTENT_TYPE] ==
ccf::http::headervalues::contenttype::JSON);
const std::string body_s(response.body.begin(), response.body.end());
auto body_j = nlohmann::json::parse(body_s);
CHECK(body_j["error"]["message"] == msg);
}
}
}
}

TEST_CASE("Restricted verbs")
Expand Down
6 changes: 3 additions & 3 deletions src/node/rpc/test/frontend_test_infra.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ auto valid_to = ccf::crypto::compute_cert_valid_to_string(
valid_from, certificate_validity_period_days);

auto kp = ccf::crypto::make_key_pair();
auto member_cert = kp -> self_sign("CN=name_member", valid_from, valid_to);
auto member_cert = kp->self_sign("CN=name_member", valid_from, valid_to);
auto verifier_mem = ccf::crypto::make_verifier(member_cert);
auto user_cert = kp -> self_sign("CN=name_user", valid_from, valid_to);
auto dummy_enc_pubk = ccf::crypto::make_rsa_key_pair() -> public_key_pem();
auto user_cert = kp->self_sign("CN=name_user", valid_from, valid_to);
auto dummy_enc_pubk = ccf::crypto::make_rsa_key_pair()->public_key_pem();

auto encryptor = std::make_shared<ccf::kv::NullTxEncryptor>();

Expand Down
2 changes: 1 addition & 1 deletion src/node/rpc/test/node_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace ccf
historical::ExpiryDuration seconds_until_expiry)
{}

void set_soft_cache_limit(historical::CacheSize cache_limit){};
void set_soft_cache_limit(historical::CacheSize cache_limit) {};

void track_deletes_on_missing_keys(bool track) {}

Expand Down

0 comments on commit 5f45eab

Please sign in to comment.