Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v24.3.x] http/utils: changed url encoding to use upper case hex representation #25188

Open
wants to merge 1 commit into
base: v24.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/v/http/tests/request_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TEST(request_builder, test_url_percent_encoding) {
ASSERT_TRUE(req.has_value());
EXPECT_EQ(
req->target(),
"/?afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%3f%"
"40%5b%5dafgz0119=afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%"
"3f%40%5b%5dafgz0119");
"/?afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%"
"40%5B%5Dafgz0119=afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%"
"3F%40%5B%5Dafgz0119");
}
26 changes: 13 additions & 13 deletions src/v/http/tests/uri_encoding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ TEST(uri_encoding, encode_special_chars) {
constexpr auto input = "afgz0119!#$&'()*+,/:;=?@[]afgz0119";
ASSERT_EQ(
http::uri_encode(input, http::uri_encode_slash::yes),
"afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%3f%"
"40%5b%5dafgz0119");
"afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%"
"40%5B%5Dafgz0119");

ASSERT_EQ(
http::uri_encode(input, http::uri_encode_slash::no),
"afgz0119%21%23%24%26%27%28%29%2a%2b%2c/"
"%3a%3b%3d%3f%40%5b%5dafgz0119");
"afgz0119%21%23%24%26%27%28%29%2A%2B%2C/"
"%3A%3B%3D%3F%40%5B%5Dafgz0119");
}

TEST(uri_encoding, form_encoded_data) {
Expand All @@ -38,15 +38,15 @@ TEST(uri_encoding, form_encoded_data) {
iobuf_parser p{http::form_encode_data(input)};

// Order of kv pairs is not guaranteed due to map iteration order
auto s = p.read_string(p.bytes_left());
fmt::print(">>> {}\n", s);
ASSERT_THAT(
p.read_string(p.bytes_left()),
s,
AnyOf(
"foo=bar&afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%3f%40%"
"5b%"
"5dafgz0119=afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%3f%"
"40%"
"5b%5dafgz0119",
"afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%3b%3d%3f%"
"40%5b%5dafgz0119=afgz0119%21%23%24%26%27%28%29%2a%2b%2c%2F%3a%"
"3b%3d%3f%40%5b%5dafgz0119&foo=bar"));
"foo=bar&afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%"
"5Dafgz0119=afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%"
"5B%5Dafgz0119",
"afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%"
"40%5B%5Dafgz0119=afgz0119%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%"
"3B%3D%3F%40%5B%5Dafgz0119&foo=bar"));
}
14 changes: 7 additions & 7 deletions src/v/http/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

#include "http/utils.h"

#include "bytes/bytes.h"

#include <boost/algorithm/string/join.hpp>

namespace {

/**
* Each URI encoded byte is formed by a '%' and the two-digit hexadecimal
* value of the byte.
* from:
* https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
*/
inline void append_hex_utf8(ss::sstring& result, char ch) {
bytes b = {static_cast<uint8_t>(ch)};
result.append("%", 1);
auto h = to_hex(b);
auto h = fmt::format("%{:02X}", static_cast<uint8_t>(ch));
result.append(h.data(), h.size());
}

Expand Down
2 changes: 1 addition & 1 deletion src/v/iceberg/rest_client/tests/catalog_client_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ss::future<http::downloaded_response> validate_token_request(
std::ranges::sort(received);

ss::sstring expected{
"grant_type=client_credentials&scope=PRINCIPAL_ROLE%3aALL&client_secret="
"grant_type=client_credentials&scope=PRINCIPAL_ROLE%3AALL&client_secret="
"secret&client_id=id"};
std::ranges::sort(expected);

Expand Down
2 changes: 1 addition & 1 deletion src/v/iceberg/tests/rest_catalog_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ss::future<http::downloaded_response> handle_token_request(
EXPECT_TRUE(query_params_equal(
absl::flat_hash_map<ss::sstring, ss::sstring>{
{"grant_type", "client_credentials"},
{"scope", "PRINCIPAL_ROLE%3aALL"},
{"scope", "PRINCIPAL_ROLE%3AALL"},
{"client_secret", get_credentials().client_secret},
{"client_id", get_credentials().client_id}},
received));
Expand Down