Skip to content

Commit 4e8c39d

Browse files
committed
Fix for #304
1 parent 6d47577 commit 4e8c39d

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
### Fixed
5+
- Issue [#304](https://github.com/reportportal/agent-python-pytest/issues/304):
6+
SSL certificate flag handling issue, by @HardNorth
7+
8+
## [5.1.0]
9+
### Changed
10+
- Agent complete rewrite, by @HardNorth

pytest_reportportal/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""This module contains class that stores RP agent configuration data."""
22

3+
from distutils.util import strtobool
34
from os import getenv
45

56
try:
@@ -64,7 +65,11 @@ def __init__(self, pytest_config):
6465
'true', '1', 'yes', 'y')
6566
self.rp_uuid = getenv('RP_UUID') or self.find_option(pytest_config,
6667
'rp_uuid')
67-
self.rp_verify_ssl = self.find_option(pytest_config, 'rp_verify_ssl')
68+
rp_verify_ssl = self.find_option(pytest_config, 'rp_verify_ssl', True)
69+
try:
70+
self.rp_verify_ssl = bool(strtobool(rp_verify_ssl))
71+
except (ValueError, AttributeError):
72+
self.rp_verify_ssl = rp_verify_ssl
6873

6974
# noinspection PyMethodMayBeStatic
7075
def find_option(self, pytest_config, option_name, default=None):
@@ -85,4 +90,6 @@ def find_option(self, pytest_config, option_name, default=None):
8590
getattr(pytest_config.option, option_name, None) or
8691
pytest_config.getini(option_name)
8792
)
93+
if isinstance(value, bool):
94+
return value
8895
return value if value else default

pytest_reportportal/config.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _pytest.config import Config as Config
2-
from typing import List, Optional, Text, Union
2+
from typing import List, Optional, Text, Union, Any
33

44
class AgentConfig:
55
rp_rerun: Optional[bool] = ...
@@ -28,8 +28,9 @@ class AgentConfig:
2828
rp_retries: int = ...
2929
rp_skip_connection_test: bool = ...
3030
rp_uuid: Text = ...
31-
rp_verify_ssl: bool = ...
31+
rp_verify_ssl: Union[bool, Text] = ...
3232

3333
def __init__(self, pytest_config: Config) -> None: ...
3434

35-
def find_option(self, pytest_config, param: Text) -> Union[Text, bool, list]: ...
35+
def find_option(self, pytest_config, param: Text,
36+
default: Any = ...) -> Union[Text, bool, list]: ...

tests/unit/test_config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2022 https://reportportal.io .
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License
13+
14+
import pytest
15+
from pytest_reportportal.config import AgentConfig
16+
17+
18+
@pytest.mark.parametrize(
19+
['verify_ssl', 'expected_result'],
20+
[
21+
('True', True),
22+
('False', False),
23+
('true', True),
24+
('false', False),
25+
(True, True),
26+
(False, False),
27+
('path/to/certificate', 'path/to/certificate'),
28+
(None, True)
29+
]
30+
)
31+
def test_verify_ssl_true(mocked_config, verify_ssl, expected_result):
32+
mocked_config.getini.side_effect = \
33+
lambda x: verify_ssl if x == 'rp_verify_ssl' else None
34+
config = AgentConfig(mocked_config)
35+
36+
assert config.rp_verify_ssl == expected_result

0 commit comments

Comments
 (0)