Skip to content

Commit

Permalink
test(helper): fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Rulleau <[email protected]>
  • Loading branch information
Leiyks committed Oct 28, 2024
1 parent f9cdb9e commit 16a5999
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions appsec/tests/helper/client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ TEST(ClientTest, EventWithMultipleActions)
EXPECT_EQ(msg_res->actions.size(),
3); // Block is not generated since there is a redirect
EXPECT_STREQ(msg_res->actions[0].verdict.c_str(), "redirect");
EXPECT_STREQ(
msg_res->actions[0].parameters["location"].c_str(), "localhost");
EXPECT_STREQ(msg_res->actions[0].parameters["location"].c_str(),
"https://localhost");
EXPECT_STREQ(
msg_res->actions[0].parameters["status_code"].c_str(), "303");
EXPECT_STREQ(msg_res->actions[1].verdict.c_str(),
Expand Down
5 changes: 2 additions & 3 deletions appsec/tests/helper/engine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
// This product includes software developed at Datadog
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#include "common.hpp"
#include "json_helper.hpp"
#include <engine.hpp>
#include <memory>
#include <rapidjson/document.h>
#include <subscriber/waf.hpp>

const std::string waf_rule =
R"({"version":"2.1","rules":[{"id":"1","name":"rule1","tags":{"type":"flow1","category":"category1"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg1","key_path":[]}],"regex":"^string.*"}},{"operator":"match_regex","parameters":{"inputs":[{"address":"arg2","key_path":[]}],"regex":".*"}}]}]})";
R"({"version":"2.1","rules":[{"id":"1","name":"rule1","tags":{"type":"flow1","category":"category1"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg1","key_path":[]}],"regex":"^string.*"}},{"operator":"match_regex","parameters":{"inputs":[{"address":"arg2","key_path":[]}],"regex":".*"}}]},{"id":"2","name":"rule2","tags":{"type":"flow2","category":"category2"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg3","key_path":[]}],"regex":"^string.*"}}]}]})";
const std::string waf_rule_with_data =
R"({"version":"2.1","rules":[{"id":"blk-001-001","name":"Block IP Addresses","tags":{"type":"block_ip","category":"security_response"},"conditions":[{"parameters":{"inputs":[{"address":"http.client_ip"}],"data":"blocked_ips"},"operator":"ip_match"}],"transformers":[],"on_match":["block"]}]})";

Expand Down Expand Up @@ -704,7 +703,7 @@ TEST(EngineTest, WafSubscriptorUpdateRuleOverrideAndActions)
R"({"rules_override": [{"rules_target":[{"rule_id":"1"}],
"on_match": ["redirect"]}], "actions": [{"id": "redirect",
"type": "redirect_request", "parameters": {"status_code": "303",
"location": "localhost"}}]})");
"location": "https://localhost"}}]})");
e->update(update, meta, metrics);
}

Expand Down
2 changes: 1 addition & 1 deletion appsec/tests/helper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ std::string create_sample_rules_ok()
"id": "redirect",
"type": "redirect_request",
"parameters": {
"location": "localhost"
"location": "https://localhost"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@

#include "../../common.hpp"
#include "../mocks.hpp"
#include "base64.h"
#include "engine.hpp"
#include "json_helper.hpp"
#include "remote_config/exception.hpp"
#include "remote_config/listeners/engine_listener.hpp"
#include "remote_config/product.hpp"
#include "subscriber/waf.hpp"
#include <memory>
#include <rapidjson/writer.h>

const std::string waf_rule =
R"({"version":"2.1","rules":[{"id":"1","name":"rule1","tags":{"type":"flow1","category":"category1"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg1","key_path":[]}],"regex":".*"}}]}]})";
R"({"version":"2.1","rules":[{"id":"1","name":"rule1","tags":{"type":"flow1","category":"category1"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg1","key_path":[]}],"regex":".*"}}]},{"id":"2","name":"rule2","tags":{"type":"flow2","category":"category2"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"dummy","key_path":[]}],"regex":".*"}}]}]})";

namespace dds::remote_config {

Expand Down Expand Up @@ -978,7 +976,7 @@ TEST(RemoteConfigEngineListener, EngineRuleOverrideAndActionsUpdate)
}
const std::string update =
R"({"actions": [{"id": "redirect", "type": "redirect_request", "parameters":
{"status_code": "303", "location": "localhost"}}],"rules_override":
{"status_code": "303", "location": "https://localhost"}}],"rules_override":
[{"rules_target": [{"rule_id": "1"}], "on_match": ["redirect"]}]})";

listener.on_update(get_config("ASM", update));
Expand Down

0 comments on commit 16a5999

Please sign in to comment.