-
Notifications
You must be signed in to change notification settings - Fork 13
ADR 013: bolt_agent, Bolt 5.3 #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d3b9a79
ADR 013: bolt_agent, user_agent update, Bolt 5.3
robsdedude 17b26d2
Fix feature flag guards
robsdedude 92e4973
code style
robsdedude b52e142
Fix Windows: use utf-8 for reading files in repo
robsdedude 30f45cd
Merge branch '5.0' into bolt-agent
robsdedude b8b7d3f
Merge branch '5.0' into bolt-agent
robsdedude 1835f7a
Add test case where userAgent == boltAgent
robsdedude 1b4d5a3
Merge branch '5.0' into bolt-agent
robsdedude c0abd43
Expect user_agent to be omitted in test_user_agent_is_bolt_agent
injectives d7c000f
Remove accidentally added comment
robsdedude e894384
Merge branch '5.0' into bolt-agent
robsdedude 1946f58
Adopt tests for structured bolt agent
robsdedude 27263e8
Remove test of empty user_agent (drivers are not unified)
robsdedude b3bc5c8
Merge branch '5.0' into bolt-agent
thelonelyvulpes 7e5000c
Add constraints to product field in bolt_agent
robsdedude 4c7f49a
Fix wrong version numbers
fbiville 1e5f267
Merge branch '5.0' into bolt-agent
robsdedude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
tests/stub/driver_parameters/scripts/v5x2/user_agent_custom.script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!: BOLT 5.2 | ||
|
||
C: HELLO {"[routing]": null, "user_agent": "Hello, I'm a banana 🍌!"} | ||
S: SUCCESS {"server": "Neo4j/5.5.0", "connection_id": "bolt-1"} | ||
C: LOGON {"{}": "*"} | ||
S: SUCCESS {} | ||
*: RESET | ||
C: RUN "*" "*" "*" | ||
S: SUCCESS {"fields": ["n"]} | ||
C: PULL {"n": "*"} | ||
S: RECORD [1] | ||
SUCCESS {"type": "r"} | ||
*: RESET | ||
?: GOODBYE |
14 changes: 14 additions & 0 deletions
14
tests/stub/driver_parameters/scripts/v5x2/user_agent_default.script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!: BOLT 5.2 | ||
|
||
C: HELLO {"[routing]": null, "user_agent": {"U": "*"}} | ||
S: SUCCESS {"server": "Neo4j/5.5.0", "connection_id": "bolt-1"} | ||
C: LOGON {"{}": "*"} | ||
S: SUCCESS {} | ||
*: RESET | ||
C: RUN "*" "*" "*" | ||
S: SUCCESS {"fields": ["n"]} | ||
C: PULL {"n": "*"} | ||
S: RECORD [1] | ||
SUCCESS {"type": "r"} | ||
*: RESET | ||
?: GOODBYE |
14 changes: 14 additions & 0 deletions
14
tests/stub/driver_parameters/scripts/v5x3/user_agent_custom.script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!: BOLT 5.3 | ||
|
||
C: HELLO {"[routing]": null, "user_agent": "Hello, I'm a banana 🍌!", "bolt_agent": {"product": {"U": "*"}, "[platform]": {"U": "*"}, "[language]": {"U": "*"}, "[language_details]": {"U": "*"}}} | ||
S: SUCCESS {"server": "Neo4j/5.9.0", "connection_id": "bolt-1"} | ||
C: LOGON {"{}": "*"} | ||
S: SUCCESS {} | ||
*: RESET | ||
C: RUN "*" "*" "*" | ||
S: SUCCESS {"fields": ["n"]} | ||
C: PULL {"n": "*"} | ||
S: RECORD [1] | ||
SUCCESS {"type": "r"} | ||
*: RESET | ||
?: GOODBYE |
14 changes: 14 additions & 0 deletions
14
tests/stub/driver_parameters/scripts/v5x3/user_agent_default.script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!: BOLT 5.3 | ||
|
||
C: HELLO {"[routing]": null, "user_agent": {"U": "*"}, "bolt_agent": {"product": {"U": "*"}, "[platform]": {"U": "*"}, "[language]": {"U": "*"}, "[language_details]": {"U": "*"}}} | ||
S: SUCCESS {"server": "Neo4j/5.9.0", "connection_id": "bolt-1"} | ||
C: LOGON {"{}": "*"} | ||
S: SUCCESS {} | ||
*: RESET | ||
C: RUN "*" "*" "*" | ||
S: SUCCESS {"fields": ["n"]} | ||
C: PULL {"n": "*"} | ||
S: RECORD [1] | ||
SUCCESS {"type": "r"} | ||
*: RESET | ||
?: GOODBYE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
tests/stub/driver_parameters/test_client_agent_strings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import abc | ||
import json | ||
import re | ||
from contextlib import contextmanager | ||
|
||
import nutkit.protocol as types | ||
from nutkit.frontend import Driver | ||
from tests.shared import TestkitTestCase | ||
from tests.stub.shared import StubServer | ||
|
||
|
||
class _ClientAgentStringsTestBase(TestkitTestCase, abc.ABC): | ||
|
||
@property | ||
@abc.abstractmethod | ||
def version_folder(self) -> str: | ||
... | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self._server = StubServer(9000) | ||
self._driver = None | ||
self._session = None | ||
|
||
def tearDown(self): | ||
self._server.reset() | ||
if self._session: | ||
self._session.close() | ||
if self._driver: | ||
self._driver.close() | ||
return super().tearDown() | ||
|
||
def _start_server(self, script, version_folder=None, vars_=None): | ||
if version_folder is None: | ||
version_folder = self.version_folder | ||
self._server.start(self.script_path(version_folder, script), | ||
vars_=vars_) | ||
|
||
@contextmanager | ||
def driver(self, **kwargs): | ||
auth = types.AuthorizationToken("basic", principal="neo4j", | ||
credentials="pass") | ||
uri = "bolt://%s" % self._server.address | ||
driver = Driver(self._backend, uri, auth, **kwargs) | ||
try: | ||
yield driver | ||
finally: | ||
driver.close() | ||
|
||
@contextmanager | ||
def session(self, driver=None, **driver_kwargs): | ||
if driver is None: | ||
with self.driver(**driver_kwargs) as driver: | ||
session = driver.session("r") | ||
try: | ||
yield session | ||
finally: | ||
session.close() | ||
else: | ||
session = driver.session("r") | ||
try: | ||
yield session | ||
finally: | ||
session.close() | ||
|
||
def _session_run_return_1(self, **driver_kwargs): | ||
with self.session(**driver_kwargs) as session: | ||
result = session.run("RETURN 1 AS n") | ||
list(result) | ||
|
||
def _test_default_user_agent(self): | ||
self._start_server("user_agent_default.script") | ||
self._session_run_return_1() | ||
|
||
def _test_custom_user_agent(self): | ||
self._start_server("user_agent_custom.script") | ||
self._session_run_return_1(user_agent="Hello, I'm a banana 🍌!") | ||
robsdedude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class TestClientAgentStringsV5x2(_ClientAgentStringsTestBase): | ||
|
||
version_folder = "v5x2" | ||
required_features = (types.Feature.BOLT_5_2,) | ||
|
||
def test_default_user_agent(self): | ||
injectives marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super()._test_default_user_agent() | ||
|
||
def test_custom_user_agent(self): | ||
super()._test_custom_user_agent() | ||
|
||
|
||
class TestClientAgentStringsV5x3(_ClientAgentStringsTestBase): | ||
|
||
version_folder = "v5x3" | ||
required_features = (types.Feature.BOLT_5_3,) | ||
|
||
def test_default_user_agent(self): | ||
super()._test_default_user_agent() | ||
|
||
def test_custom_user_agent(self): | ||
super()._test_custom_user_agent() | ||
|
||
def test_bolt_agent(self): | ||
super()._test_default_user_agent() | ||
|
||
hellos = self._server.get_requests("HELLO") | ||
assert len(hellos) == 1 | ||
hello_extra = json.loads(hellos[0].split(maxsplit=1)[1]) | ||
bolt_agent = hello_extra["{}"]["bolt_agent"]["{}"] | ||
self._assert_bolt_agent_product_conforms_format(bolt_agent["product"]) | ||
|
||
self._server.reset() | ||
super()._test_custom_user_agent() | ||
|
||
hellos = self._server.get_requests("HELLO") | ||
assert len(hellos) == 1 | ||
hello_extra = json.loads(hellos[0].split(maxsplit=1)[1]) | ||
# asserts user agent is does not affect bolt agent | ||
assert bolt_agent == hello_extra["{}"]["bolt_agent"]["{}"] | ||
|
||
@staticmethod | ||
def _assert_bolt_agent_product_conforms_format(bolt_agent_product): | ||
assert re.match(r"^.+/.+$", bolt_agent_product) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
!: BOLT 5.3 | ||
|
||
C: HELLO {"{}": "*"} | ||
S: SUCCESS {"server": "#SERVER_AGENT#", "connection_id": "bolt-123456789"} | ||
A: LOGON {"{}": "*"} | ||
*: RESET | ||
{? | ||
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"} | ||
S: SUCCESS {"fields": ["n.name"]} | ||
{{ | ||
C: PULL {"n": {"Z": "*"}} | ||
---- | ||
C: DISCARD {"n": {"Z": "*"}} | ||
}} | ||
S: SUCCESS {"type": "w"} | ||
?} | ||
*: RESET | ||
?: GOODBYE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.