Skip to content

Commit c003f27

Browse files
authored
Bugfix/disable ssl errors fix (#110)
* fix for --disable-ssl-errors not actually doing anything * update changelog
1 parent d59753f commit c003f27

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
2121

2222
- The `print` command on the `security-data` and `alerts` command groups has been replaced with the `search` command.
2323
This was a name change only, all other functionality remains the same.
24+
25+
- A profile created with the `--disable-ssl-errors` flag will now correctly not verify SSL certs when making requests. A warning message is printed
26+
each time the CLI is run with a profile configured this way, as it is not recommended.
2427

2528
### Added
2629

src/code42cli/sdk_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import py42.sdk
22
import py42.settings
33
import py42.settings.debug as debug
4+
import requests
5+
from click import secho
46
from py42.exceptions import Py42UnauthorizedError
57
from requests.exceptions import ConnectionError
68

@@ -15,6 +17,17 @@
1517
def create_sdk(profile, is_debug_mode):
1618
if is_debug_mode:
1719
py42.settings.debug.level = debug.DEBUG
20+
if profile.ignore_ssl_errors == "True":
21+
secho(
22+
"Warning: Profile '{0}' has SSL verification disabled. Adding certificate verification "
23+
"is strongly advised.".format(profile.name),
24+
fg="red",
25+
err=True,
26+
)
27+
requests.packages.urllib3.disable_warnings(
28+
requests.packages.urllib3.exceptions.InsecureRequestWarning
29+
)
30+
py42.settings.verify_ssl_certs = False
1831
password = profile.get_password()
1932
return validate_connection(profile.authority_url, profile.username, password)
2033

tests/test_sdk_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ def requests_exception(mocker):
2828
return mock_exception
2929

3030

31+
def test_create_sdk_when_profile_has_ssl_errors_disabled_sets_py42_setting_and_prints_warning(
32+
profile, mocker, capsys
33+
):
34+
mock_py42 = mocker.patch("code42cli.sdk_client.py42")
35+
profile.ignore_ssl_errors = "True"
36+
sdk = create_sdk(profile, False)
37+
output = capsys.readouterr()
38+
assert mock_py42.settings.verify_ssl_certs == False
39+
assert (
40+
"Warning: Profile '{0}' has SSL verification disabled. Adding certificate verification is strongly advised.".format(
41+
profile.name
42+
)
43+
in output.err
44+
)
45+
46+
3147
def test_create_sdk_when_py42_exception_occurs_raises_and_logs_cli_error(
3248
sdk_logger, mock_sdk_factory, requests_exception
3349
):

0 commit comments

Comments
 (0)