-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Bolt: Pre-compile regex for rule validation #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -312,6 +312,10 @@ def _api_client() -> httpx.Client: | |||
| ) | ||||
| MAX_RESPONSE_SIZE = 10 * 1024 * 1024 # 10 MB limit for external resources | ||||
|
||||
| MAX_RESPONSE_SIZE = 10 * 1024 * 1024 # 10 MB limit for external resources |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,7 +475,7 @@ | |
|
|
||
| # Case 12: get_validated_input works with getpass | ||
| def test_get_validated_input_password(monkeypatch): | ||
| m = reload_main_with_env(monkeypatch) | ||
Check warningCode scanning / Pylint (reported by Codacy) Variable name "m" doesn't conform to snake_case naming style Warning test
Variable name "m" doesn't conform to snake_case naming style
|
||
|
|
||
| getpass_mock = MagicMock(return_value="secret") | ||
| monkeypatch.setattr("getpass.getpass", getpass_mock) | ||
|
|
@@ -510,3 +510,27 @@ | |
| # Color codes (accessing instance Colors or m.Colors) | ||
| assert m.Colors.CYAN in combined | ||
| assert m.Colors.ENDC in combined | ||
|
|
||
|
|
||
| # Case 14: is_valid_rule logic correctness | ||
| def test_is_valid_rule_logic(monkeypatch): | ||
Check warningCode scanning / Pylint (reported by Codacy) Missing function docstring Warning test
Missing function docstring
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing function or method docstring Warning test
Missing function or method docstring
|
||
| m = reload_main_with_env(monkeypatch) | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Variable name "m" doesn't conform to snake_case naming style Warning test
Variable name "m" doesn't conform to snake_case naming style
|
||
|
|
||
| # Valid rules | ||
| assert m.is_valid_rule("example.com") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("sub.example.com") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("1.2.3.4") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("2001:db8::1") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("192.168.1.0/24") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("example-domain.com") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("example_domain.com") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert m.is_valid_rule("*.example.com") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| # Invalid rules | ||
| assert not m.is_valid_rule("") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule(" ") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule("example.com; rm -rf /") # Injection attempt | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule("<script>alert(1)</script>") # XSS | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule("example.com|cat /etc/passwd") # Shell pipe | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule("example.com&") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert not m.is_valid_rule("$variable") | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Comment on lines
+516
to
+536
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved readability and maintainability, you could refactor this test to use @pytest.mark.parametrize(
("rule", "expected"),
[
# Valid rules
("example.com", True),
("sub.example.com", True),
("1.2.3.4", True),
("2001:db8::1", True),
("192.168.1.0/24", True),
("example-domain.com", True),
("example_domain.com", True),
("*.example.com", True),
# Invalid rules
("", False),
(" ", False),
("example.com; rm -rf /", False),
("<script>alert(1)</script>", False),
("example.com|cat /etc/passwd", False),
("example.com&", False),
("$variable", False),
],
ids=[
"valid domain",
"valid subdomain",
"valid ipv4",
"valid ipv6",
"valid cidr",
"valid with hyphen",
"valid with underscore",
"valid with wildcard",
"invalid empty string",
"invalid space",
"invalid with semicolon",
"invalid with html tag",
"invalid with pipe",
"invalid with ampersand",
"invalid with dollar",
],
)
def test_is_valid_rule_logic(monkeypatch, rule, expected):
m = reload_main_with_env(monkeypatch)
assert m.is_valid_rule(rule) is expected
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date is in the past. The entry is dated 2025-01-28, but based on the PR metadata (created in February 2026), this should be 2026-01-28 to maintain chronological consistency with other entries in this file.