Skip to content

Commit 8c2ba37

Browse files
fzipiCopilot
andcommitted
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a6032bb commit 8c2ba37

4 files changed

Lines changed: 18 additions & 20 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def test_template():
278278
User-Agent: OWASP CRS
279279
method: {{ method }}
280280
port: 80
281-
uri: "{{ uri }}
281+
uri: "{{ uri }}"
282282
output:
283283
log_contains: id "{{ id }}"
284284
"""

tests/test_actions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,17 +1105,17 @@ def test_action_ctl_force_request_body_variable() -> None:
11051105
def test_multiple_actions_combined() -> None:
11061106
"""Test rule with multiple different actions"""
11071107
rule_text = """
1108-
SecRule ARGS "@rx attack" \
1109-
"id:999001,\
1110-
phase:2,\
1111-
deny,\
1112-
status:403,\
1113-
log,\
1114-
msg:'SQL Injection Attempt',\
1115-
severity:CRITICAL,\
1116-
tag:'attack-sqli',\
1117-
setvar:'tx.anomaly_score=+5',\
1118-
t:lowercase,\
1108+
SecRule ARGS "@rx attack" \\
1109+
"id:999001,\\
1110+
phase:2,\\
1111+
deny,\\
1112+
status:403,\\
1113+
log,\\
1114+
msg:'SQL Injection Attempt',\\
1115+
severity:CRITICAL,\\
1116+
tag:'attack-sqli',\\
1117+
setvar:'tx.anomaly_score=+5',\\
1118+
t:lowercase,\\
11191119
t:urlDecode"
11201120
"""
11211121
parsed_rule = parser.process_from_str(rule_text)

tests/test_conftest_examples.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
These examples show how the shared fixtures and helper functions from conftest.py
66
can simplify test code and reduce duplication.
77
8-
Note: The helper functions from conftest.py are automatically available in the test
9-
namespace when using pytest. You can also import them explicitly using:
8+
Note: Fixtures defined in conftest.py are automatically available in the test
9+
namespace when using pytest. Plain helper functions must be imported explicitly,
10+
for example:
1011
from tests.conftest import parse_rule, assert_parse_success, etc.
1112
"""
1213
import pytest
1314

1415
# Import helper functions from conftest.py
15-
# These are automatically available via pytest's conftest mechanism
16-
import sys
17-
import os
18-
sys.path.insert(0, os.path.dirname(__file__))
19-
from conftest import (
16+
# Fixtures are auto-discovered by pytest; helper functions are imported explicitly
17+
from tests.conftest import (
2018
parse_rule,
2119
assert_parse_success,
2220
get_rules_by_type,

tests/test_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_operator_contains_word() -> None:
8383
for rule in parsed_rule.rules:
8484
assert rule.__class__.__name__ == "SecRule"
8585
# containsWord is parsed but STRING may be empty - just verify it exists
86-
if hasattr(rule.operator, 'containsWord'):
86+
if getattr(rule.operator, "containsWord", None) is not None:
8787
matches += 1
8888
assert matches == 1
8989

0 commit comments

Comments
 (0)