testit-cli 2.4.9__tar.gz → 2.4.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {testit_cli-2.4.9 → testit_cli-2.4.10}/PKG-INFO +1 -1
  2. {testit_cli-2.4.9 → testit_cli-2.4.10}/setup.py +1 -1
  3. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/apiclient.py +9 -0
  4. testit_cli-2.4.10/src/testit_cli/html_escape_utils.py +212 -0
  5. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/PKG-INFO +1 -1
  6. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/SOURCES.txt +1 -0
  7. {testit_cli-2.4.9 → testit_cli-2.4.10}/LICENSE +0 -0
  8. {testit_cli-2.4.9 → testit_cli-2.4.10}/README.md +0 -0
  9. {testit_cli-2.4.9 → testit_cli-2.4.10}/setup.cfg +0 -0
  10. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/__init__.py +0 -0
  11. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/__main__.py +0 -0
  12. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/autotests_filter.py +0 -0
  13. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/click_commands.py +0 -0
  14. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/converter.py +0 -0
  15. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/dir_worker.py +0 -0
  16. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/file_worker.py +0 -0
  17. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/filter_factory.py +0 -0
  18. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/importer.py +0 -0
  19. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/logger.py +0 -0
  20. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/__init__.py +0 -0
  21. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/config.py +0 -0
  22. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/mode.py +0 -0
  23. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/status.py +0 -0
  24. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/testcase.py +0 -0
  25. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/models/testrun.py +0 -0
  26. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/parser.py +0 -0
  27. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/service.py +0 -0
  28. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/service_factory.py +0 -0
  29. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli/validation.py +0 -0
  30. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/dependency_links.txt +0 -0
  31. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/entry_points.txt +0 -0
  32. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/requires.txt +0 -0
  33. {testit_cli-2.4.9 → testit_cli-2.4.10}/src/testit_cli.egg-info/top_level.txt +0 -0
  34. {testit_cli-2.4.9 → testit_cli-2.4.10}/tests/test_click.py +0 -0
  35. {testit_cli-2.4.9 → testit_cli-2.4.10}/tests/test_service.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testit-cli
3
- Version: 2.4.9
3
+ Version: 2.4.10
4
4
  Summary: This tool is the command line wrapper of Test IT allowing you to upload the test results in real time to Test IT
5
5
  Home-page: https://pypi.org/project/testit-cli/
6
6
  Author: Integration team
@@ -1,6 +1,6 @@
1
1
  from setuptools import find_packages, setup
2
2
 
3
- VERSION = "2.4.9"
3
+ VERSION = "2.4.10"
4
4
 
5
5
  setup(
6
6
  name='testit-cli',
@@ -11,6 +11,7 @@ from testit_api_client.models import TestResultShortResponse
11
11
 
12
12
  from .converter import Converter
13
13
  from .models.testrun import TestRun
14
+ from .html_escape_utils import HtmlEscapeUtils
14
15
 
15
16
 
16
17
  class ApiClient:
@@ -34,6 +35,7 @@ class ApiClient:
34
35
  def create_test_run(self, project_id: str, name: str) -> TestRun:
35
36
  """Function creates test run and returns test run id."""
36
37
  model = CreateEmptyTestRunApiModel(project_id=project_id, name=name)
38
+ model = HtmlEscapeUtils.escape_html_in_object(model)
37
39
  logging.debug(f"Creating test run with model: {model}")
38
40
 
39
41
  test_run = self.__test_run_api.create_empty(model)
@@ -46,6 +48,7 @@ class ApiClient:
46
48
  def update_test_run(self, test_run: TestRun):
47
49
  """Function updates test run."""
48
50
  model = Converter.test_run_to_update_empty_request(test_run)
51
+ model = HtmlEscapeUtils.escape_html_in_object(model)
49
52
  logging.debug(f"Updating test run with model: {model}")
50
53
 
51
54
  self.__test_run_api.update_empty(model)
@@ -86,6 +89,8 @@ class ApiClient:
86
89
 
87
90
  def create_autotest(self, model: Converter.test_result_to_create_autotest_request):
88
91
  """Function creates autotest and returns autotest id."""
92
+ model = HtmlEscapeUtils.escape_html_in_object(model)
93
+
89
94
  logging.debug(f"Creating autotest {model}")
90
95
 
91
96
  response = self.__autotest_api.create_auto_test(auto_test_post_model=model)
@@ -97,6 +102,8 @@ class ApiClient:
97
102
  def update_autotest(self, model: Converter.test_result_to_update_autotest_request):
98
103
  """Function updates autotest"""
99
104
  try:
105
+ model = HtmlEscapeUtils.escape_html_in_object(model)
106
+
100
107
  logging.debug(f"Updating autotest {model}")
101
108
 
102
109
  self.__autotest_api.update_auto_test(auto_test_put_model=model)
@@ -110,6 +117,8 @@ class ApiClient:
110
117
  ):
