From dc91725ef8dbee0acef7a2b9012871214b3e5a9c Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Mon, 5 Sep 2016 14:44:59 +0200 Subject: [PATCH 1/2] Added support for custom auth tokens --- src/v1/index.js | 16 ++++++++++++++-- test/v1/driver.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/v1/index.js b/src/v1/index.js index d6ba4f2e2..bb7b67a2b 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -31,8 +31,20 @@ export default { isInt, Neo4jError, auth: { - basic: (username, password) => { - return {scheme: "basic", principal: username, credentials: password}; + basic: (username, password, realm = undefined) => { + if (realm) { + return {scheme: "basic", principal: username, credentials: password, realm: realm}; + } else { + return {scheme: "basic", principal: username, credentials: password}; + } + }, + custom: (principal, credentials, realm, scheme = "basic", parameters = undefined ) => { + if (parameters) { + return {scheme: scheme, principal: principal, credentials: credentials, realm: realm, + parameters: parameters} + } else { + return {scheme: scheme, principal: principal, credentials: credentials, realm: realm} + } } }, types: { diff --git a/test/v1/driver.test.js b/test/v1/driver.test.js index 97fc7890a..b6c03af74 100644 --- a/test/v1/driver.test.js +++ b/test/v1/driver.test.js @@ -76,6 +76,32 @@ describe('driver', function() { driver.session(); }); + it('should be possible to create custom auth tokens', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic")); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + + it('should be possible to create custom auth tokens with additional parameters', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic", {secret: 42})); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + var exposedTypes = [ 'Node', 'Path', From 6f0e1506152fbf79a6b257c68d032b53e01490be Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Tue, 6 Sep 2016 11:04:09 +0200 Subject: [PATCH 2/2] Fixes from code review --- src/v1/index.js | 2 +- test/v1/driver.test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/v1/index.js b/src/v1/index.js index bb7b67a2b..bf02c05f3 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -38,7 +38,7 @@ export default { return {scheme: "basic", principal: username, credentials: password}; } }, - custom: (principal, credentials, realm, scheme = "basic", parameters = undefined ) => { + custom: (principal, credentials, realm, scheme, parameters = undefined ) => { if (parameters) { return {scheme: scheme, principal: principal, credentials: credentials, realm: realm, parameters: parameters} diff --git a/test/v1/driver.test.js b/test/v1/driver.test.js index b6c03af74..ef695deb7 100644 --- a/test/v1/driver.test.js +++ b/test/v1/driver.test.js @@ -76,6 +76,19 @@ describe('driver', function() { driver.session(); }); + it('should be possible to pass a realm with basic auth tokens', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j", "native")); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + it('should be possible to create custom auth tokens', function(done) { // Given var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic"));