Skip to content

Commit c2fc26f

Browse files
committed
fix: cppcheck duplicated
Signed-off-by: Felipe Zipitria <[email protected]>
1 parent 519d9dc commit c2fc26f

File tree

3 files changed

+70
-77
lines changed

3 files changed

+70
-77
lines changed

test/benchmark/benchmark_rules.cc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "modsecurity/modsecurity.h"
2222
#include "modsecurity/rules_set.h"
2323
#include "modsecurity/transaction.h"
24+
#include "modsec_fixture.h"
2425

2526
using modsecurity::ModSecurity;
2627
using modsecurity::RulesSet;
@@ -49,44 +50,6 @@ static const char* TEST_URI = "/api/users?id=123&name=test&action=update";
4950
static const char* TEST_CLIENT_IP = "203.0.113.45";
5051
static const char* TEST_SERVER_IP = "192.0.2.1";
5152

52-
// Helper class to manage ModSecurity lifecycle
53-
class ModSecFixture {
54-
public:
55-
ModSecurity* modsec;
56-
RulesSet* rules;
57-
58-
ModSecFixture() {
59-
modsec = new ModSecurity();
60-
modsec->setConnectorInformation("ModSecurity-benchmark v1.0");
61-
rules = new RulesSet();
62-
}
63-
64-
~ModSecFixture() {
65-
delete rules;
66-
delete modsec;
67-
}
68-
69-
bool loadRules(const std::string& ruleConfig) {
70-
// Create a temporary rules object for this configuration
71-
RulesSet* tempRules = new RulesSet();
72-
int result = tempRules->load(ruleConfig.c_str());
73-
74-
if (result < 0) {
75-
delete tempRules;
76-
return false;
77-
}
78-
79-
// Replace old rules
80-
delete rules;
81-
rules = tempRules;
82-
return true;
83-
}
84-
85-
Transaction* createTransaction() {
86-
return new Transaction(modsec, rules, nullptr);
87-
}
88-
};
89-
9053
// Helper to run a complete transaction
9154
static void runTransaction(Transaction* trans) {
9255
modsecurity::ModSecurityIntervention intervention;

test/benchmark/benchmark_template.cc

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "modsecurity/modsecurity.h"
2020
#include "modsecurity/rules_set.h"
2121
#include "modsecurity/transaction.h"
22+
#include "modsec_fixture.h"
2223

2324
using modsecurity::ModSecurity;
2425
using modsecurity::RulesSet;
@@ -50,45 +51,6 @@ static const char* MY_REQUEST_BODY = R"({
5051
"tags": ["tag1", "tag2"]
5152
})";
5253

53-
// ============================================================================
54-
// HELPER CLASSES (Same as benchmark_rules.cc)
55-
// ============================================================================
56-
57-
class ModSecFixture {
58-
public:
59-
ModSecurity* modsec;
60-
RulesSet* rules;
61-
62-
ModSecFixture() {
63-
modsec = new ModSecurity();
64-
modsec->setConnectorInformation("ModSecurity-custom-benchmark v1.0");
65-
rules = new RulesSet();
66-
}
67-
68-
~ModSecFixture() {
69-
delete rules;
70-
delete modsec;
71-
}
72-
73-
bool loadRules(const std::string& ruleConfig) {
74-
RulesSet* tempRules = new RulesSet();
75-
int result = tempRules->load(ruleConfig.c_str());
76-
77-
if (result < 0) {
78-
delete tempRules;
79-
return false;
80-
}
81-
82-
delete rules;
83-
rules = tempRules;
84-
return true;
85-
}
86-
87-
Transaction* createTransaction() {
88-
return new Transaction(modsec, rules, nullptr);
89-
}
90-
};
91-
9254
// ============================================================================
9355
// EXAMPLE 1: Benchmark testing a specific header
9456
// ============================================================================

test/benchmark/modsec_fixture.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 - 2025 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
#ifndef TEST_BENCHMARK_MODSEC_FIXTURE_H_
17+
#define TEST_BENCHMARK_MODSEC_FIXTURE_H_
18+
19+
#include <string>
20+
#include "modsecurity/modsecurity.h"
21+
#include "modsecurity/rules_set.h"
22+
#include "modsecurity/transaction.h"
23+
24+
// Helper class to manage ModSecurity lifecycle
25+
class ModSecFixture {
26+
public:
27+
modsecurity::ModSecurity* modsec;
28+
modsecurity::RulesSet* rules;
29+
30+
ModSecFixture() {
31+
modsec = new modsecurity::ModSecurity();
32+
modsec->setConnectorInformation("ModSecurity-benchmark v1.0");
33+
rules = new modsecurity::RulesSet();
34+
}
35+
36+
~ModSecFixture() {
37+
delete rules;
38+
delete modsec;
39+
}
40+
41+
// Delete copy and move operations since we manage raw pointers
42+
ModSecFixture(const ModSecFixture&) = delete;
43+
ModSecFixture& operator=(const ModSecFixture&) = delete;
44+
ModSecFixture(ModSecFixture&&) = delete;
45+
ModSecFixture& operator=(ModSecFixture&&) = delete;
46+
47+
bool loadRules(const std::string& ruleConfig) {
48+
// Create a temporary rules object for this configuration
49+
modsecurity::RulesSet* tempRules = new modsecurity::RulesSet();
50+
int result = tempRules->load(ruleConfig.c_str());
51+
52+
if (result < 0) {
53+
delete tempRules;
54+
return false;
55+
}
56+
57+
// Replace old rules
58+
delete rules;
59+
rules = tempRules;
60+
return true;
61+
}
62+
63+
modsecurity::Transaction* createTransaction() {
64+
return new modsecurity::Transaction(modsec, rules, nullptr);
65+
}
66+
};
67+
68+
#endif // TEST_BENCHMARK_MODSEC_FIXTURE_H_

0 commit comments

Comments
 (0)