Skip to content

Commit 63ca7a0

Browse files
committed
Test socket types
1 parent b070622 commit 63ca7a0

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
@@ -60,9 +62,6 @@ def test_session_that_dies_in_the_pool_will_not_be_given_out(self):
6062
session_2 = driver.session()
6163
assert session_2 is not session_1
6264

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

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

0 commit comments

Comments
 (0)