Skip to content

Commit 05370f8

Browse files
committed
Fixes from code review
1 parent fb909a5 commit 05370f8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

neo4j/v1/session.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class AuthToken(object):
4747
""" Container for auth information
4848
"""
4949

50-
def __init__(self, scheme, principal, credentials, realm=None, parameters=None):
50+
#: By default we should not send any realm
51+
realm = None
52+
53+
def __init__(self, scheme, principal, credentials, realm=None, **parameters):
5154
self.scheme = scheme
5255
self.principal = principal
5356
self.credentials = credentials
@@ -523,7 +526,7 @@ def basic_auth(user, password, realm=None):
523526
return AuthToken("basic", user, password, realm)
524527

525528

526-
def custom_auth(principal, credentials, realm=None, scheme=None, parameters=None):
529+
def custom_auth(principal, credentials, realm, scheme, **parameters):
527530
""" Generate a basic auth token for a given user and password.
528531
529532
:param principal: specifies who is being authenticated
@@ -533,7 +536,7 @@ def custom_auth(principal, credentials, realm=None, scheme=None, parameters=None
533536
:param parameters: parameters passed along to the authenticatin provider
534537
:return: auth token for use with :meth:`GraphDatabase.driver`
535538
"""
536-
return AuthToken(scheme, principal, credentials, realm, parameters)
539+
return AuthToken(scheme, principal, credentials, realm, **parameters)
537540

538541

539542
def run(connection, statement, parameters=None):

test/test_session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def test_fail_nicely_when_connecting_to_http_port(self):
9797
assert str(context.exception) == "Server responded HTTP. Make sure you are not trying to connect to the http " \
9898
"endpoint (HTTP defaults to port 7474 whereas BOLT defaults to port 7687)"
9999

100+
def test_can_provide_realm_with_basic_auth_token(self):
101+
token = basic_auth("neo4j", "neo4j", "native")
102+
driver = GraphDatabase.driver("bolt://localhost", auth=token)
103+
session = driver.session()
104+
result = session.run("RETURN 1").consume()
105+
session.close()
106+
assert result is not None
107+
100108
def test_can_create_custom_auth_token(self):
101109
token = custom_auth("neo4j", "neo4j", "native", "basic")
102110
driver = GraphDatabase.driver("bolt://localhost", auth=token)
@@ -106,7 +114,7 @@ def test_can_create_custom_auth_token(self):
106114
assert result is not None
107115

108116
def test_can_create_custom_auth_token_with_additional_parameters(self):
109-
token = custom_auth("neo4j", "neo4j", "native", "basic", {secret: 42})
117+
token = custom_auth("neo4j", "neo4j", "native", "basic", secret=42)
110118
driver = GraphDatabase.driver("bolt://localhost", auth=token)
111119
session = driver.session()
112120
result = session.run("RETURN 1").consume()

0 commit comments

Comments
 (0)