Skip to content

Commit 851dfdc

Browse files
committed
Fixes from code review
1 parent fb909a5 commit 851dfdc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

neo4j/v1/session.py

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

50-
def __init__(self, scheme, principal, credentials, realm=None, parameters=None):
50+
def __init__(self, scheme, principal, credentials, realm=None, **parameters):
5151
self.scheme = scheme
5252
self.principal = principal
5353
self.credentials = credentials
@@ -523,7 +523,7 @@ def basic_auth(user, password, realm=None):
523523
return AuthToken("basic", user, password, realm)
524524

525525

526-
def custom_auth(principal, credentials, realm=None, scheme=None, parameters=None):
526+
def custom_auth(principal, credentials, realm, scheme, **parameters):
527527
""" Generate a basic auth token for a given user and password.
528528
529529
:param principal: specifies who is being authenticated
@@ -533,7 +533,7 @@ def custom_auth(principal, credentials, realm=None, scheme=None, parameters=None
533533
:param parameters: parameters passed along to the authenticatin provider
534534
:return: auth token for use with :meth:`GraphDatabase.driver`
535535
"""
536-
return AuthToken(scheme, principal, credentials, realm, parameters)
536+
return AuthToken(scheme, principal, credentials, realm, **parameters)
537537

538538

539539
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)