Skip to content

Commit 4d0c42c

Browse files
authored
Suppress InsecureRequestWarning if SSL verification is disabled (#499)
* Suppress InsecureRequestWarning if ssl_verify is False * Extra unit tests for ssl_verify * update changelog --------- Co-authored-by: Michael Chin <chnmch@amazon.com>
1 parent ff49be9 commit 4d0c42c

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
1717
- Changed datatype of "amount" from String to numeric for "Transaction" vertices in Fraud Graph sample notebook ([Link to PR](https://github.com/aws/graph-notebook/pull/489))
1818
- Replaced usages of deprecated DataFrame.append method in ML samples ([Link to PR](https://github.com/aws/graph-notebook/pull/495))
1919
- Set Gremlin as default language for PropertyGraph samples in `%seed` ([Link to PR](https://github.com/aws/graph-notebook/pull/497))
20+
- Suppress InsecureRequestWarning if SSL verification is disabled ([Link to PR](https://github.com/aws/graph-notebook/pull/499))
2021

2122
## Release 3.8.1 (April 17, 2023)
2223
- Reinstate Python 3.7 support for compatibility with legacy AL1 Neptune Notebooks ([Link to PR](https://github.com/aws/graph-notebook/pull/479))

src/graph_notebook/neptune/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99

1010
import requests
11+
import urllib3
1112
from urllib.parse import urlparse, urlunparse
1213
from SPARQLWrapper import SPARQLWrapper
1314
from boto3 import Session
@@ -146,6 +147,8 @@ def __init__(self, host: str, port: int = DEFAULT_PORT, ssl: bool = True, ssl_ve
146147
self.target_port = port
147148
self.ssl = ssl
148149
self.ssl_verify = ssl_verify
150+
if not self.ssl_verify:
151+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
149152
self.sparql_path = sparql_path
150153
self.gremlin_traversal_source = gremlin_traversal_source
151154
self.gremlin_username = gremlin_username

test/unit/configuration/test_configuration.py

+19
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ def test_generate_configuration_override_defaults_neptune_reg(self):
136136
config_from_file = get_config(self.test_file_path)
137137
self.assertEqual(config.to_dict(), config_from_file.to_dict())
138138

139+
def test_generate_configuration_override_defaults_neptune_no_verify(self):
140+
auth_mode = AuthModeEnum.IAM
141+
ssl = True
142+
ssl_verify = False
143+
loader_arn = 'foo'
144+
aws_region = 'us-iso-east-1'
145+
config = Configuration(self.neptune_host_reg, self.port, auth_mode=auth_mode,
146+
load_from_s3_arn=loader_arn,
147+
ssl=ssl, ssl_verify=ssl_verify,
148+
aws_region=aws_region)
149+
150+
c = generate_config(config.host, config.port, auth_mode=config.auth_mode,
151+
load_from_s3_arn=config.load_from_s3_arn,
152+
ssl=config.ssl, ssl_verify=config.ssl_verify,
153+
aws_region=config.aws_region)
154+
c.write_to_file(self.test_file_path)
155+
config_from_file = get_config(self.test_file_path)
156+
self.assertEqual(config.to_dict(), config_from_file.to_dict())
157+
139158
def test_generate_configuration_override_defaults_neptune_cn(self):
140159
auth_mode = AuthModeEnum.IAM
141160
ssl = False

test/unit/configuration/test_configuration_from_main.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_generate_configuration_main_override_defaults_neptune_reg(self):
5252
load_from_s3_arn='loader_arn', ssl=False)
5353
self.generate_config_from_main_and_test(expected_config, host_type='neptune')
5454

55+
def test_generate_configuration_main_override_defaults_neptune_no_verify(self):
56+
expected_config = Configuration(self.neptune_host_reg, self.port, auth_mode=AuthModeEnum.IAM,
57+
load_from_s3_arn='loader_arn', ssl=True, ssl_verify=False)
58+
self.generate_config_from_main_and_test(expected_config, host_type='neptune')
59+
5560
def test_generate_configuration_main_override_defaults_neptune_cn(self):
5661
expected_config = Configuration(self.neptune_host_cn, self.port, auth_mode=AuthModeEnum.IAM,
5762
load_from_s3_arn='loader_arn', ssl=False)
@@ -95,8 +100,11 @@ def generate_config_from_main_and_test(self, source_config: Configuration, host_
95100
# Configuration object we get from the resulting file is what we expect.
96101
if host_type == 'neptune':
97102
result = os.system(f'{self.python_cmd} -m graph_notebook.configuration.generate_config '
98-
f'--host "{source_config.host}" --port "{source_config.port}" '
99-
f'--auth_mode "{source_config.auth_mode.value}" --ssl "{source_config.ssl}" '
103+
f'--host "{source_config.host}" '
104+
f'--port "{source_config.port}" '
105+
f'--auth_mode "{source_config.auth_mode.value}" '
106+
f'--ssl "{source_config.ssl}" '
107+
f'--ssl-verify "{source_config.ssl_verify}" '
100108
f'--load_from_s3_arn "{source_config.load_from_s3_arn}" '
101109
f'--proxy_host "{source_config.proxy_host}" '
102110
f'--proxy_port "{source_config.proxy_port}" '
@@ -106,7 +114,9 @@ def generate_config_from_main_and_test(self, source_config: Configuration, host_
106114
f'--host "{source_config.host}" --port "{source_config.port}" '
107115
f'--proxy_host "{source_config.proxy_host}" '
108116
f'--proxy_port "{source_config.proxy_port}" '
109-
f'--ssl "{source_config.ssl}" --config_destination="{self.test_file_path}" ')
117+
f'--ssl "{source_config.ssl}" '
118+
f'--ssl-verify "{source_config.ssl_verify}" '
119+
f'--config_destination="{self.test_file_path}" ')
110120
self.assertEqual(result, 0)
111121
config = get_config(self.test_file_path)
112122
self.assertEqual(source_config.to_dict(), config.to_dict())

0 commit comments

Comments
 (0)