Skip to content

Commit

Permalink
fix hmac auth (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni authored Oct 25, 2023
1 parent b54a2e7 commit 4e44e7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/wasm-cpp/extensions/hmac_auth/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ std::string getStringToSign() {
getRequestHeader(CA_SIGNATURE_HEADERS)->toString();
std::vector<std::string> header_arr;
for (const auto& header : absl::StrSplit(dynamic_check_headers, ",")) {
if (header.empty()) {
continue;
}
auto lower_header = absl::AsciiStrToLower(header);
if (lower_header == CA_SIGNATURE || lower_header == CA_SIGNATURE_HEADERS) {
continue;
Expand Down
30 changes: 30 additions & 0 deletions plugins/wasm-cpp/extensions/hmac_auth/plugin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ TEST_F(HmacAuthTest, Sign) {
FilterHeadersStatus::Continue);
}

TEST_F(HmacAuthTest, SignWithoutDynamicHeader) {
headers_ = {
{":path", "/Third/Tools/checkSign"},
{":method", "GET"},
{"accept", "application/json"},
{"x-ca-key", "appKey"},
{"x-ca-signature", "ZpJhkHdtjLTJiR6CJWHL8ikLtPB2z6CoztG21wG3PT4="},
};
HmacAuthConfigRule rule;
rule.credentials = {{"appKey", "appSecret"}};
// EXPECT_EQ(root_context_->checkPlugin(rule, std::nullopt), true);

std::string configuration = R"(
{
"_rules_": [
{
"_match_route_":["test"],
"credentials":[
{"key": "appKey", "secret": "appSecret"}
]
}
]
})";
route_name_ = "test";
config_.set(configuration);
EXPECT_TRUE(root_context_->configure(configuration.size()));
EXPECT_EQ(context_->onRequestHeaders(0, false),
FilterHeadersStatus::Continue);
}

TEST_F(HmacAuthTest, SignWithConsumer) {
headers_ = {
{":path", "/Third/Tools/checkSign"},
Expand Down

0 comments on commit 4e44e7a

Please sign in to comment.