You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2018/08/23 12:51:12 UTC
[11/15] tinkerpop git commit: Added PlainTextSaslAuthenticator helper
and updated the tests to use it.
Added PlainTextSaslAuthenticator helper and updated the tests to use it.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cc57c2b8
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cc57c2b8
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cc57c2b8
Branch: refs/heads/tp32
Commit: cc57c2b886652bcdad127bb0358c9b85156b5156
Parents: 18598ba
Author: Matthew Allen <ma...@runbox.com>
Authored: Mon Aug 13 21:08:25 2018 +0100
Committer: Matthew Allen <ma...@runbox.com>
Committed: Thu Aug 23 06:39:29 2018 +0100
----------------------------------------------------------------------
.../auth/plain-text-sasl-authenticator.js | 53 ++++++++++++++++++++
.../lib/driver/auth/sasl-authenticator.js | 2 +-
.../gremlin-javascript/test/helper.js | 7 ++-
.../integration/sasl-authentication-tests.js | 9 +---
4 files changed, 59 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cc57c2b8/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/plain-text-sasl-authenticator.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/plain-text-sasl-authenticator.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/plain-text-sasl-authenticator.js
new file mode 100644
index 0000000..b8f104d
--- /dev/null
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/plain-text-sasl-authenticator.js
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+'use strict';
+
+const Authenticator = require('./authenticator');
+const SaslMechanismPlain = require('./mechanisms/sasl-mechanism-plain');
+
+class PlainTextSaslAuthenticator extends Authenticator {
+ /**
+ * Creates a new instance of PlainTextSaslAuthenticator.
+ * @param {string} username Username to log into the server.
+ * @param {string} password Password for the user.
+ * @constructor
+ */
+ constructor(username, password, authzid) {
+ const options = {
+ mechanism: new SaslMechanismPlain({
+ 'username': username,
+ 'password': password,
+ 'authzid': authzid
+ })
+ };
+
+ super(options);
+ }
+
+ /**
+ * Evaluates the challenge from the server and returns appropriate response.
+ * @param {String} challenge Challenge string presented by the server.
+ * @return {Object} A Promise that resolves to a valid sasl response object.
+ */
+ evaluateChallenge(challenge) {
+ return this._options.mechanism.evaluateChallenge(challenge);
+ }
+}
+
+module.exports = PlainTextSaslAuthenticator;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cc57c2b8/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/sasl-authenticator.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/sasl-authenticator.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/sasl-authenticator.js
index eb1fbe8..cdf56e1 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/sasl-authenticator.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/auth/sasl-authenticator.js
@@ -23,7 +23,7 @@ class SaslAuthenticator extends Authenticator {
* @return {Object} A Promise that resolves to a valid sasl response object.
*/
evaluateChallenge(challenge) {
- return Promise.resolve(this._options.mechanism.evaluateChallenge(challenge));
+ return this._options.mechanism.evaluateChallenge(challenge);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cc57c2b8/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
index 82c47be..899a8ad 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
@@ -24,15 +24,14 @@
const os = require('os');
const DriverRemoteConnection = require('../lib/driver/driver-remote-connection');
-const SaslAuthenticator = require('../lib/driver/auth/sasl-authenticator');
-const SaslMechanismPlain = require('../lib/driver/auth/mechanisms/sasl-mechanism-plain');
+const PlainTextSaslAuthenticator = require('../lib/driver/auth/plain-text-sasl-authenticator');
exports.getConnection = function getConnection(traversalSource) {
return new DriverRemoteConnection('ws://localhost:45940/gremlin', { traversalSource: traversalSource });
};
-exports.getSecureConnectionWithAuthenticator = function getConnection(traversalSource) {
- const authenticator = new SaslAuthenticator({ mechanism: new SaslMechanismPlain({ username: 'stephen', password: 'password', authzid: os.hostname() }) });
+exports.getSecureConnectionWithPlainTextSaslAuthenticator = function getConnection(traversalSource) {
+ const authenticator = new PlainTextSaslAuthenticator('stephen', 'password');
return new DriverRemoteConnection('ws://localhost:45941/gremlin', {
traversalSource: traversalSource,
authenticator: authenticator,
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cc57c2b8/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 c9450f8..2cf1dff 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
@@ -17,9 +17,6 @@
* under the License.
*/
-/**
- * @author Jorge Bay Gondra
- */
'use strict';
const assert = require('assert');
@@ -29,10 +26,10 @@ const helper = require('../helper');
let connection;
-describe('DriverRemoteConnectionWithSaslAuthenticator', function () {
+describe('DriverRemoteConnectionWithPlainTextSaslAuthenticator', function () {
before(function () {
this.timeout(20000);
- connection = helper.getSecureConnectionWithAuthenticator(null);
+ connection = helper.getSecureConnectionWithPlainTextSaslAuthenticator(null);
return connection.open();
});
after(function () {
@@ -44,8 +41,6 @@ describe('DriverRemoteConnectionWithSaslAuthenticator', function () {
.then(function (response) {
assert.ok(response);
assert.ok(response.traversers);
- //assert.strictEqual(response.traversers.length, 1);
- //assert.ok(response.traversers[0].object instanceof graphModule.Vertex);
});
});
it('should send the request with invalid credentials and parse the response error', function () {