mirror of
https://github.com/alibaba/higress.git
synced 2026-02-22 18:01:09 +08:00
fix hmac auth (#603)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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"},
|
||||
|
||||
Reference in New Issue
Block a user