tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorg...@apache.org
Subject [03/17] tinkerpop git commit: Abstracted transport out of the authenticator class. Added authenticator and sasl implmentation to global export. Added more testing of the sasl authenticator implementation.
Date Thu, 23 Aug 2018 12:51:43 GMT
Abstracted transport out of the authenticator class.
Added authenticator and sasl implmentation to global export.
Added more testing of the sasl authenticator implementation.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6f65b92e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6f65b92e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6f65b92e

Branch: refs/heads/master
Commit: 6f65b92e7ac92cf4da105d9fef71ac51c6121013
Parents: c8ae3c8
Author: Matthew Allen <matt.allen@runbox.com>
Authored: Mon Jul 9 22:49:41 2018 +0100
Committer: Matthew Allen <matt.allen@runbox.com>
Committed: Thu Aug 23 06:36:58 2018 +0100

----------------------------------------------------------------------
 .../main/javascript/gremlin-javascript/index.js |  6 ++++-
 .../lib/driver/authenticator.js                 |  4 +--
 .../lib/driver/driver-remote-connection.js      | 17 +++++++-----
 .../lib/driver/remote-connection.js             |  4 ++-
 .../lib/driver/sasl-authenticator.js            | 27 +++++---------------
 .../integration/sasl-authentication-tests.js    | 10 +++++++-
 6 files changed, 36 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
index d4c6d88..5ada391 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
@@ -31,13 +31,17 @@ const rc = require('./lib/driver/remote-connection');
 const Bytecode = require('./lib/process/bytecode');
 const utils = require('./lib/utils');
 const DriverRemoteConnection = require('./lib/driver/driver-remote-connection');
+const Auth = require('./lib/driver/authenticator');
+const SaslAuth = require('./lib/driver/sasl-authenticator');
 
 module.exports = {
   driver: {
     RemoteConnection: rc.RemoteConnection,
     RemoteStrategy: rc.RemoteStrategy,
     RemoteTraversal: rc.RemoteTraversal,
-    DriverRemoteConnection: DriverRemoteConnection
+    DriverRemoteConnection: DriverRemoteConnection,
+    Authenticator: Auth,
+    SaslAuthenticator: SaslAuth
   },
   process: {
     Bytecode: Bytecode,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/authenticator.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/authenticator.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/authenticator.js
index 053aecd..fe83077 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/authenticator.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/authenticator.js
@@ -6,9 +6,9 @@ class Authenticator {
     this._credentials = credentials;
   }
   
-  evaluateChallenge(ws, header) {
+  async evaluateChallenge(challenge) {
     throw new Error("evaluateChallenge should be implemented");
   }
 }
 
-module.exports = Authenticator;
\ No newline at end of file
+module.exports = Authenticator;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
index 0f46745..facc0b8 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
@@ -105,24 +105,24 @@ class DriverRemoteConnection extends RemoteConnection {
   }
 
   /** @override */
-  submit(bytecode) {
+  submit(bytecode, op, args) {
     return this.open().then(() => new Promise((resolve, reject) => {
       const requestId = utils.getUuid();
       this._responseHandlers[requestId] = {
         callback: (err, result) => err ? reject(err) : resolve(result),
         result: null
       };
-      const message = bufferFromString(this._header + JSON.stringify(this._getRequest(requestId,
bytecode)));
+      const message = bufferFromString(this._header + JSON.stringify(this._getRequest(requestId,
bytecode, op, args)));
       this._ws.send(message);
     }));
   }
 
-  _getRequest(id, bytecode) {
+  _getRequest(id, bytecode, op, args) {
     return ({
       'requestId': { '@type': 'g:UUID', '@value': id },
-      'op': 'bytecode',
+      'op': op || 'bytecode',
       'processor': 'traversal',
-      'args': {
+      'args': args || {
         'gremlin': this._writer.adaptObject(bytecode),
         'aliases': { 'g': this.traversalSource }
       }
@@ -157,7 +157,12 @@ class DriverRemoteConnection extends RemoteConnection {
     }
 
     if (response.status.code === responseStatusCode.authenticationChallenge && this._authenticator)
{
-       this._authenticator.evaluateChallenge(this._ws, this._header);
+      this._authenticator.evaluateChallenge(response).then(res => {
+        this.submit('', 'authentication', res);
+      }, err => {
+        return handler.callback(err);
+      });
+       
        return;
     }
     else if (response.status.code >= 400) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
index 2672ff4..46918df 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
@@ -33,9 +33,11 @@ class RemoteConnection {
   /**
    * @abstract
    * @param {Bytecode} bytecode
+   * @param {String} op Operation to perform, defaults to bytecode.
+   * @param {Object} args The arguments for the operation. Defaults to
    * @returns {Promise}
    */
-  submit(bytecode) {
+  submit(bytecode, op, args) {
     throw new Error('submit() was not implemented');
   };
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/sasl-authenticator.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/sasl-authenticator.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/sasl-authenticator.js
index 1f08b7d..d7db3de 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/sasl-authenticator.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/sasl-authenticator.js
@@ -1,7 +1,6 @@
 'use strict';
 
 const Authenticator = require('./authenticator');
-const utils = require('../utils');
 
 class SaslAuthenticator extends Authenticator {
   /**
@@ -15,31 +14,17 @@ class SaslAuthenticator extends Authenticator {
     super(credentials);
   }
   
-  evaluateChallenge(ws, header) {
-    const message = bufferFromString(header + JSON.stringify({
-      'requestId': { '@type': 'g:UUID', '@value': utils.getUuid() },
-      'op': 'authentication',
-      'processor': 'traversal',
-      'args': {
-        'sasl': this.saslArgument()
-      }
-    }));
-    
-    return ws.send(message);
+  async evaluateChallenge(challenge) {
+    return Promise.resolve({ 'sasl': this.saslArgument() });
   }
 
   saslArgument() {
-    if (this._credentials.username === null || this._credentials.username.length === 0 
-      || this._credentials.password === null || this._credentials.password.length === 0 )
{
-      return '';
+    if (typeof this._credentials.username === "undefined" || this._credentials.username.length
=== 0 
+      || typeof this._credentials.password === "undefined" || this._credentials.password.length
=== 0 ) {
+        throw new Error('No Credentials Supplied');
     }
     return new Buffer(`\0${this._credentials.username}\0${this._credentials.password}`).toString('base64');
   }
 }
 
-
-const bufferFromString = (Int8Array.from !== Buffer.from && Buffer.from) || function
newBuffer(text) {
-  return new Buffer(text, 'utf8');
-};
-
-module.exports = SaslAuthenticator;
\ No newline at end of file
+module.exports = SaslAuthenticator;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f65b92e/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/sasl-authentication-tests.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/sasl-authentication-tests.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/sasl-authentication-tests.js
index c5dc48f..d517d22 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/sasl-authentication-tests.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/sasl-authentication-tests.js
@@ -55,5 +55,13 @@ describe('DriverRemoteConnectionWithSaslAuthenticator', function () {
           assert.ok(err.message.indexOf('401') > 0);
         });
     });
+    it('should send incorrect conifugration to the authenticator and parse the response error',
function () {
+      delete connection._authenticator.username;
+      delete connection._authenticator.password;
+      return connection.submit(new Bytecode().addStep('V', []).addStep('tail', []))
+        .catch(function (err) {
+          assert.ok(err);
+        });
+    });
   });
-});
\ No newline at end of file
+});


Mime
View raw message