Permalink
Browse files

Testing notify-one and notify-one-challenge

  • Loading branch information...
andrewshell committed Nov 11, 2015
1 parent cae59f5 commit 6c19a29f0166c3bd34288adcaecd5946ee50a86e

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,15 @@
(function () {
"use strict";
var getRandomPassword = require('../../services/get-random-password.js');
describe('services/get-random-password.js', function () {
it('should return 8 digit password', function () {
getRandomPassword(8).should.have.lengthOf(8);
});
it('should return 16 digit password', function () {
getRandomPassword(16).should.have.lengthOf(16);
});
});
}());
@@ -0,0 +1,127 @@
(function () {
"use strict";
var crypto = require('crypto'),
notifyOneChallenge = require('../../services/notify-one-challenge.js'),
request = require('request'),
sinon = require('sinon'),
clock;
describe('services/notify-one-challenge.js correct api', function () {
before(function(done) {
sinon
.stub(crypto, 'randomBytes')
.returns('CHALLENGE');
sinon
.stub(request, 'get')
.yields(null, {statusCode: 200}, 'CHALLENGE');
clock = sinon.useFakeTimers();
clock.tick(300000);
done();
});
after(function(done) {
crypto.randomBytes.restore();
request.get.restore();
clock.restore();
done();
});
it('should notify api correctly', function (done) {
var data = {
subscriptions: {},
prefs: {
ctSecsResourceExpire: 25 * 60 * 60
}
};
notifyOneChallenge(data, 'http://www.google.com/', 'http://192.168.0.1/', function (err) {
if (err) { return done(err); }
data.subscriptions.should.have.property('http://www.google.com/');
data.subscriptions['http://www.google.com/'].should.have.property('http://192.168.0.1/');
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctUpdates', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctConsecutiveErrors', 0);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/'].whenLastUpdate.unix()
.should.equal(300);
done();
});
});
});
describe('services/notify-one-challenge.js invalid api', function () {
before(function(done) {
sinon
.stub(request, 'get')
.yields(null, {statusCode: 404});
clock = sinon.useFakeTimers();
clock.tick(300000);
done();
});
after(function(done) {
request.get.restore();
clock.restore();
done();
});
it('should fail to notify api correctly', function (done) {
var data = {
subscriptions: {},
prefs: {
ctSecsResourceExpire: 25 * 60 * 60
}
};
notifyOneChallenge(data, 'http://www.google.com/', 'http://192.168.0.1/', function (err) {
err.should.not.be.empty;
data.subscriptions.should.have.property('http://www.google.com/');
data.subscriptions['http://www.google.com/'].should.have.property('http://192.168.0.1/');
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctConsecutiveErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/'].whenLastError.unix()
.should.equal(300);
done();
});
});
});
describe('services/notify-one-challenge.js invalid challenge', function () {
before(function(done) {
sinon
.stub(request, 'get')
.yields(null, {statusCode: 200});
clock = sinon.useFakeTimers();
clock.tick(300000);
done();
});
after(function(done) {
request.get.restore();
clock.restore();
done();
});
it('should fail to notify api correctly', function (done) {
var data = {
subscriptions: {},
prefs: {
ctSecsResourceExpire: 25 * 60 * 60
}
};
notifyOneChallenge(data, 'http://www.google.com/', 'http://192.168.0.1/', function (err) {
err.should.not.be.empty;
data.subscriptions.should.have.property('http://www.google.com/');
data.subscriptions['http://www.google.com/'].should.have.property('http://192.168.0.1/');
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctConsecutiveErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/'].whenLastError.unix()
.should.equal(300);
done();
});
});
});
}());
@@ -0,0 +1,84 @@
(function () {
"use strict";
var notifyOne = require('../../services/notify-one.js'),
request = require('request'),
sinon = require('sinon'),
clock;
describe('services/notify-one.js correct api', function () {
before(function(done) {
sinon
.stub(request, 'post')
.yields(null, {statusCode: 200});
clock = sinon.useFakeTimers();
clock.tick(300000);
done();
});
after(function(done) {
request.post.restore();
clock.restore();
done();
});
it('should notify api correctly', function (done) {
var data = {
subscriptions: {},
prefs: {
ctSecsResourceExpire: 25 * 60 * 60
}
};
notifyOne(data, 'http://www.google.com/', 'http://192.168.0.1/', false, function (err) {
if (err) { return done(err); }
data.subscriptions.should.have.property('http://www.google.com/');
data.subscriptions['http://www.google.com/'].should.have.property('http://192.168.0.1/');
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctUpdates', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctConsecutiveErrors', 0);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/'].whenLastUpdate.unix()
.should.equal(300);
done();
});
});
});
describe('services/notify-one.js invalid api', function () {
before(function(done) {
sinon
.stub(request, 'post')
.yields(null, {statusCode: 404});
clock = sinon.useFakeTimers();
clock.tick(300000);
done();
});
after(function(done) {
request.post.restore();
clock.restore();
done();
});
it('should fail to notify api correctly', function (done) {
var data = {
subscriptions: {},
prefs: {
ctSecsResourceExpire: 25 * 60 * 60
}
};
notifyOne(data, 'http://www.google.com/', 'http://192.168.0.1/', false, function (err) {
err.should.not.be.empty;
data.subscriptions.should.have.property('http://www.google.com/');
data.subscriptions['http://www.google.com/'].should.have.property('http://192.168.0.1/');
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/']
.should.have.property('ctConsecutiveErrors', 1);
data.subscriptions['http://www.google.com/']['http://192.168.0.1/'].whenLastError.unix()
.should.equal(300);
done();
});
});
});
}());

0 comments on commit 6c19a29

Please sign in to comment.