Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
KEP-1229 Quickread responses must not be signed
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruck committed Mar 5, 2019
1 parent 83e96ec commit 5306c30
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
10 changes: 9 additions & 1 deletion crud/crud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ crud::send_response(const database_msg& request, const bzn::storage_result resul

if (session)
{
session->send_signed_message(std::make_shared<bzn_envelope>(env));
// special response case that does not require sighing...
if (request.msg_case() == database_msg::kQuickRead)
{
session->send_message(std::make_shared<bzn::encoded_message >(env.SerializeAsString()));
}
else
{
session->send_signed_message(std::make_shared<bzn_envelope>(env));
}
}
else
{
Expand Down
45 changes: 43 additions & 2 deletions crud/test/crud_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,47 @@ namespace
additional_checks(resp);
}));
}

void expect_response(const std::shared_ptr<bzn::Mocksession_base>& session,
std::optional<bzn::uuid_t> db_uuid = std::nullopt,
std::optional<uint64_t> nonce = std::nullopt,
std::optional<database_response::ResponseCase> response_case = std::nullopt,
std::optional<std::string> error_msg = std::nullopt,
std::function<void(const database_response&)> additional_checks = [](auto){})
{
EXPECT_CALL(*session, send_message(_)).WillOnce(Invoke(
[=](std::shared_ptr<std::string> msg)
{
bzn_envelope env;
env.ParseFromString(*msg);

EXPECT_EQ(env.payload_case(), bzn_envelope::kDatabaseResponse);
database_response resp;
resp.ParseFromString(env.database_response());

if (db_uuid)
{
EXPECT_EQ(resp.header().db_uuid(), *db_uuid);
}

if (nonce)
{
EXPECT_EQ(resp.header().nonce(), *nonce);
}

if (response_case)
{
EXPECT_EQ(resp.response_case(), *response_case);
}

if (error_msg)
{
EXPECT_EQ(resp.error().message(), *error_msg);
}

additional_checks(resp);
}));
}
}


Expand Down Expand Up @@ -285,7 +326,7 @@ TEST(crud, test_that_read_sends_proper_response)
// quick read key...
msg.release_read();
msg.mutable_quick_read()->set_key("key");
expect_signed_response(session, "uuid", uint64_t(123), database_response::kRead, std::nullopt,
expect_response(session, "uuid", uint64_t(123), database_response::kRead, std::nullopt,
[](const auto& resp)
{
ASSERT_EQ(resp.read().key(), "key");
Expand All @@ -304,7 +345,7 @@ TEST(crud, test_that_read_sends_proper_response)
// quick read invalid key...
msg.release_read();
msg.mutable_quick_read()->set_key("invalid-key");
expect_signed_response(session, "uuid", uint64_t(123), database_response::kError, bzn::storage_result_msg.at(bzn::storage_result::not_found));
expect_response(session, "uuid", uint64_t(123), database_response::kError, bzn::storage_result_msg.at(bzn::storage_result::not_found));

crud.handle_request("caller_id", msg, session);

Expand Down

0 comments on commit 5306c30

Please sign in to comment.