Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sntp

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sntp - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

20

lib/index.js

@@ -32,3 +32,2 @@ // Load modules

var isFinished = false;
var finish = function (err, result) {

@@ -41,11 +40,10 @@

if (!isFinished) {
isFinished = true;
socket.removeAllListeners();
socket.once('error', internals.ignore);
socket.close();
return callback(err, result);
}
socket.removeAllListeners();
socket.once('error', internals.ignore);
socket.close();
return callback(err, result);
};
finish = Hoek.once(finish);
// Create UDP socket

@@ -324,3 +322,3 @@

process.nextTick(function () {
callback(null, internals.last.offset);

@@ -366,6 +364,6 @@ });

process.nextTick(function () {
callback();
});
return;

@@ -372,0 +370,0 @@ }

{
"name": "sntp",
"description": "SNTP Client",
"version": "1.0.3",
"version": "1.0.4",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -18,6 +18,6 @@ "contributors": [],

"dependencies": {
"hoek": "1.x.x"
"hoek": "2.x.x"
},
"devDependencies": {
"lab": "1.x.x"
"lab": "3.x.x"
},

@@ -24,0 +24,0 @@ "scripts": {

// Load modules
var Dns = require('dns');
var Dgram = require('dgram');

@@ -56,2 +57,20 @@ var Lab = require('lab');

it('fails to resolve reference IP', { parallel: false }, function (done) {
var orig = Dns.reverse;
Dns.reverse = function (ip, callback) {
Dns.reverse = orig;
return callback(new Error('Missing IP'));
};
Sntp.time({ host: 'ntp.exnet.com', resolveReference: true }, function (err, time) {
expect(err).to.exist;
expect(time).to.exist;
expect(time.referenceHost).to.not.exist;
done();
});
});
it('times out on no response', function (done) {

@@ -68,3 +87,3 @@

it('errors on error event', function (done) {
it('errors on error event', { parallel: false }, function (done) {

@@ -76,3 +95,3 @@ var orig = Dgram.createSocket;

var socket = Dgram.createSocket(type);
process.nextTick(function () { socket.emit('error', new Error('Fake')) });
setImmediate(function () { socket.emit('error', new Error('Fake')) });
return socket;

@@ -90,2 +109,20 @@ };

it('errors on incorrect sent size', { parallel: false }, function (done) {
var orig = Dgram.Socket.prototype.send;
Dgram.Socket.prototype.send = function (buf, offset, length, port, address, callback) {
Dgram.Socket.prototype.send = orig;
return callback(null, 40);
};
Sntp.time(function (err, time) {
expect(err).to.exist;
expect(time).to.not.exist;
expect(err.message).to.equal('Could not send entire message');
done();
});
});
it('times out on invalid host', function (done) {

@@ -169,2 +206,26 @@

it('fails on bad originateTimestamp', function (done) {
messup([[24, 0x83], [25, 0xaa], [26, 0x7e], [27, 0x80], [28, 0], [29, 0], [30, 0], [31, 0]]);
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) {
expect(err).to.exist;
expect(err.message).to.equal('Invalid server response');
done();
});
});
it('fails on bad receiveTimestamp', function (done) {
messup([[32, 0x83], [33, 0xaa], [34, 0x7e], [35, 0x80], [36, 0], [37, 0], [38, 0], [39, 0]]);
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) {
expect(err).to.exist;
expect(err.message).to.equal('Invalid server response');
done();
});
});
it('fails on bad originate timestamp and alarm li', function (done) {

@@ -296,2 +357,34 @@

it('gets the new offset on different server', function (done) {
Sntp.offset(function (err, offset) {
expect(err).to.not.exist;
expect(offset).to.not.equal(0);
var offset1 = offset;
Sntp.offset({ host: 'nist1-sj.ustiming.org' }, function (err, offset) {
expect(err).to.not.exist;
expect(offset).to.not.equal(offset1);
done();
});
});
});
it('gets the new offset on different server', function (done) {
Sntp.offset(function (err, offset) {
expect(err).to.not.exist;
expect(offset).to.not.equal(0);
var offset1 = offset;
Sntp.offset({ port: 123 }, function (err, offset) {
expect(err).to.not.exist;
expect(offset).to.not.equal(offset1);
done();
});
});
});
it('fails getting the current offset on invalid server', function (done) {

@@ -298,0 +391,0 @@

Sorry, the diff of this file is not supported yet

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