-
Notifications
You must be signed in to change notification settings - Fork 152
[validations] fix: prevent cifmw_validations_xml_filter hang #4000
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
Open
hgoelredhat
wants to merge
1
commit into
main
Choose a base branch
from
fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
roles/validations/tests/unit/plugins/filter/test_cifmw_validations_xml_filter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/python3 | ||
| # Copyright (c) 2026 Red Hat, Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import pytest | ||
| import sys | ||
| import xml.etree.ElementTree as ET | ||
|
|
||
| sys.path.insert(0, 'roles/validations/filter_plugins') | ||
| from cifmw_validations_xml_filter import FilterModule | ||
|
|
||
|
|
||
| class TestFilterReturnType: | ||
| """Tests to verify the filter works correctly""" | ||
|
|
||
| def setup_method(self): | ||
| self.filter_module = FilterModule() | ||
| self.filter_func = self.filter_module.filters()['cifmw_validations_xml_filter'] | ||
|
|
||
| def test_returns_format(self): | ||
| """Verify filter returns str format, not bytes.""" | ||
| result = self.filter_func({}) | ||
| assert isinstance(result, str), "Filter must return str, not bytes!" | ||
|
|
||
| def test_empty_results(self): | ||
| """Verify filter generates valid XML with empty test results.""" | ||
| result = self.filter_func({}) | ||
| assert isinstance(result, str) | ||
| assert 'tests="0"' in result | ||
|
|
||
| def test_single_passing_test(self): | ||
| """Verify filter correctly formats a single passing test case.""" | ||
| result = self.filter_func({"test-1": {"time": 1.5}}) | ||
| assert isinstance(result, str) | ||
| assert 'tests="1"' in result | ||
| assert 'failures="0"' in result | ||
|
|
||
| def test_single_failing_test(self): | ||
| """Verify filter correctly formats a single failing test case.""" | ||
| result = self.filter_func({"test-1": {"time": 1.0, "error": "Test failed"}}) | ||
| assert 'failures="1"' in result | ||
|
|
||
| def test_multiple_mixed_tests(self): | ||
| """Verify filter correctly formats multiple passing and failing tests.""" | ||
| result = self.filter_func({ | ||
| "test-1": {"time": 1.0}, | ||
| "test-2.yml": {"time": 2.0, "error": "failed"}, | ||
| "test-3.yaml": {"time": 1.5} | ||
| }) | ||
| assert 'tests="3"' in result | ||
| assert 'failures="1"' in result | ||
|
|
||
| def test_valid_xml_output(self): | ||
| """Verify filter generates valid, parseable XML with correct structure.""" | ||
| result = self.filter_func({"test-1": {"time": 1.0, "error": "err"}, "test-2": {"time": 2.0}}) | ||
| root = ET.fromstring(result) | ||
| assert root.tag == 'testsuites' | ||
| ts = root.find('testsuite') | ||
| assert ts.attrib['tests'] == '2' | ||
| assert ts.attrib['failures'] == '1' | ||
|
|
||
|
|
||
| class TestMalformedInput: | ||
| """Tests to verify filter handles edge cases and malformed input gracefully""" | ||
|
|
||
| def setup_method(self): | ||
| self.filter_module = FilterModule() | ||
| self.filter_func = self.filter_module.filters()['cifmw_validations_xml_filter'] | ||
|
|
||
| def test_missing_time_field(self): | ||
| """Verify filter handles test results with missing time field.""" | ||
| result = self.filter_func({"test-1": {"error": "some error"}, "test-2": {"time": 1.5}}) | ||
| assert isinstance(result, str) | ||
| assert 'tests="2"' in result | ||
|
|
||
| def test_very_long_error_message(self): | ||
| """Verify filter handles very long error messages (5000+ characters).""" | ||
| long_error = "x" * 5000 | ||
| result = self.filter_func({"test-1": {"time": 1.0, "error": long_error}}) | ||
| assert isinstance(result, str) | ||
| root = ET.fromstring(result) | ||
| assert root is not None | ||
|
|
||
| def test_xml_special_characters_in_error(self): | ||
| """Verify filter properly escapes XML special characters in error messages.""" | ||
| result = self.filter_func({"test-1": {"time": 1.0, "error": "<tag> & special > chars"}}) | ||
| assert isinstance(result, str) | ||
| root = ET.fromstring(result) | ||
| assert root is not None | ||
|
|
||
| def test_unicode_characters(self): | ||
| """Verify filter handles unicode characters in test names and messages.""" | ||
| result = self.filter_func({"test-unicode": {"time": 1.0, "error": "Error message"}}) | ||
| assert isinstance(result, str) | ||
| assert 'tests="1"' in result | ||
|
|
||
| def test_large_number_of_tests(self): | ||
| """Verify filter performs well with large number of test cases (100+).""" | ||
| large_test_data = {f"test-{i}": {"time": 0.1 * i} for i in range(100)} | ||
| result = self.filter_func(large_test_data) | ||
| assert isinstance(result, str) | ||
| assert 'tests="100"' in result | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.