gremlin-aws-sigv4
Advanced tools
Comparing version 3.4.8 to 3.5.1
const debug = require('debug')('gremlin-aws-sigv4:driver'); | ||
const gremlin = require('gremlin'); | ||
const request = require('request'); | ||
const { getUrlAndHeaders, uuid } = require('../utils'); | ||
const { getUrlAndHeaders, uuid, request } = require('../utils'); | ||
@@ -40,5 +39,7 @@ class AwsSigV4DriverRemoteConnection extends gremlin.driver.RemoteConnection { | ||
debug(`get Neptune status: ${JSON.stringify(url, headers)} (try #${this.try})`); | ||
request.get({ url, headers, timeout: 3000 }, (error, response, body) => { | ||
this._statusCallback(error, response, body); | ||
}); | ||
request( | ||
url, | ||
{ headers, timeout: 3000 }, | ||
(err, response, body) => { this._statusCallback(err, response, body); }, | ||
); | ||
} | ||
@@ -45,0 +46,0 @@ |
/* eslint-disable no-bitwise */ | ||
const aws4 = require('aws4'); | ||
const crypto = require('crypto'); | ||
const debug = require('debug')('gremlin-aws-sigv4:utils'); | ||
const aws4 = require('aws4'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
@@ -59,4 +61,23 @@ /** | ||
/** | ||
* Callbackify native http(s) get | ||
*/ | ||
const request = (url, options, cb) => { | ||
debug(`Requesting: ${url}`); | ||
(url.match('https://') ? https.get : http.get)(url, options, (response) => { | ||
let body = ''; | ||
response.on('data', (d) => { | ||
body += d; | ||
}); | ||
response.on('end', () => { | ||
cb(null, response, body); | ||
}); | ||
}) | ||
.on('error', (err) => { | ||
cb(err, null, null); | ||
}); | ||
}; | ||
module.exports = { | ||
uuid, getUrlAndHeaders, | ||
uuid, getUrlAndHeaders, request, | ||
}; |
{ | ||
"name": "gremlin-aws-sigv4", | ||
"version": "3.4.8", | ||
"version": "3.5.1", | ||
"main": "index.js", | ||
@@ -27,13 +27,13 @@ "scripts": { | ||
"dependencies": { | ||
"aws4": "^1.10.1", | ||
"aws4": "^1.11.0", | ||
"debug": "^4.2.0", | ||
"gremlin": "^3.4.8", | ||
"request": "2.88.0" | ||
"gremlin": "^3.5.1" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^8.2.0", | ||
"eslint": "^7.11.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"jest": "^26.5.3" | ||
"dotenv": "^8.6.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.25.3", | ||
"jest": "^26.6.3", | ||
"nock": "^13.2.1" | ||
}, | ||
@@ -40,0 +40,0 @@ "jest": { |
@@ -0,6 +1,11 @@ | ||
/* eslint-disable-line no-new */ | ||
const gremlin = require('gremlin'); | ||
const request = require('request'); | ||
const utils = require('../../../lib/utils'); | ||
const AwsSigV4DriverRemoteConnection = require('../../../lib/driver/aws-sigv4-driver-remote-connection'); | ||
request.get = jest.fn(); | ||
jest.mock('gremlin'); | ||
jest.mock('../../../lib/utils', () => ({ | ||
...jest.requireActual('../../../lib/utils'), | ||
request: jest.fn(), | ||
})); | ||
@@ -18,2 +23,11 @@ const HOST = 'aws.dev.gremlin'; | ||
jest.resetAllMocks(); | ||
gremlin.driver.Client.mockImplementation((url) => ({ | ||
_connection: { | ||
url, | ||
on: jest.fn(), | ||
_ws: { | ||
on: jest.fn(), | ||
}, | ||
}, | ||
})); | ||
}); | ||
@@ -30,3 +44,3 @@ | ||
const connection = new AwsSigV4DriverRemoteConnection(HOST, PORT, OPTS); | ||
expect(connection.url).toEqual(`ws://${HOST}:${PORT}/gremlin`); | ||
expect(connection.options).toEqual(OPTS); | ||
}); | ||
@@ -37,8 +51,3 @@ }); | ||
it('should make a get request to the /status endpoint and connect the socket if successful', () => { | ||
request.get.mockImplementation(({ url }, callback) => { | ||
if (url === `http://${HOST}:${PORT}/status`) { | ||
callback(null, { statusCode: 200 }, null); | ||
} | ||
}); | ||
// eslint-disable-next-line no-new | ||
utils.request.mockImplementation((url, options, cb) => { cb(null, { statusCode: 200 }, 'hello world'); }); | ||
const connection = new AwsSigV4DriverRemoteConnection(HOST, PORT, OPTS); | ||
@@ -49,8 +58,3 @@ expect(connection).toHaveProperty('_client'); | ||
it('should make a get request to the /status endpoint using secure HTTPS if secure is set', () => { | ||
request.get.mockImplementation(({ url }, callback) => { | ||
if (url === `https://${HOST}:${PORT}/status`) { | ||
callback(null, { statusCode: 200 }, null); | ||
} | ||
}); | ||
// eslint-disable-next-line no-new | ||
utils.request.mockImplementation((url, options, cb) => { cb(null, { statusCode: 200 }, 'hello world'); }); | ||
const connection = new AwsSigV4DriverRemoteConnection(HOST, PORT, { ...OPTS, secure: true }); | ||
@@ -61,8 +65,3 @@ expect(connection).toHaveProperty('_client'); | ||
it('should make a get request to the /status endpoint and throw an error if not sucessful', () => { | ||
request.get.mockImplementation(({ url }, callback) => { | ||
if (url === `http://${HOST}:${PORT}/status`) { | ||
callback(null, { statusCode: 403 }, null); | ||
} | ||
}); | ||
// eslint-disable-next-line no-new | ||
utils.request.mockImplementation((url, options, cb) => { cb(null, { statusCode: 403 }, 'hello world'); }); | ||
expect(() => new AwsSigV4DriverRemoteConnection(HOST, PORT, OPTS)).toThrow(); | ||
@@ -239,613 +238,1 @@ }); | ||
}); | ||
// jest.mock('websocket', () => ({ | ||
// client: jest.fn().mockImplementation(() => ({ | ||
// connect: function connect() { | ||
// this.topics.connect({ | ||
// on: jest.fn(), | ||
// send: jest.fn(), | ||
// close: jest.fn(), | ||
// }); | ||
// }, | ||
// topics: {}, | ||
// on: function on(topic, callback) { | ||
// this.topics[topic] = callback; | ||
// }, | ||
// })), | ||
// })); | ||
// describe('AwsSigV4DriverRemoteConnection', () => { | ||
// describe('constructor', () => { | ||
// it('should accept options', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// expect(connection.isOpen).toEqual(true); | ||
// }); | ||
// it('should accept traversalSource', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// traversalSource: 'o', | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.traversalSource).toEqual('o'); | ||
// }); | ||
// it('should require host and port', () => { | ||
// expect(() => { | ||
// const connection = new AwsSigV4DriverRemoteConnection(); | ||
// expect(connection).toEqual(undefined); | ||
// }).toThrow('Host and port are required'); | ||
// }); | ||
// it('should require access key and secret', () => { | ||
// expect(() => { | ||
// const connection = new AwsSigV4DriverRemoteConnection('host', 1337); | ||
// expect(connection).toEqual(undefined); | ||
// }).toThrow('Access key and secret key are required'); | ||
// }); | ||
// it('should resolve the open promise if exist on connection', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// connection._openCallback = jest.fn(); | ||
// connection._connected(connection._socket); | ||
// expect(connection._openCallback).toHaveBeenCalled(); | ||
// }); | ||
// }); | ||
// describe('open', () => { | ||
// let connection; | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// beforeEach(() => { | ||
// connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// }); | ||
// it('should expect socket was opened in the constructor', () => connection.open() | ||
// .then((result) => { | ||
// expect(result).toEqual(undefined); | ||
// })); | ||
// it('should not re-open if alredy open', () => { | ||
// connection.isOpen = false; | ||
// setTimeout(() => { | ||
// connection._openCallback(); | ||
// }, 100); | ||
// return connection.open() | ||
// .then(() => connection.open()) | ||
// .then((result) => { | ||
// expect(result).toEqual(undefined); | ||
// }); | ||
// }); | ||
// it('should reject when error on connection', () => { | ||
// connection.isOpen = false; | ||
// const error = new Error('_openCallback error'); | ||
// setTimeout(() => { | ||
// connection._openCallback(error); | ||
// }, 100); | ||
// return connection.open() | ||
// .catch((ex) => { | ||
// expect(ex).toEqual(error); | ||
// }); | ||
// }); | ||
// }); | ||
// describe('submit', () => { | ||
// let connection; | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// beforeEach(() => { | ||
// connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// }); | ||
// it('should submit', () => { | ||
// // simulate request is called back | ||
// setTimeout(() => { | ||
// const requests = Object.keys(connection._responseHandlers); | ||
// expect(requests.length).toEqual(1); | ||
// Object.keys(connection._responseHandlers).forEach((id) => { | ||
// connection._responseHandlers[id].callback(null, 'stuff'); | ||
// }); | ||
// }, 200); | ||
// const bytecode = 'placeholder'; | ||
// return connection.submit(bytecode) | ||
// .then((result) => { | ||
// expect(result).toEqual('stuff'); | ||
// expect(connection._socket.send).toHaveBeenCalled(); | ||
// }); | ||
// }); | ||
// }); | ||
// describe('_handleMessage', () => { | ||
// let connection; | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// beforeEach(() => { | ||
// connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// }); | ||
// it('should handle data with undefined request id', () => { | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// foo: 'bar', | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// }); | ||
// it('should handle serialization issues', () => { | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'anything', | ||
// result: ['here'], | ||
// }; | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// foo: 'bar', | ||
// status: { | ||
// code: 500, | ||
// message: 'Something happened', | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// }); | ||
// it('should handle serialization issues', () => { | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'anything', | ||
// result: ['here'], | ||
// }; | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// foo: 'bar', | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// }); | ||
// it('should handle if handlers are gone', () => { | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 200, | ||
// }, | ||
// result: { | ||
// data: 'stuff', | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// expect(connection._responseHandlers.abc).toEqual(undefined); | ||
// }); | ||
// it('should handle success', () => { | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 200, | ||
// }, | ||
// result: { | ||
// data: 'stuff', | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'full', | ||
// result: [], | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual('full'); | ||
// expect(connection._responseHandlers.abc).toEqual(undefined); | ||
// }); | ||
// it('should defualt to success', () => { | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 302, | ||
// }, | ||
// result: { | ||
// data: 'stuff', | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'full', | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual('full'); | ||
// expect(connection._responseHandlers.abc).toEqual(undefined); | ||
// }); | ||
// it('should handle no content', () => { | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'pea', | ||
// result: [], | ||
// }; | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 204, | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual('pea'); | ||
// expect(connection._responseHandlers.abc).toEqual(undefined); | ||
// }); | ||
// it('should handle partial content', () => { | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'anything', | ||
// result: ['here'], | ||
// }; | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 206, | ||
// }, | ||
// result: { | ||
// data: [1, 'foo', 'bar'], | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// expect(connection._responseHandlers.abc).not.toEqual(undefined); | ||
// expect(connection._responseHandlers.abc.result).toEqual(['here', 1, 'foo', 'bar']); | ||
// }); | ||
// it('should handle partial content starting with empty result', () => { | ||
// connection._responseHandlers.abc = { | ||
// callback: () => 'anything', | ||
// }; | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: 'abc', | ||
// status: { | ||
// code: 206, | ||
// }, | ||
// result: { | ||
// data: [1, 'foo', 'bar'], | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// expect(connection._responseHandlers.abc).not.toEqual(undefined); | ||
// expect(connection._responseHandlers.abc.result).toEqual([1, 'foo', 'bar']); | ||
// }); | ||
// it('should handle errors', (done) => { | ||
// const submitPromise = connection.submit('a'); | ||
// setTimeout(() => { | ||
// const requests = Object.keys(connection._responseHandlers); | ||
// const data = { | ||
// binaryData: { | ||
// toString: () => JSON.stringify({ | ||
// requestId: requests[0], | ||
// status: { | ||
// code: 400, | ||
// message: 'Bad requestroo', | ||
// }, | ||
// result: { | ||
// // data: [1, 'foo', 'bar'] | ||
// }, | ||
// }), | ||
// }, | ||
// }; | ||
// const result = connection._handleMessage(data); | ||
// expect(result).toEqual(undefined); | ||
// expect(connection._responseHandlers.abc).toEqual(undefined); | ||
// submitPromise | ||
// .then(() => { | ||
// throw new Error('should not succeed'); | ||
// }) | ||
// .catch((err) => { | ||
// expect(err.message).toEqual('Server error: Bad requestroo (400)'); | ||
// done(); | ||
// }); | ||
// }); | ||
// }, 100); | ||
// }); | ||
// describe('close', () => { | ||
// let connection; | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// beforeEach(() => { | ||
// connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// }); | ||
// it('should close the socket', () => { | ||
// connection.close(); | ||
// expect(connection._socket.close).toHaveBeenCalled(); | ||
// expect(connection.isOpen).toEqual(true); | ||
// }); | ||
// it('should set open to false if there was no socket', () => { | ||
// delete connection._socket; | ||
// connection.close(); | ||
// expect(connection.isOpen).toEqual(false); | ||
// }); | ||
// }); | ||
// describe('_disconnected', () => { | ||
// it('should set the isOpen flag to false when disconnecting', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.isOpen).toEqual(true); | ||
// connection._disconnected(); | ||
// expect(connection.isOpen).toEqual(false); | ||
// }); | ||
// }); | ||
// describe('_connectionFailed', () => { | ||
// it('should try to reconnect when autoReconnect is set to true', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// expect(connection.try).toEqual(0); | ||
// connection._connectionFailed(new Error()); | ||
// expect(connection.try).toEqual(1); | ||
// }); | ||
// it('should not try to reconnect when autoReconnect is set to false', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: false, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// connection._openCallback = jest.fn(); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// const error = new Error('_connectionFailed error'); | ||
// connection._connectionFailed(error); | ||
// expect(connection._openCallback).toHaveBeenLastCalledWith(error); | ||
// }); | ||
// it('should not try to reconnect when max connection retries is reached', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// maxRetry: -1, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// connection._openCallback = undefined; | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// const error = new Error('_connectionFailed error'); | ||
// connection._connectionFailed(error); | ||
// }); | ||
// it('should call callback function with error on socket connection failure', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// maxRetry: -1, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// connection._openCallback = jest.fn(); | ||
// const error = new Error('connectFailed event error'); | ||
// connection.client.topics.connectFailed(error); | ||
// expect(connection._openCallback).toHaveBeenLastCalledWith(error); | ||
// }); | ||
// }); | ||
// describe('_connectionError', () => { | ||
// it('should try to reconnect when autoReconnect is set to true', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// expect(connection.try).toEqual(0); | ||
// connection._connectionError(new Error()); | ||
// expect(connection.try).toEqual(1); | ||
// }); | ||
// it('should not try to reconnect when autoReconnect is set to false', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: false, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// const error = new Error('_connectionError error'); | ||
// expect(() => { connection._connectionError(error); }).toThrow(error); | ||
// }); | ||
// it('should not try to reconnect when max connection retries is reached', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// autoReconnect: true, | ||
// maxRetry: -1, | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// expect(connection.url).toEqual(`ws://${host}:${port}/gremlin`); | ||
// expect(connection.traversalSource).toEqual('g'); | ||
// const error = new Error('_connectionError error'); | ||
// expect(() => { connection._connectionError(error); }).toThrow(error); | ||
// }); | ||
// }); | ||
// describe('socket events', () => { | ||
// class SocketMock extends EventEmitter { } | ||
// test('socket events', () => { | ||
// const host = 'local.host'; | ||
// const port = 1337; | ||
// const opts = { | ||
// accessKey: 'MY_ACCESS_KEY', | ||
// secretKey: 'MY_SECRET_KEY', | ||
// region: 'MY_REGION', | ||
// }; | ||
// const connection = new AwsSigV4DriverRemoteConnection(host, port, opts); | ||
// const socket = new SocketMock(); | ||
// connection._connected(socket); | ||
// connection._disconnected = jest.fn(); | ||
// socket.emit('close'); | ||
// expect(connection._disconnected).toHaveBeenCalled(); | ||
// connection._handleMessage = jest.fn(); | ||
// const message = {}; | ||
// socket.emit('message', message); | ||
// expect(connection._handleMessage).toHaveBeenLastCalledWith(message); | ||
// connection._connectionError = jest.fn(); | ||
// const error = new Error('socket event error'); | ||
// socket.emit('error', error); | ||
// expect(connection._connectionError).toHaveBeenCalledWith(error); | ||
// }); | ||
// }); | ||
// }); |
@@ -0,3 +1,14 @@ | ||
const nock = require('nock'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
const httpGetSpy = jest.spyOn(http, 'get'); | ||
const httpsGetSpy = jest.spyOn(https, 'get'); | ||
const utils = require('../../lib/utils'); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
describe('utils', () => { | ||
@@ -83,2 +94,53 @@ describe('uuid', () => { | ||
}); | ||
describe('request', () => { | ||
const httpHost = 'http://localhost'; | ||
const httpsHost = 'https://localhost'; | ||
it('should use http for http requests', async () => { | ||
nock(httpHost).get('/').reply(200, 'ok'); | ||
const result = await new Promise((resolve) => { | ||
utils.request(`${httpHost}/`, {}, (error, response, body) => { | ||
resolve({ error, response, body }); | ||
}); | ||
}); | ||
expect(result.error).toBeNull(); | ||
expect(result.response).not.toBeNull(); | ||
expect(result.body).not.toBeNull(); | ||
expect(result.response.socket.remotePort).toEqual(80); | ||
}); | ||
it('should use https for https requests', async () => { | ||
nock(httpsHost).get('/').reply(200, 'ok'); | ||
const result = await new Promise((resolve) => { | ||
utils.request(`${httpsHost}/`, {}, (error, response, body) => { | ||
resolve({ error, response, body }); | ||
}); | ||
}); | ||
expect(result.error).toBeNull(); | ||
expect(result.response).not.toBeNull(); | ||
expect(result.body).not.toBeNull(); | ||
expect(result.response.socket.remotePort).toEqual(443); | ||
}); | ||
it('should pass errors to callback function', async () => { | ||
nock(httpsHost).get('/').replyWithError('oops'); | ||
const result = await new Promise((resolve) => { | ||
utils.request(`${httpsHost}/`, {}, (error, response, body) => { | ||
resolve({ error, response, body }); | ||
}); | ||
}); | ||
expect(result.error).not.toBeNull(); | ||
expect(result.response).toBeNull(); | ||
expect(result.body).toBeNull(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
28334
6
574
4
- Removedrequest@2.88.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@1.4.12.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.4.3(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedaws4@^1.11.0
Updatedgremlin@^3.5.1