Skip to content

Commit

Permalink
Ensure auth (#18)
Browse files Browse the repository at this point in the history
* Test seeding overhaul, routes authorized, misc test fixes
* Cleanup, unified formatting, reduced use of own code
* update readme
* made the grunt default test task include dummy database restore
* created a separate shell script for linux machines
* increased logging level, database still not restoring for some reason
* removed obsolete --quiet parameter from mongorestore exec
* cleanup for controllers
* cleaned configs
  • Loading branch information
jupe authored Jun 7, 2017
1 parent 1eba6ac commit caa183e
Show file tree
Hide file tree
Showing 62 changed files with 1,480 additions and 1,319 deletions.
21 changes: 16 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("xunit-file");
fs = require('fs');
const fs = require('fs');


module.exports = function(grunt) {
Expand All @@ -14,7 +14,7 @@ module.exports = function(grunt) {
script: "index.js",
timeout: 3000,
harmony: true,
args: ['-s'] //to more traces set -vvv instead of -s (silent)
args: ['-s'], //to more traces set -vvv instead of -s (silent)
}
}
},
Expand All @@ -26,6 +26,16 @@ module.exports = function(grunt) {
}
}
},
exec: {
restore_db: {
cmd: './scripts/dbrestore_linux.sh local ./test/seeds/test_dump/',
stdout: true,
stderr: true,
options: {
shell: 'bash'
}
}
},
simplemocha: {
options: {
globals: ["should"],
Expand Down Expand Up @@ -64,7 +74,8 @@ module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-wait-server');
grunt.loadNpmTasks("grunt-express-server");
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks("grunt-simple-mocha");
grunt.registerTask("default", ["FindTests", "express:test", 'waitServer', "simplemocha:all"]);

};
grunt.registerTask("default", ["FindTests", "express:test", "waitServer", "exec", "simplemocha:all"]);
grunt.registerTask("no-db-restore", ["FindTests", "express:test", "waitServer", "simplemocha:all"]);
};
61 changes: 32 additions & 29 deletions app/controllers/apikeys.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
var _ = require('lodash');
var mongoose = require('mongoose');

var User = mongoose.model('User');
var ApiKey = mongoose.model('ApiKey');
var _ = require('lodash');