111
118
  """Function sends autotest result to test run"""
112
119
  try:
120
+ model = HtmlEscapeUtils.escape_html_in_object(model)
121
+
113
122
  logging.debug(f"Adding autotest results to testrun {testrun_id}: {model}")
114
123
 
115
124
  self.__test_run_api.set_auto_test_results_for_test_run(
@@ -0,0 +1,212 @@
1
+ import os
2
+ import re
3
+ import logging
4
+ from typing import Any, List, Optional
5
+ from datetime import datetime, date, time, timedelta
6
+ from decimal import Decimal
7
+ from uuid import UUID
8
+
9
+
10
+ class HtmlEscapeUtils:
11
+ """
12
+ HTML escape utilities for preventing XSS attacks.
13
+ Escapes HTML tags in strings and objects using reflection.
14
+ """
15
+
16
+ NO_ESCAPE_HTML_ENV_VAR = "NO_ESCAPE_HTML"
17
+
18
+ # Regex pattern to detect HTML tags (requires at least one non-whitespace character after <)
19
+ # This ensures empty <> brackets are not considered HTML tags
20
+ _HTML_TAG_PATTERN = re.compile(r'<\S.*?(?:>|/>)')
21
+
22
+ # Regex patterns to escape only non-escaped characters
23
+ # Using negative lookbehind to avoid double escaping
24
+ _LESS_THAN_PATTERN = re.compile(r'(?<!\\)<')
25
+ _GREATER_THAN_PATTERN = re.compile(r'(?<!\\)>')
26
+
27
+ @staticmethod
28
+ def escape_html_tags(text: Optional[str]) -> Optional[str]:
29
+ """
30
+ Escapes HTML tags to prevent XSS attacks.
31
+ First checks if the string contains HTML tags using regex pattern.
32
+ Only performs escaping if HTML tags are detected.
33
+ Escapes all < as \\< and > as \\> only if they are not already escaped.
34
+ Uses regex with negative lookbehind to avoid double escaping.
35
+
36
+ Args:
37
+ text: The text to escape
38
+
39
+ Returns:
40
+ Escaped text or original text if escaping is disabled
41
+ """
42
+ if text is None:
43
+ return None
44
+
45
+ # Check if escaping is disabled via environment variable
46
+ no_escape_html = os.environ.get(HtmlEscapeUtils.NO_ESCAPE_HTML_ENV_VAR, "").lower()
47
+ if no_escape_html == "true":
48
+ return text
49
+
50
+ # First check if the string contains HTML tags
51
+ if not HtmlEscapeUtils._HTML_TAG_PATTERN.search(text):
52
+ return text # No HTML tags found, return original string
53
+
54
+ # Use regex with negative lookbehind to escape only non-escaped characters
55
+ result = HtmlEscapeUtils._LESS_THAN_PATTERN.sub(r'\\<', text)
56
+ result = HtmlEscapeUtils._GREATER_THAN_PATTERN.sub(r'\\>', result)
57
+
58
+ return result
59
+
60
+ @staticmethod
61
+ def escape_html_in_object(obj: Any) -> Any:
62
+ """
63
+ Escapes HTML tags in all string attributes of an object using reflection.
64
+ Also processes list attributes: if list of objects - calls escape_html_in_object_list,
65
+ if list of strings - escapes each string.
66
+ Can be disabled by setting NO_ESCAPE_HTML environment variable to "true".
67
+
68
+ Args:
69
+ obj: The object to process
70
+
71
+ Returns:
72
+ The processed object with escaped strings
73
+ """
74
+ if obj is None:
75
+ return None
76
+
77
+ # Check if escaping is disabled via environment variable
78
+ no_escape_html = os.environ.get(HtmlEscapeUtils.NO_ESCAPE_HTML_ENV_VAR, "").lower()
79
+ if no_escape_html == "true":
80
+ return obj
81
+
82
+ try:
83
+ HtmlEscapeUtils._process_object_attributes(obj)
84
+ except Exception as e:
85
+ # Silently ignore reflection errors
86
+ logging.debug(f"Error processing object attributes: {e}")
87
+
88
+ return obj
89
+
90
+ @staticmethod
91
+ def escape_html_in_object_list(obj_list: Optional[List[Any]]) -> Optional[List[Any]]:
92
+ """
93
+ Escapes HTML tags in all string attributes of objects in a list using reflection.
94
+ Can be disabled by setting NO_ESCAPE_HTML environment variable to "true".
95
+
96
+ Args:
97
+ obj_list: The list of objects to process
98
+
99
+ Returns:
100
+ The processed list with escaped strings in all objects
101
+ """
102
+ if obj_list is None:
103
+ return None
104
+
105
+ # Check if escaping is disabled via environment variable
106
+ no_escape_html = os.environ.get(HtmlEscapeUtils.NO_ESCAPE_HTML_ENV_VAR, "").lower()
107
+ if no_escape_html == "true":
108
+ return obj_list
109
+
110
+ for obj in obj_list:
111
+ HtmlEscapeUtils.escape_html_in_object(obj)
112
+
113
+ return obj_list
114
+
115
+ @staticmethod
116
+ def _process_object_attributes(obj: Any) -> None:
117
+ """
118
+ Process all attributes of an object for HTML escaping.
119
+ """
120
+ # Handle dictionary-like objects (common in API models)
121
+ if hasattr(obj, '__dict__'):
122
+ for attr_name in dir(obj):
123
+ # Skip private/protected attributes and methods
124
+ if attr_name.startswith('_') or callable(getattr(obj, attr_name, None)):
125
+ continue
126
+
127
+ try:
128
+ value = getattr(obj, attr_name)
129
+ HtmlEscapeUtils._process_attribute_value(obj, attr_name, value)
130
+ except Exception as e:
131
+ # Silently ignore attribute errors
132
+ logging.debug(f"Error processing attribute {attr_name}: {e}")
133
+
134
+ # Handle dictionary objects
135
+ elif isinstance(obj, dict):
136
+ for key, value in obj.items():
137
+ if isinstance(value, str):
138
+ obj[key] = HtmlEscapeUtils.escape_html_tags(value)
139
+ elif isinstance(value, list):
140
+ HtmlEscapeUtils._process_list(value)
141
+ elif not HtmlEscapeUtils._is_simple_type(type(value)):
142
+ HtmlEscapeUtils.escape_html_in_object(value)
143
+
144
+ @staticmethod
145
+ def _process_attribute_value(obj: Any, attr_name: str, value: Any) -> None:
146
+ """
147
+ Process a single attribute value for HTML escaping.
148
+ """
149
+ if isinstance(value, str):
150
+ # Escape string attributes
151
+ try:
152
+ setattr(obj, attr_name, HtmlEscapeUtils.escape_html_tags(value))
153
+ except AttributeError:
154
+ # Attribute might be read-only
155
+ pass
156
+ elif isinstance(value, list):
157
+ HtmlEscapeUtils._process_list(value)
158
+ elif value is not None and not HtmlEscapeUtils._is_simple_type(type(value)):
159
+ # Process nested objects (but not simple types)
160
+ HtmlEscapeUtils.escape_html_in_object(value)
161
+
162
+ @staticmethod
163
+ def _process_list(lst: List[Any]) -> None:
164
+ """
165
+ Process a list for HTML escaping.
166
+ """
167
+ if not lst:
168
+ return
169
+
170
+ first_element = lst[0]
171
+
172
+ if isinstance(first_element, str):
173
+ # List of strings - escape each string
174
+ for i, item in enumerate(lst):
175
+ if isinstance(item, str):
176
+ lst[i] = HtmlEscapeUtils.escape_html_tags(item)
177
+ elif first_element is not None:
178
+ # List of objects - process each object
179
+ for item in lst:
180
+ HtmlEscapeUtils.escape_html_in_object(item)
181
+
182
+ @staticmethod
183
+ def _is_simple_type(obj_type: type) -> bool:
184
+ """
185
+ Checks if a type is a simple type that doesn't need HTML escaping.
186
+
187
+ Args:
188
+ obj_type: Type to check
189
+
190
+ Returns:
191
+ True if it's a simple type
192
+ """
193
+ simple_types = {
194
+ # Basic types
195
+ bool, int, float, complex, bytes, bytearray,
196
+ # String type (handled separately)
197
+ str,
198
+ # Date/time types
199
+ datetime, date, time, timedelta,
200
+ # Other common types
201
+ Decimal, UUID,
202
+ # None type
203
+ type(None)
204
+ }
205
+
206
+ return (
207
+ obj_type in simple_types or
208
+ # Check for enums
209
+ (hasattr(obj_type, '__bases__') and any(
210
+ base.__name__ == 'Enum' for base in obj_type.__bases__
211
+ ))
212
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testit-cli
3
- Version: 2.4.9
3
+ Version: 2.4.10
4
4
  Summary: This tool is the command line wrapper of Test IT allowing you to upload the test results in real time to Test IT
5
5
  Home-page: https://pypi.org/project/testit-cli/
6
6
  Author: Integration team
@@ -10,6 +10,7 @@ src/testit_cli/converter.py
10
10
  src/testit_cli/dir_worker.py
11
11
  src/testit_cli/file_worker.py
12
12
  src/testit_cli/filter_factory.py
13
+ src/testit_cli/html_escape_utils.py
13
14
  src/testit_cli/importer.py
14
15
  src/testit_cli/logger.py
15
16
  src/testit_cli/parser.py
File without changes
File without changes
File without changes