Skip to content

Commit

Permalink
WIP: Security patterns plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
anmavrid committed Oct 2, 2017
1 parent 01f3a99 commit 0c38973
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Anastasia Mavridou
Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 0 additions & 3 deletions config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @author anmavrid / https://github.com/anmavrid
*/
'use strict';

var config = require('./config.webgme'),
Expand Down
5 changes: 0 additions & 5 deletions config/config.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*jshint node: true*/
/**
* @author lattmann / https://github.com/lattmann
*/

'use strict';

var config = require('./config.default');
Expand Down
6 changes: 0 additions & 6 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*jshint node: true*/
/**
* @author lattmann / https://github.com/lattmann
* @author pmeijer / https://github.com/pmeijer
*/

'use strict';

var env = process.env.NODE_ENV || 'default',
Expand Down
33 changes: 25 additions & 8 deletions src/plugins/AddSecurityPatterns/AddSecurityPatterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,17 @@ define([

return utils.getModelOfContract(self.core, contractNode)
.then(function (contractModel) {
//TODO: add input from widget to contractModel
var currentConfig = self.getCurrentConfig(),
info = {
locking: currentConfig['locking'],
counter: currentConfig['counter'],
timedTransitions: currentConfig['timedTransitions'],
accessControl: currentConfig['accessControl'],
events: currentConfig['events']
};
Object.assign(contractModel, currentConfig);
fileContent = ejs.render(ejsCache.contractType.complete, contractModel);
//Need to change this for a Javascript file.
//TODO: Need to change this for a Javascript file.
//var parseResult = javaParser.checkWholeFile(fileContent);
//if (parseResult) {
//self.logger.debug(parseResult.line);
Expand Down Expand Up @@ -272,12 +280,21 @@ define([
return nameAndViolations;
};

// AddSecurityPatterns.prototype.generateTestInfo = function () {
// var self = this,
// currentConfig = this.getCurrentConfig(),
//
// return currentConfig;
// };
AddSecurityPatterns.prototype.generatePluginInfo = function () {
var self = this,
currentConfig = this.getCurrentConfig(),
info = {
locking: currentConfig['locking'],
counter: currentConfig['counter'],
timedTransitions: currentConfig['timedTransitions'],
accessControl: currentConfig['accessControl'],
events: currentConfig['events']
};
console.log(currentConfig['locking']);
console.log(info.locking);

return info;
};

return AddSecurityPatterns;

Expand Down
54 changes: 54 additions & 0 deletions src/templatesWithPatterns/contractPlugins.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<% if (locking) { %>
// Locking plugin
bool private locked = false;
modifier locking {
require(!locked);
locked = true;
_;
locked = false;
}
<% } %>
<% if (counter) { %>
// Transition Counter plugin
uint private transitionCounter = 0;
modifier transitionCounting(uint nextTransitionNumber) {
require(nextTransitionNumber == transitionCounter);
transitionCounter +=1;
_;
}
<% } %>
<% if (timedTransitions) { %>
// Timed Transitions plugin
<% } %>
<% if (accessControl) { %>
// Access Control plugin
mapping(address => bool) private isAdmin;
uint private numAdmins = 1;
function name() {
isAdmin[msg.sender] = true;
}
modifier onlyAdmin {
require(isAdmin[msg.sender]);
_;
}
function addAdmin(address admin) onlyAdmin {
require(!isAdmin[admin]);
isAdmin[admin] = true;
numAdmins +=1;
}
function removeAdmin(address admin) onlyAdmin {
require(isAdmin[admin]);
require(numAdmins > 1);
isAdmin[admin] = false;
numAdmins -= 1;
}
<% } %>
<% if (events) { %>
// Events plugin
<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
/*jshint browser: true*/
/*jscs:disable maximumLineLength*/

/**
* @author rkereskenyi / https://github.com/rkereskenyi
*/

define(['js/logger',
'js/util',
'js/Constants',
Expand Down
3 changes: 0 additions & 3 deletions test/globals.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// This is used by the test/plugins tests
/*globals requireJS*/
/*jshint node:true*/
/**
* @author pmeijer / https://github.com/pmeijer
*/

'use strict';

Expand Down

0 comments on commit 0c38973

Please sign in to comment.