Skip to content

Commit

Permalink
Merge pull request #5454 from abhijat/si-header-logging
Browse files Browse the repository at this point in the history
http: tests and improvements for header logging
  • Loading branch information
Lazin committed Jul 20, 2022
2 parents 5b0b0eb + 24a84d5 commit 8690c40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/v/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include <limits>
#include <stdexcept>

namespace {
using field_type = std::variant<boost::beast::http::field, std::string>;

const std::unordered_set<field_type> redacted_fields{
boost::beast::http::field::authorization,
"x-amz-content-sha256",
"x-amz-security-token"};
} // namespace

namespace http {

// client implementation //
Expand Down Expand Up @@ -593,13 +602,7 @@ ss::input_stream<char> client::response_stream::as_input_stream() {
}

client::request_header redacted_header(client::request_header original) {
using field_type = std::variant<boost::beast::http::field, std::string>;

static const std::unordered_set<field_type> redacted_fields{
boost::beast::http::field::authorization, "x-amz-content-sha256"};

auto h{std::move(original)};

for (const auto& field : redacted_fields) {
std::visit(
[&h](const auto& f) {
Expand Down
12 changes: 12 additions & 0 deletions src/v/http/tests/http_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,15 @@ SEASTAR_THREAD_TEST_CASE(test_http_reconnect_graceful_shutdown) {
ss::sleep(10ms).get();
BOOST_REQUIRE(fut.get() == http::reconnect_result_t::timed_out);
}

SEASTAR_THREAD_TEST_CASE(test_header_redacted) {
http::client::request_header request_header;
request_header.set(boost::beast::http::field::authorization, "password");
request_header.set("x-amz-content-sha256", "pigeon");
request_header.set("x-amz-security-token", "capetown");
auto redacted = http::redacted_header(request_header);
auto s = fmt::format("{}", redacted);
BOOST_REQUIRE(s.find("password") == std::string::npos);
BOOST_REQUIRE(s.find("pigeon") == std::string::npos);
BOOST_REQUIRE(s.find("capetown") == std::string::npos);
}

0 comments on commit 8690c40

Please sign in to comment.