-
Notifications
You must be signed in to change notification settings - Fork 1
π‘οΈ Sentinel: [CRITICAL] Fix syntax error in input validation #421
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Missing module docstring Warning test
Missing module docstring
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing module docstring Warning test
Missing module docstring
|
||||||||||||||||||||||||||||||||||||||||||||
| from unittest.mock import MagicMock | ||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Add root to path to import main | ||||||||||||||||||||||||||||||||||||||||||||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import main | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Import "import main" should be placed at the top of the module (wrong-import-position) Warning test
Import "import main" should be placed at the top of the module (wrong-import-position)
Check warningCode scanning / Pylint (reported by Codacy) Import "import main" should be placed at the top of the module Warning test
Import "import main" should be placed at the top of the module
Check warningCode scanning / Pylintpython3 (reported by Codacy) Import "import main" should be placed at the top of the module Warning test
Import "import main" should be placed at the top of the module
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| class TestFixBrokenValidation(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Missing class docstring Warning test
Missing class docstring
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing class docstring Warning test
Missing class docstring
|
||||||||||||||||||||||||||||||||||||||||||||
| def setUp(self): | ||||||||||||||||||||||||||||||||||||||||||||
| self.original_log = main.log | ||||||||||||||||||||||||||||||||||||||||||||
| main.log = MagicMock() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def tearDown(self): | ||||||||||||||||||||||||||||||||||||||||||||
| main.log = self.original_log | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def test_invalid_rule_type_in_rule_groups(self): | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| Verify that validate_folder_data correctly identifies and rejects | ||||||||||||||||||||||||||||||||||||||||||||
| non-dict rules inside rule_groups. | ||||||||||||||||||||||||||||||||||||||||||||
| This tests the fix for the broken syntax block. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| # Data with invalid rule (string instead of dict) inside rule_groups | ||||||||||||||||||||||||||||||||||||||||||||
| invalid_data = { | ||||||||||||||||||||||||||||||||||||||||||||
| "group": {"group": "Test Group"}, | ||||||||||||||||||||||||||||||||||||||||||||
| "rule_groups": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "rules": [ | ||||||||||||||||||||||||||||||||||||||||||||
| {"PK": "valid.com"}, | ||||||||||||||||||||||||||||||||||||||||||||
| "invalid_string_rule" # Should trigger the error | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| result = main.validate_folder_data(invalid_data, "http://test.com") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| self.assertFalse(result, "Should return False for invalid rule type") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Verify the error log message | ||||||||||||||||||||||||||||||||||||||||||||
| # We expect: "Invalid data from http://test.com: rule_groups[0].rules[1] must be an object." | ||||||||||||||||||||||||||||||||||||||||||||
| main.log.error.assert_called() | ||||||||||||||||||||||||||||||||||||||||||||
| found = False | ||||||||||||||||||||||||||||||||||||||||||||
| for call in main.log.error.call_args_list: | ||||||||||||||||||||||||||||||||||||||||||||
| if "rule_groups[0].rules[1] must be an object" in call[0][0]: | ||||||||||||||||||||||||||||||||||||||||||||
| found = True | ||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||
| self.assertTrue(found, "Did not find expected error message for invalid rule type") | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+50
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 conciseness, you can replace this loop with a more Pythonic approach using self.assertTrue(
any("rule_groups[0].rules[1] must be an object" in call[0][0] for call in main.log.error.call_args_list),
"Did not find expected error message for invalid rule type") |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def test_invalid_rules_list_type(self): | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check warningCode scanning / Prospector (reported by Codacy) over-indented (E117) Warning test
over-indented (E117)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| Verify that if 'rules' is not a list, it is caught. | ||||||||||||||||||||||||||||||||||||||||||||
| This tests the fix for the malformed logging block above the loop. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| invalid_data = { | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| "group": {"group": "Test Group"}, | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation (add 1 space). Warning test
Wrong hanging indentation (add 1 space).
|
||||||||||||||||||||||||||||||||||||||||||||
| "rule_groups": [ | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation (add 1 space). Warning test
Wrong hanging indentation (add 1 space).
|
||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "rules": "not_a_list" # Should trigger error | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| result = main.validate_folder_data(invalid_data, "http://test.com") | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| self.assertFalse(result) | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| main.log.error.assert_called() | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| found = False | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| for call in main.log.error.call_args_list: | ||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
|
||||||||||||||||||||||||||||||||||||||||||||
| if "rule_groups[0].rules must be a list" in call[0][0]: | ||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 13 spaces, expected 12 Note test
Bad indentation. Found 13 spaces, expected 12
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 13 spaces, expected 12 (bad-indentation) Warning test
Bad indentation. Found 13 spaces, expected 12 (bad-indentation)
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 13 spaces, expected 12 Note test
Bad indentation. Found 13 spaces, expected 12
|
||||||||||||||||||||||||||||||||||||||||||||
| found = True | ||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 Note test
Bad indentation. Found 17 spaces, expected 16
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 Note test
Bad indentation. Found 17 spaces, expected 16
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 (bad-indentation) Warning test
Bad indentation. Found 17 spaces, expected 16 (bad-indentation)
|
||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 Note test
Bad indentation. Found 17 spaces, expected 16
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 Note test
Bad indentation. Found 17 spaces, expected 16
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 17 spaces, expected 16 (bad-indentation) Warning test
Bad indentation. Found 17 spaces, expected 16 (bad-indentation)
|
||||||||||||||||||||||||||||||||||||||||||||
| self.assertTrue(found, "Did not find expected error message for invalid rules list type") | ||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Pylint (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 Note test
Bad indentation. Found 9 spaces, expected 8
Check warningCode scanning / Prospector (reported by Codacy) Bad indentation. Found 9 spaces, expected 8 (bad-indentation) Warning test
Bad indentation. Found 9 spaces, expected 8 (bad-indentation)
Comment on lines
+53
to
+75
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. This test method has inconsistent indentation (9 spaces instead of the standard 8 for this level). Additionally, the loop for checking the log message can be simplified. This suggestion corrects the indentation to follow PEP 8 and uses """
Verify that if 'rules' is not a list, it is caught.
This tests the fix for the malformed logging block above the loop.
"""
invalid_data = {
"group": {"group": "Test Group"},
"rule_groups": [
{
"rules": "not_a_list" # Should trigger error
}
]
}
result = main.validate_folder_data(invalid_data, "http://test.com")
self.assertFalse(result)
main.log.error.assert_called()
self.assertTrue(
any("rule_groups[0].rules must be a list" in call[0][0] for call in main.log.error.call_args_list),
"Did not find expected error message for invalid rules list type") |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| def test_valid_rule_groups(self): | |
| """ | |
| Verify that valid rule_groups with dict rules are accepted. | |
| This ensures that the validation logic does not reject correct inputs. | |
| """ | |
| valid_data = { | |
| "group": {"group": "Test Group"}, | |
| "rule_groups": [ | |
| { | |
| "rules": [ | |
| {"PK": "example.com"}, | |
| {"PK": "test.com", "status": "active"} | |
| ] | |
| } | |
| ] | |
| } | |
| result = main.validate_folder_data(valid_data, "http://test.com") | |
| self.assertTrue(result, "Should return True for valid rule_groups") |
Check warning
Code scanning / Prospector (reported by Codacy)
expected 2 blank lines after class or function definition, found 1 (E305) Warning test
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (108/100) Warning