module.exports = {
keys: function(req, res){
ApiKey.find({}, function(error, keys){
if(error){
return res.status(401).send({message: error});
keys: (req, res) => {
ApiKey.find({}, (error, keys) => {
if (error) {
return res.status(401).send({ message: error });
}
res.send(_.map(keys, function(key){
return key.key;
}));
})

return res.send(_.map(keys, key => key.key));
});
},
userKeys: function(req, res){
User.getApiKeys(req.user.sub, function(error, keys){
if(error){
return res.status(401).send({message: error});
}
res.send(keys);
userKeys: (req, res) => {
User.getApiKeys(req.user.sub, (error, keys) => {
if (error) {
return res.status(401).send({ message: error });
}

return res.send(keys);
});
},
createKey: function(req, res){
User.createApiKey(req.user.sub, function(error, key){
if(error){
return res.status(401).send({message: error});
createKey: (req, res) => {
User.createApiKey(req.user.sub, (error, key) => {
if (error) {
return res.status(401).send({ message: error });
}
res.send({apikey: key});
})

return res.send({ apikey: key });
});
},
deleteKey: function(req, res){
User.deleteApiKey(req.user.sub, req.params.ApiKey, function(error, ok){
if(error){
return res.status(401).send({message: error});
deleteKey: (req, res) => {
User.deleteApiKey(req.user.sub, req.params.ApiKey, (error, ok) => {
if (error) {
return res.status(401).send({ message: error });
}
res.send({ok: ok});
})
}
}

return res.send({ ok: ok });
});
},
};
4 changes: 2 additions & 2 deletions app/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ var Controller = function () {
var id = nconf.get('github').clientID;
if (id === undefined) {
res.status(400).json({ error:'found client id is undefined' });
}
}
else {
res.status(200).json({ clientID:id });
res.status(200).json({ clientID:id });
}
}

Expand Down
61 changes: 10 additions & 51 deletions app/controllers/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,38 @@
Builds Controller
*/

//native modules
var util = require("util");
// native modules

//3rd party modules
var express = require('express');
// 3rd party modules
var mongoose = require('mongoose');
var _ = require('lodash');

//own modules
// own modules
var DefaultController = require('./');

var Controller = function(){

var Controller = function () {
var Build = mongoose.model('Build');
var defaultCtrl = new DefaultController(Build, 'Build');

function randomIntInc (low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
}
function randomText( list ){
i = randomIntInc( 0, list.length-1 )
return list[i]
}

//create dummy testcases when db is empty ->
defaultCtrl.isEmpty( function(yes){
if( yes === true ){
var Template = {
name: 'Build-',
target: {
type: 'simulate',
hw: {
platform: ''
}
}
}
defaultCtrl.generateDummyData( function(i){
var _new = {};
_.extend(_new, Template)
_new.name += i;
_new.target.type = defaultCtrl.randomText(['simulate', 'hardware']);
_new.target.hw.platform =
defaultCtrl.randomText(['K84F', 'nRF123', 'XBoard'])
return _new;
}, 10, function(err){
//done
if(err)console.log(err);
else console.log('dummy build generated');
});
}
});

this.paramFormat = defaultCtrl.format();
this.paramBuild = defaultCtrl.modelParam();

this.all = function(req, res, next){
this.all = (req, res, next) => {
// dummy middleman function..
next();
next();
};

this.get = defaultCtrl.get;
this.find = defaultCtrl.find;
this.create = defaultCtrl.create;
this.update = defaultCtrl.update;
this.remove = defaultCtrl.remove;

this.download = function(req, res) {
req.Build.download( req.params.Index, res);
this.download = (req, res) => {
req.Build.download(req.params.Index, res);
};
//util.inherits(this, defaultCtrl);

return this;
}
};


module.exports = Controller;
47 changes: 9 additions & 38 deletions app/controllers/campaigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,34 @@
Campaign Controller
*/

//native modules
var util = require("util");
// native modules

//3rd party modules
var express = require('express');
// 3rd party modules
var mongoose = require('mongoose');
var _ = require('lodash');

//own modules
// own modules
var DefaultController = require('./');

var Controller = function(){

var Controller = function () {
var Campaign = mongoose.model('Campaign');
var defaultCtrl = new DefaultController(Campaign, 'Campaign');

//create dummy campaigns when db is empty ->
defaultCtrl.isEmpty( function(yes){
if( yes === true ){
var Template = {
name: 'Campaign-',
cre: { user: 'tmt'},
tcs: JSON.stringify({})
}

defaultCtrl.generateDummyData( function(i){
var _new = {};
_.extend(_new, Template)
_new.name += i;
return _new;
}, 2, function(err){
//done
if(err)console.log(err);
else console.log('dummy campaign generated');
});
}
});

this.paramFormat = defaultCtrl.format();
this.paramCampaign = defaultCtrl.modelParam();

this.all = function(req, res, next){
this.all = (req, res, next) => {
// dummy middleman function..
next();
}
next();
};

this.get = defaultCtrl.get;
this.find = defaultCtrl.find;
this.create = defaultCtrl.create;
this.update = defaultCtrl.update;
this.remove = defaultCtrl.remove;


//util.inherits(this, defaultCtrl);

return this;
}
};


module.exports = Controller;
26 changes: 10 additions & 16 deletions app/controllers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,34 @@
Groups Controller
*/

//native modules
var util = require("util");
// native modules

//3rd party modules
var express = require('express');
// 3rd party modules
var mongoose = require('mongoose');

//own modules
// own modules
var DefaultController = require('./');

var Controller = function(){

var Controller = function () {
var Group = mongoose.model('Group');
var defaultCtrl = new DefaultController(Group, 'Group');

this.paramFormat = defaultCtrl.format();
this.paramGroup = defaultCtrl.modelParam();

this.all = function(req, res, next){
this.all = (req, res, next) => {
// dummy middleman function..
next();
}
next();
};

this.get = defaultCtrl.get;
this.find = defaultCtrl.find;
this.create = defaultCtrl.create;
this.update = defaultCtrl.update;
this.remove = defaultCtrl.remove;


//util.inherits(this, defaultCtrl);

return this;
}
};


module.exports = Controller;
module.exports = Controller;
Loading

0 comments on commit caa183e

Please sign in to comment.