Skip to content

Commit c761614

Browse files
authored
Merge pull request #138 from iivanou/ssl_verification
Add ability to disable SSL verification
2 parents ec861ac + 31febaf commit c761614

File tree

8 files changed

+67
-15
lines changed

8 files changed

+67
-15
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ NOT REQUIRED:
8080
--variable RP_ATTACH_XUNIT:"True"
8181
- Default value is "False", attaches Robot Framework XUnit result file to
8282
the launch.
83+
--variable RP_VERIFY_SSL:"True"
84+
- Default value is "True", disables SSL verification for HTTP requests.
85+
Also, you can specify a full path to your certificate as the value.
8386
```
8487

8588
Custom logger which supports attachments can be used in Python keywords.

robotframework_reportportal/listener.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def service(self):
103103
uuid=self.variables.uuid,
104104
log_batch_size=self.variables.log_batch_size,
105105
pool_size=self.variables.pool_size,
106-
skipped_issue=self.variables.skipped_issue
106+
skipped_issue=self.variables.skipped_issue,
107+
verify_ssl=self.variables.verify_ssl
107108
)
108109
return self._service
109110

robotframework_reportportal/service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _get_launch_attributes(self, cmd_attrs):
6868
return attributes + _dict_to_payload(system_attributes)
6969

7070
def init_service(self, endpoint, project, uuid, log_batch_size, pool_size,
71-
skipped_issue=True):
71+
skipped_issue=True, verify_ssl=True):
7272
"""Initialize common reportportal client.
7373
7474
:param endpoint: Report Portal API endpoint
@@ -78,6 +78,7 @@ def init_service(self, endpoint, project, uuid, log_batch_size, pool_size,
7878
:param pool_size: HTTPAdapter max pool size
7979
:param skipped_issue Mark skipped test items with 'To Investigate',
8080
default value 'True'
81+
:param verify_ssl: Disable SSL verification
8182
"""
8283
if self.rp is None:
8384
logger.debug(
@@ -90,7 +91,9 @@ def init_service(self, endpoint, project, uuid, log_batch_size, pool_size,
9091
token=uuid,
9192
log_batch_size=log_batch_size,
9293
max_pool_size=pool_size,
93-
is_skipped_an_issue=skipped_issue)
94+
is_skipped_an_issue=skipped_issue,
95+
verify_ssl=verify_ssl
96+
)
9497
else:
9598
raise RobotServiceException(
9699
'RobotFrameworkService is already initialized.')

robotframework_reportportal/service.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from logging import Logger
22
from reportportal_client.service import ReportPortalService
33
from .model import Keyword as Keyword, Launch as Launch, LogMessage as LogMessage, Suite as Suite, Test as Test
4-
from typing import List, Optional, Text
4+
from typing import List, Optional, Text, Union
55

66
logger: Logger
77

@@ -13,7 +13,7 @@ class RobotService:
1313
rp: Optional[ReportPortalService] = ...
1414
def __init__(self) -> None: ...
1515
def _get_launch_attributes(self, cmd_attrs: List) -> List: ...
16-
def init_service(self, endpoint: Text, project: Text, uuid: Text, log_batch_size: int, pool_size: int, skipped_issue:bool) -> None: ...
16+
def init_service(self, endpoint: Text, project: Text, uuid: Text, log_batch_size: int, pool_size: int, skipped_issue: bool, verify_ssl: Union[Text, bool]) -> None: ...
1717
def terminate_service(self) -> None: ...
1818
def start_launch(self, launch: Launch, mode: Optional[Text] = ..., rerun: bool = ...,
1919
rerun_of: Optional[Text] = ..., ts: Optional[Text] = ..., skip_analytics: Optional[bool] = ...) -> Text: ...

robotframework_reportportal/variables.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
limitations under the License.
1313
"""
1414

15-
from os import getenv
15+
from os import getenv, path
1616
from distutils.util import strtobool
1717

1818
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
@@ -145,3 +145,11 @@ def uuid(self):
145145
'Missing parameter RP_UUID for robot run\n'
146146
'You should pass -v RP_UUID:<uuid_value>')
147147
return self._uuid
148+
149+
@property
150+
def verify_ssl(self):
151+
"""Get value of the verify_ssl parameter for the client."""
152+
verify_ssl = get_variable('RP_VERIFY_SSL', default='True')
153+
if path.exists(verify_ssl):
154+
return verify_ssl
155+
return bool(strtobool(verify_ssl))

robotframework_reportportal/variables.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
from typing import Dict, List, Optional, Text
1+
from typing import Dict, List, Optional, Text, Union
22

33
_variables: Dict
44

55
def get_variable(name: Text, default: Optional[Text] = ...) -> Optional[Text]: ...
66

77
class Variables:
8+
_endpoint: Optional[Text] = ...
9+
_launch_name: Optional[Text] = ...
10+
_pabot_pool_id: Optional[int] = ...
11+
_pabot_used: Optional[Text] = ...
12+
_project: Optional[Text] = ...
13+
_uuid: Optional[Text] = ...
814
attach_log: bool = ...
915
attach_report: bool = ...
1016
attach_xunit: bool = ...
@@ -27,8 +33,10 @@ class Variables:
2733
@property
2834
def pabot_pool_id(self) -> int: ...
2935
@property
30-
def pabot_used(self) -> Optional[str]: ...
36+
def pabot_used(self) -> Optional[Text]: ...
3137
@property
3238
def project(self) -> Text: ...
3339
@property
3440
def uuid(self) -> Text: ...
41+
@property
42+
def verify_ssl(self) -> Union[bool, Text]: ...

tests/unit/conftest.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from six.moves import mock
2020

2121
from robotframework_reportportal.listener import listener
22+
from robotframework_reportportal.variables import Variables
2223
from robotframework_reportportal.result_visitor import RobotResultsVisitor
2324

2425

@@ -27,13 +28,15 @@ def visitor():
2728
return RobotResultsVisitor()
2829

2930

31+
@mock.patch('robotframework_reportportal.variables.strtobool', mock.Mock())
32+
@mock.patch('robotframework_reportportal.variables.get_variable', mock.Mock())
3033
@fixture()
3134
def mock_variables():
32-
mock_variables = mock.Mock()
33-
mock_variables.endpoint = "http://localhost:8080"
34-
mock_variables.launch_name = "Robot"
35-
mock_variables.project = "default_personal"
36-
mock_variables.uuid = "test_uuid"
35+
mock_variables = Variables()
36+
mock_variables._endpoint = "http://localhost:8080"
37+
mock_variables._launch_name = "Robot"
38+
mock_variables._project = "default_personal"
39+
mock_variables._uuid = "test_uuid"
3740
mock_variables.launch_attributes = ''
3841
mock_variables.launch_id = None
3942
mock_variables.launch_doc = None
@@ -43,7 +46,7 @@ def mock_variables():
4346
mock_variables.skip_analytics = None
4447
mock_variables.test_attributes = []
4548
mock_variables.skip_analytics = True
46-
mock_variables.pabot_used = None
49+
mock_variables._pabot_used = False
4750
mock_variables.skipped_issue = True
4851
return mock_variables
4952

tests/unit/test_listener.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,37 @@ def test_skipped_issue_variable_bypass(self, mock_client_init,
123123
mock_variables.skipped_issue = skipped_issue_value
124124
mock_listener = listener()
125125
mock_listener._variables = mock_variables
126-
mock_listener.service
126+
_ = mock_listener.service
127127
assert mock_client_init.call_count == 1
128128
args, kwargs = mock_client_init.call_args
129129
assert kwargs['is_skipped_an_issue'] == skipped_issue_value
130130

131+
@mock.patch('robotframework_reportportal.variables.get_variable')
132+
@mock.patch(REPORT_PORTAL_SERVICE)
133+
@pytest.mark.parametrize(
134+
'get_var_value, verify_ssl_value, path_exists_value', [
135+
('True', True, False),
136+
('False', False, False),
137+
('/path/to/cert', '/path/to/cert', True)
138+
])
139+
def test_verify_ssl_variable_bypass(self,
140+
mock_client_init,
141+
get_var_mock,
142+
mock_variables,
143+
get_var_value,
144+
verify_ssl_value,
145+
path_exists_value):
146+
"""Test case for the RP_VERIFY_SSL bypass."""
147+
get_var_mock.return_value = get_var_value
148+
with mock.patch('robotframework_reportportal.variables.path.exists',
149+
return_value=path_exists_value):
150+
mock_listener = listener()
151+
mock_listener._variables = mock_variables
152+
_ = mock_listener.service
153+
assert mock_client_init.call_count == 1
154+
args, kwargs = mock_client_init.call_args
155+
assert kwargs['verify_ssl'] == verify_ssl_value
156+
131157
@mock.patch(REPORT_PORTAL_SERVICE)
132158
def test_test_case_id(self, mock_client_init, mock_listener,
133159
test_attributes):

0 commit comments

Comments
 (0)