mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
* * Simplified bundling to just one bundle * Removed cache invalidation token from bundling * Generate strong persistent random string on deploy to use for JWT signing * WIP: moving api-secret and JWT signing to a separate centralized security component * Moved some server components away from project root * Fix issues reported by linter * Ignore detect-object-injection everywhere but the client * Make admin message button red * Remove alarms for some security alerts on code * api_secret is now fully contained in the enclave
115 lines
3.0 KiB
JavaScript
115 lines
3.0 KiB
JavaScript
'use strict';
|
|
|
|
var should = require('should');
|
|
var levels = require('../lib/levels');
|
|
|
|
describe('pushnotify', function ( ) {
|
|
|
|
it('send a pushover alarm, but only 1 time', function (done) {
|
|
var env = require('../lib/server/env')();
|
|
var ctx = {};
|
|
|
|
ctx.levels = levels;
|
|
ctx.notifications = require('../lib/notifications')(env, ctx);
|
|
|
|
var notify = {
|
|
title: 'Warning, this is a test!'
|
|
, message: 'details details details details'
|
|
, level: levels.WARN
|
|
, pushoverSound: 'climb'
|
|
, plugin: {name: 'test'}
|
|
};
|
|
|
|
ctx.pushover = {
|
|
PRIORITY_NORMAL: 0
|
|
, PRIORITY_EMERGENCY: 2
|
|
, send: function mockedSend (notify2, callback) {
|
|
should.deepEqual(notify, notify2);
|
|
callback(null, JSON.stringify({receipt: 'abcd12345'}));
|
|
done();
|
|
}
|
|
};
|
|
|
|
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
|
|
|
|
ctx.pushnotify.emitNotification(notify);
|
|
|
|
//call again, but should be deduped, or fail with 'done() called multiple times'
|
|
ctx.pushnotify.emitNotification(notify);
|
|
|
|
});
|
|
|
|
it('send a pushover notification, but only 1 time', function (done) {
|
|
var env = require('../lib/server/env')();
|
|
var ctx = {};
|
|
ctx.levels = levels;
|
|
ctx.notifications = require('../lib/notifications')(env, ctx);
|
|
|
|
var notify = {
|
|
title: 'Sent from a test'
|
|
, message: 'details details details details'
|
|
, level: levels.INFO
|
|
, plugin: {name: 'test'}
|
|
};
|
|
|
|
ctx.pushover = {
|
|
PRIORITY_NORMAL: 0
|
|
, PRIORITY_EMERGENCY: 2
|
|
, send: function mockedSend (notify2, callback) {
|
|
should.deepEqual(notify, notify2);
|
|
callback(null, JSON.stringify({}));
|
|
done();
|
|
}
|
|
};
|
|
|
|
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
|
|
|
|
ctx.pushnotify.emitNotification(notify);
|
|
|
|
//call again, but should be deduped, or fail with 'done() called multiple times'
|
|
ctx.pushnotify.emitNotification(notify);
|
|
|
|
});
|
|
|
|
it('send a pushover alarm, and then cancel', function (done) {
|
|
var env = require('../lib/server/env')();
|
|
var ctx = {};
|
|
ctx.levels = levels;
|
|
|
|
ctx.notifications = require('../lib/notifications')(env, ctx);
|
|
|
|
var notify = {
|
|
title: 'Warning, this is a test!'
|
|
, message: 'details details details details'
|
|
, level: levels.WARN
|
|
, pushoverSound: 'climb'
|
|
, plugin: {name: 'test'}
|
|
};
|
|
|
|
ctx.pushover = {
|
|
PRIORITY_NORMAL: 0
|
|
, PRIORITY_EMERGENCY: 2
|
|
, send: function mockedSend (notify2, callback) {
|
|
should.deepEqual(notify, notify2);
|
|
callback(null, JSON.stringify({receipt: 'abcd12345'}));
|
|
}
|
|
, cancelWithReceipt: function mockedCancel (receipt) {
|
|
receipt.should.equal('abcd12345');
|
|
done();
|
|
}
|
|
};
|
|
|
|
ctx.pushnotify = require('../lib/server/pushnotify')(env, ctx);
|
|
|
|
//first send the warning
|
|
ctx.pushnotify.emitNotification(notify);
|
|
|
|
//then pretend is was acked from the web
|
|
ctx.pushnotify.emitNotification({clear: true});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|