Skip to content

Commit 1b04f03

Browse files
4.0 handshake testing (#357)
* Added unit test for exceptions * Fixed Bolt.open error message * added stubtests for handshake negotiation of different bolt protocol versions * integration tests are skipped if the bolt protocol version is not supported by the driver. * Removed unused import * Removed assert on repr of exception * Enabled python 3.8 in test
1 parent 16fa03c commit 1b04f03

33 files changed

+639
-276
lines changed

neo4j/io/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
BoltRoutingError,
7171
BoltSecurityError,
7272
BoltProtocolError,
73+
BoltHandshakeError,
7374
)
7475
from neo4j.exceptions import (
7576
ServiceUnavailable,
@@ -168,7 +169,7 @@ def open(cls, address, *, auth=None, timeout=None, **config):
168169
:return:
169170
"""
170171
config = PoolConfig.consume(config)
171-
s, config.protocol_version = connect(address, timeout=timeout, config=config)
172+
s, config.protocol_version, handshake, data = connect(address, timeout=timeout, config=config)
172173

173174
if config.protocol_version == (3, 0):
174175
from neo4j.io._bolt3 import Bolt3
@@ -180,7 +181,9 @@ def open(cls, address, *, auth=None, timeout=None, **config):
180181
log.debug("[#%04X] S: <CLOSE>", s.getpeername()[1])
181182
s.shutdown(SHUT_RDWR)
182183
s.close()
183-
raise BoltProtocolError("Driver does not support Bolt protocol version: 0x%06X%02X", config.protocol_version[0], config.protocol_version[1])
184+
185+
supported_versions = Bolt.protocol_handlers().keys()
186+
raise BoltHandshakeError("The Neo4J server does not support communication with this driver. This driver have support for Bolt Protocols {}".format(supported_versions), address=address, request_data=handshake, response_data=data)
184187

185188
connection.hello()
186189
return connection
@@ -849,7 +852,7 @@ def _handshake(s, resolved_address):
849852
"(looks like HTTP)".format(resolved_address))
850853
agreed_version = data[-1], data[-2]
851854
log.debug("[#%04X] S: <HANDSHAKE> 0x%06X%02X", local_port, agreed_version[1], agreed_version[0])
852-
return s, agreed_version
855+
return s, agreed_version, handshake, data
853856

854857

855858
def connect(address, *, timeout=None, config):

tests/integration/aio/conftest.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
22-
from pytest import fixture
21+
import pytest
2322

2423
from neo4j.aio import Bolt, BoltPool
24+
from neo4j._exceptions import BoltHandshakeError
2525

2626

27-
@fixture
27+
@pytest.fixture
2828
async def bolt(address, auth):
29-
bolt = await Bolt.open(address, auth=auth)
30-
yield bolt
31-
await bolt.close()
29+
try:
30+
bolt = await Bolt.open(address, auth=auth)
31+
yield bolt
32+
await bolt.close()
33+
except BoltHandshakeError as error:
34+
pytest.skip(error.args[0])
3235

3336

34-
@fixture
37+
@pytest.fixture
3538
async def bolt_pool(address, auth):
36-
pool = await BoltPool.open(address, auth=auth)
37-
yield pool
38-
await pool.close()
39+
try:
40+
pool = await BoltPool.open(address, auth=auth)
41+
yield pool
42+
await pool.close()
43+
except BoltHandshakeError as error:
44+
pytest.skip(error.args[0])

0 commit comments

Comments
 (0)