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
86 lines
2.2 KiB
JavaScript
86 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
var request = require('supertest');
|
|
var should = require('should');
|
|
var Stream = require('stream');
|
|
|
|
var levels = require('../lib/levels');
|
|
var notificationsAPI = require('../lib/api/notifications-api');
|
|
|
|
function examplePlugin () {}
|
|
|
|
describe('Notifications API', function ( ) {
|
|
|
|
it('ack notifications', function (done) {
|
|
|
|
var known = 'b723e97aa97846eb92d5264f084b2823f57c4aa1';
|
|
delete process.env.API_SECRET;
|
|
process.env.API_SECRET = 'this is my long pass phrase';
|
|
var env = require('../lib/server/env')( );
|
|
env.enclave.isApiKey(known).should.equal(true);
|
|
env.testMode = true;
|
|
|
|
var ctx = {
|
|
bus: new Stream
|
|
, ddata: {
|
|
lastUpdated: Date.now()
|
|
}
|
|
, store: {
|
|
collection: function ( ) {
|
|
return { };
|
|
}
|
|
}
|
|
, levels: levels
|
|
};
|
|
|
|
ctx.authorization = require('../lib/authorization')(env, ctx);
|
|
|
|
var notifications = require('../lib/notifications')(env, ctx);
|
|
ctx.notifications = notifications;
|
|
|
|
//start fresh to we don't pick up other notifications
|
|
ctx.bus = new Stream;
|
|
//if notification doesn't get called test will time out
|
|
ctx.bus.on('notification', function callback (notify) {
|
|
if (notify.clear) {
|
|
done();
|
|
}
|
|
});
|
|
|
|
var exampleWarn = {
|
|
title: 'test'
|
|
, message: 'testing'
|
|
, level: levels.WARN
|
|
, plugin: examplePlugin
|
|
};
|
|
|
|
notifications.resetStateForTests();
|
|
notifications.initRequests();
|
|
notifications.requestNotify(exampleWarn);
|
|
notifications.findHighestAlarm().should.equal(exampleWarn);
|
|
notifications.process();
|
|
|
|
var app = require('express')();
|
|
app.enable('api');
|
|
var wares = require('../lib/middleware/')(env);
|
|
app.use('/', notificationsAPI(app, wares, ctx));
|
|
|
|
function makeRequest () {
|
|
request(app)
|
|
.get('/notifications/ack?level=1')
|
|
.set('api-secret', known || '')
|
|
.expect(200)
|
|
.end(function (err) {
|
|
should.not.exist(err);
|
|
if (err) {
|
|
console.error(err);
|
|
}
|
|
});
|
|
}
|
|
|
|
makeRequest();
|
|
|
|
//2nd call should have no effect, done should NOT be called again
|
|
makeRequest();
|
|
});
|
|
}); |