Skip to content

Commit 22d1684

Browse files
committed
Test socket types
1 parent 2c5577c commit 22d1684

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

neo4j/v1/connection.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,7 @@ def connect(host, port=None, **config):
324324
s = create_connection((host, port))
325325

326326
# Secure the connection if so requested
327-
try:
328-
secure = environ["NEO4J_SECURE"]
329-
except KeyError:
330-
secure = config.get("secure", False)
331-
if secure:
327+
if config.get("secure", False):
332328
if __debug__: log_info("~~ [SECURE] %s", host)
333329
s = secure_socket(s, host)
334330

test/test_session.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# limitations under the License.
2020

2121

22+
from socket import socket
23+
from ssl import SSLSocket
2224
from unittest import TestCase
2325

2426
from mock import patch
@@ -59,9 +61,6 @@ def test_session_that_dies_in_the_pool_will_not_be_given_out(self):
5961
session_2 = driver.session()
6062
assert session_2 is not session_1
6163

62-
63-
class RunTestCase(TestCase):
64-
6564
def test_must_use_valid_url_scheme(self):
6665
with self.assertRaises(ValueError):
6766
GraphDatabase.driver("x://xxx")
@@ -82,6 +81,21 @@ def test_sessions_are_not_reused_if_still_in_use(self):
8281
session_1.close()
8382
assert session_1 is not session_2
8483

84+
def test_insecure_session_uses_insecure_socket(self):
85+
driver = GraphDatabase.driver("bolt://localhost", secure=False)
86+
session = driver.session()
87+
assert isinstance(session.connection.channel.socket, socket)
88+
session.close()
89+
90+
def test_secure_session_uses_secure_socket(self):
91+
driver = GraphDatabase.driver("bolt://localhost", secure=True)
92+
session = driver.session()
93+
assert isinstance(session.connection.channel.socket, SSLSocket)
94+
session.close()
95+
96+
97+
class RunTestCase(TestCase):
98+
8599
def test_can_run_simple_statement(self):
86100
session = GraphDatabase.driver("bolt://localhost").session()
87101
count = 0

0 commit comments

Comments
 (0)