New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

beady-eye

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beady-eye - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

spec/LambdaConnectionTest.testBehaviour.spec.ts

48

lambda/connection-tester.js
// lambda connection tester
'use strict';
var net = require('net');
/**

@@ -16,33 +16,47 @@ * Test connection to a destination host/port.

*/
exports.connect = function(event, context, callback) {
if (!event || !event.endpointAddress || !event.endpointPort) {
return callback(new Error("Connection failed. Event data missing"));
return callback(new Error("Invalid call: Event data missing"));
}
if (!isInt(event.endpointPort)) {
return callback(new Error('Connection failed. Event data malformed: "destinationPort" should be an integer'));
return callback(new Error('Invalid call: Event data malformed: "destinationPort" should be an integer'));
}
var socket = new require('net').Socket().setTimeout(1000);
var connectionSuccessful = false;
var timeoutRef = undefined;
var socket = net.createConnection(event.endpointPort, event.endpointAddress);
socket.on('error', function() {
clearTimeout(timeoutRef);
socket.end();
fail(event, context, callback);
}).on('timeout', function() {
socket.end();
fail(event, context, callback);
fail(event, callback);
});
socket.connect(event.endpointPort, event.endpointAddress, function() {
socket.end();
callback(null, {
result: true
});
})
socket.on('connect', function() {
clearTimeout(timeoutRef);
try{
socket.end();
} catch (e) {
socket.destroy();
}
callback(null, {result: true});
});
if (event.connectionTimeout_ms) {
timeoutRef = setTimeout(function() {
try{
socket.end();
} catch (e) {
console.log('Error ending socket');
console.log(e);
}
console.log('Destroying socket after timeout')
socket.destroy();
callback(null, {result: false});
}, event.connectionTimeout_ms);
}
};
function fail(event, context, callback) {
function fail(event, callback) {
const util = require('util');

@@ -49,0 +63,0 @@ var msg = util.format("Connection failed to %s:%s", event.endpointAddress, event.endpointPort)

{
"name": "beady-eye",
"version": "0.6.0",
"version": "0.7.0",
"description": "",

@@ -5,0 +5,0 @@ "main": ".build/src/index.js",

@@ -52,4 +52,21 @@ import { LambdaConnectionTester } from '../src/ConnectionTesters'

InvocationType: 'RequestResponse',
Payload: '{"endpointAddress":"mythical.host","endpointPort":31337}'
Payload: '{"endpointAddress":"mythical.host","endpointPort":31337,"connectionTimeout_ms":1234}'
};
await lambdaConnectionTester.tryConnectionTo(endpointAddress, 1234)
expect(mock.calledOnce).toEqual(true);
expect(mock.calledWith(expectedParams)).toEqual(true);
})
it("should pass through a defaulted timeout parameter if it is missing", async () => {
// test that the payload is correct:
// - endpoint
// - invocation type
// - function name
const mock = sinon.spy(callbackSuccessReturning(lambdaResponseData.successResult));
AWSMock.mock('Lambda','invoke',mock)
const expectedParams = {
FunctionName: 'ConnectionTestFunctionName',
InvocationType: 'RequestResponse',
Payload: '{"endpointAddress":"mythical.host","endpointPort":31337,"connectionTimeout_ms":2000}'
};
await lambdaConnectionTester.tryConnectionTo(endpointAddress)

@@ -56,0 +73,0 @@ expect(mock.calledOnce).toEqual(true);

@@ -57,15 +57,2 @@ import { Credentials } from 'aws-sdk'

tryConnection(port, address, timeout_ms) {
let p = new Promise((resolve, reject) => {
let s = net.createConnection(port, address);
s.on('connect', () => { s.destroy(); resolve(true)} );
s.on('error', () => { s.destroy(); reject(false)} );
// If there has been no response, naturally terminate the socket/promise
setTimeout(() => {s.destroy(); reject(false)}, timeout_ms);
});
return p;
}
toString() {

@@ -72,0 +59,0 @@ return `${this.typeName}: ${this.name}`;

@@ -22,3 +22,4 @@ import { Lambda as AwsLambda } from 'aws-sdk'

endpointAddress: endpoint.address,
endpointPort: endpoint.port
endpointPort: endpoint.port,
connectionTimeout_ms: timeout_ms
})

@@ -25,0 +26,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc