diff --git a/coffee/config.coffee b/coffee/config.coffee index 1919f11..e0d67bc 100644 --- a/coffee/config.coffee +++ b/coffee/config.coffee @@ -38,6 +38,7 @@ Reads the config file synchronously from the file system and try to parse it. @param {String} relPath ### loadConfigFile = ( relPath ) => + @config = null try @config = JSON.parse fs.readFileSync path.resolve __dirname, '..', relPath if @config and @config.http_port and @config.db_port and diff --git a/coffee/db_interface.coffee b/coffee/db_interface.coffee index 59caa69..1ab956a 100644 --- a/coffee/db_interface.coffee +++ b/coffee/db_interface.coffee @@ -213,7 +213,7 @@ Store a string representation of an action module in the DB. exports.storeActionModule = ( id, data ) => log.print 'DB', 'storeActionModule: ' + id @db.sadd 'action-modules', id, replyHandler 'storing action module key ' + id - @db.hmset 'action-module:' + id, data, replyHandler 'storing action module ' + id + @db.set 'action-module:' + id, data, replyHandler 'storing action module ' + id ### Query the DB for an action module and pass it to the callback(err, obj) function. @@ -224,7 +224,7 @@ Query the DB for an action module and pass it to the callback(err, obj) function ### exports.getActionModule = ( id, cb ) => log.print 'DB', 'getActionModule: ' + id - @db.hgetall 'action-module:' + id, cb + @db.get 'action-module:' + id, cb ### Fetch all action modules and hand them to the callback(err, obj) function. @@ -246,7 +246,7 @@ Store a string representation of the authentication parameters for an action mod exports.storeActionAuth = ( userId, moduleId, data ) => log.print 'DB', 'storeActionAuth: ' + userId + ':' + moduleId @db.set 'action-auth:' + userId + ':' + moduleId, hash(data), - replyHandler 'storing action auth ' + userId + ':' + moduleId + replyHandler 'storing action auth ' + userId + ':' + moduleId ### Query the DB for an action module authentication token associated to a user @@ -277,7 +277,7 @@ Store a string representation of an event module in the DB. exports.storeEventModule = ( id, data ) => log.print 'DB', 'storeEventModule: ' + id @db.sadd 'event-modules', id, replyHandler 'storing event module key ' + id - @db.hmset 'event-module:' + id, data, replyHandler 'storing event module ' + id + @db.set 'event-module:' + id, data, replyHandler 'storing event module ' + id ### Query the DB for an event module and pass it to the callback(err, obj) function. @@ -288,7 +288,7 @@ Query the DB for an event module and pass it to the callback(err, obj) function. ### exports.getEventModule = ( id, cb ) => log.print 'DB', 'getEventModule: ' + id - @db.hgetall 'event-module:' + id, cb + @db.get 'event-module:' + id, cb ### Fetch all event modules and pass them to the callback(err, obj) function. @@ -312,7 +312,7 @@ exports.storeEventParams = ( userId, moduleId, data ) => log.print 'DB', 'storeEventParams: ' + userId + ':' + moduleId # TODO encryption based on user specific key? @db.set 'event-params:' + moduleId + ':' + userId, encrypt(data), - replyHandler 'storing event auth ' + userId + ':' + moduleId + replyHandler 'storing event auth ' + userId + ':' + moduleId ### Query the DB for an action module authentication token, associated with a user. diff --git a/coffee/server.coffee b/coffee/server.coffee index 2bb23da..cbcdaeb 100644 --- a/coffee/server.coffee +++ b/coffee/server.coffee @@ -18,6 +18,7 @@ Server > > +TODO how about we allow spawning child processes with servers based on address? ### # **Requires:** @@ -52,6 +53,7 @@ process.on 'uncaughtException', ( err ) -> err.addInfo = 'http_port already in use, shutting down!' log.error 'RS', err shutDown() + # else log.error 'RS', err else throw err ### This function is invoked right after the module is loaded and starts the server. diff --git a/compile_testing.sh b/compile_testing.sh new file mode 100755 index 0000000..09a259f --- /dev/null +++ b/compile_testing.sh @@ -0,0 +1,3 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +echo "Started listening on file changes to compile them!..." +coffee -wc $DIR/testing/ diff --git a/js-coffee/config.js b/js-coffee/config.js index 1de8ae2..70ad3fb 100644 --- a/js-coffee/config.js +++ b/js-coffee/config.js @@ -46,6 +46,7 @@ Configuration loadConfigFile = function(relPath) { var e; + _this.config = null; try { _this.config = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', relPath))); if (_this.config && _this.config.http_port && _this.config.db_port && _this.config.crypto_key && _this.config.session_secret) { diff --git a/js-coffee/db_interface.js b/js-coffee/db_interface.js index d5230f8..de1ce4e 100644 --- a/js-coffee/db_interface.js +++ b/js-coffee/db_interface.js @@ -278,7 +278,7 @@ DB Interface exports.storeActionModule = function(id, data) { log.print('DB', 'storeActionModule: ' + id); _this.db.sadd('action-modules', id, replyHandler('storing action module key ' + id)); - return _this.db.hmset('action-module:' + id, data, replyHandler('storing action module ' + id)); + return _this.db.set('action-module:' + id, data, replyHandler('storing action module ' + id)); }; /* @@ -292,7 +292,7 @@ DB Interface exports.getActionModule = function(id, cb) { log.print('DB', 'getActionModule: ' + id); - return _this.db.hgetall('action-module:' + id, cb); + return _this.db.get('action-module:' + id, cb); }; /* @@ -357,7 +357,7 @@ DB Interface exports.storeEventModule = function(id, data) { log.print('DB', 'storeEventModule: ' + id); _this.db.sadd('event-modules', id, replyHandler('storing event module key ' + id)); - return _this.db.hmset('event-module:' + id, data, replyHandler('storing event module ' + id)); + return _this.db.set('event-module:' + id, data, replyHandler('storing event module ' + id)); }; /* @@ -371,7 +371,7 @@ DB Interface exports.getEventModule = function(id, cb) { log.print('DB', 'getEventModule: ' + id); - return _this.db.hgetall('event-module:' + id, cb); + return _this.db.get('event-module:' + id, cb); }; /* diff --git a/js-coffee/logging.js b/js-coffee/logging.js index cda375c..d76f4fc 100644 --- a/js-coffee/logging.js +++ b/js-coffee/logging.js @@ -29,8 +29,10 @@ function flush(err, msg) { } function flushToConsole(err, msg) { - if(err) console.error(msg); + if(err) console.error("\033[31m" + msg + "\033[0m"); else console.log(msg); + // if(err) console.error(msg); + // else console.log(msg); } function flushToFile(err, msg) { diff --git a/js-coffee/module_loader.js b/js-coffee/module_loader.js index e7164c7..795f7f4 100644 --- a/js-coffee/module_loader.js +++ b/js-coffee/module_loader.js @@ -25,7 +25,12 @@ exports.requireFromString = function(src, name, dir) { // Define max runtime per loop as 10 seconds, after that the child will be killed // it can still be active after that if there was a timing function or a callback used... // kill the child each time? how to determine whether there's still a token in the module? - var mod = vm.runInNewContext(src, sandbox, id + '.vm'); + try { + var mod = vm.runInNewContext(src, sandbox, id); + + } catch (err) { + log.error('ML', 'Error running module in sandbox: ' + err.message); + } return sandbox.exports; }; diff --git a/js-coffee/server.js b/js-coffee/server.js index 79435a9..046081a 100644 --- a/js-coffee/server.js +++ b/js-coffee/server.js @@ -18,6 +18,8 @@ Server >[config](config.html) file, to listen to, e.g. used by the test suite. > > + +TODO how about we allow spawning child processes with servers based on address? */ diff --git a/testing/mod_config.js b/testing/old/mod_config.js similarity index 100% rename from testing/mod_config.js rename to testing/old/mod_config.js diff --git a/testing/mod_db_interface.js b/testing/old/mod_db_interface.js similarity index 100% rename from testing/mod_db_interface.js rename to testing/old/mod_db_interface.js diff --git a/testing/mod_engine.js b/testing/old/mod_engine.js similarity index 100% rename from testing/mod_engine.js rename to testing/old/mod_engine.js diff --git a/testing/mod_eventpoller.js b/testing/old/mod_eventpoller.js similarity index 100% rename from testing/mod_eventpoller.js rename to testing/old/mod_eventpoller.js diff --git a/testing/mod_http_listener.js b/testing/old/mod_http_listener.js similarity index 100% rename from testing/mod_http_listener.js rename to testing/old/mod_http_listener.js diff --git a/testing/mod_logging.js b/testing/old/mod_logging.js similarity index 100% rename from testing/mod_logging.js rename to testing/old/mod_logging.js diff --git a/testing/mod_module_loader.js b/testing/old/mod_module_loader.js similarity index 100% rename from testing/mod_module_loader.js rename to testing/old/mod_module_loader.js diff --git a/testing/mod_module_manager.js b/testing/old/mod_module_manager.js similarity index 100% rename from testing/mod_module_manager.js rename to testing/old/mod_module_manager.js diff --git a/testing/mod_server.js b/testing/old/mod_server.js similarity index 100% rename from testing/mod_server.js rename to testing/old/mod_server.js diff --git a/testing/mod_user.js b/testing/old/mod_user.js similarity index 100% rename from testing/mod_user.js rename to testing/old/mod_user.js diff --git a/testing/unit_integration.js b/testing/old/unit_integration.js similarity index 100% rename from testing/unit_integration.js rename to testing/old/unit_integration.js diff --git a/testing/whole_system.js b/testing/old/whole_system.js similarity index 100% rename from testing/whole_system.js rename to testing/old/whole_system.js diff --git a/testing/test_config.coffee b/testing/test_config.coffee new file mode 100644 index 0000000..257d12e --- /dev/null +++ b/testing/test_config.coffee @@ -0,0 +1,20 @@ +exports.testRequire = (test) -> + conf = require '../js-coffee/config' + conf { logType: 2 } + test.ok conf.isReady(), 'File exists' + conf { relPath: 'wrongpath' } + test.strictEqual conf.isReady(), false + + test.done() + +exports.testParametersReady = (test) -> + + conf = require '../js-coffee/config' + conf { logType: 2 } + console.log conf + test.ok conf.getHttpPort(), 'HTTP port exists' + test.ok conf.getDBPort(), 'DB port exists' + test.ok conf.getCryptoKey(), 'Crypto key exists' + test.ok conf.getSessionSecret(), 'Session Secret exists' + + test.done() \ No newline at end of file diff --git a/testing/test_config.js b/testing/test_config.js new file mode 100644 index 0000000..7022d27 --- /dev/null +++ b/testing/test_config.js @@ -0,0 +1,31 @@ +// Generated by CoffeeScript 1.6.3 +(function() { + exports.testRequire = function(test) { + var conf; + conf = require('../js-coffee/config'); + conf({ + logType: 2 + }); + test.ok(conf.isReady(), 'File exists'); + conf({ + relPath: 'wrongpath' + }); + test.strictEqual(conf.isReady(), false); + return test.done(); + }; + + exports.testParametersReady = function(test) { + var conf; + conf = require('../js-coffee/config'); + conf({ + logType: 2 + }); + console.log(conf); + test.ok(conf.getHttpPort(), 'HTTP port exists'); + test.ok(conf.getDBPort(), 'DB port exists'); + test.ok(conf.getCryptoKey(), 'Crypto key exists'); + test.ok(conf.getSessionSecret(), 'Session Secret exists'); + return test.done(); + }; + +}).call(this); diff --git a/testing/test_db_interface.coffee b/testing/test_db_interface.coffee new file mode 100644 index 0000000..f61314c --- /dev/null +++ b/testing/test_db_interface.coffee @@ -0,0 +1,15 @@ +exports.testRequire = (test) -> + db = require '../js-coffee/db_interface' + test.ok db, 'DB interface loaded' + db { logType: 2 } + test.ok conf.isReady(), 'File exists' + + test.ok conf.getHttpPort(), 'HTTP port exists' + test.ok conf.getDBPort(), 'DB port exists' + test.ok conf.getCryptoKey(), 'Crypto key exists' + test.ok conf.getSessionSecret(), 'Session Secret exists' + + conf { relPath: 'wrongpath' } + test.strictEqual conf.isReady(), false + + test.done() diff --git a/testing/test_db_interface.js b/testing/test_db_interface.js new file mode 100644 index 0000000..849d411 --- /dev/null +++ b/testing/test_db_interface.js @@ -0,0 +1,22 @@ +// Generated by CoffeeScript 1.6.3 +(function() { + exports.testRequire = function(test) { + var db; + db = require('../js-coffee/db_interface'); + test.ok(db, 'DB interface loaded'); + db({ + logType: 2 + }); + test.ok(conf.isReady(), 'File exists'); + test.ok(conf.getHttpPort(), 'HTTP port exists'); + test.ok(conf.getDBPort(), 'DB port exists'); + test.ok(conf.getCryptoKey(), 'Crypto key exists'); + test.ok(conf.getSessionSecret(), 'Session Secret exists'); + conf({ + relPath: 'wrongpath' + }); + test.strictEqual(conf.isReady(), false); + return test.done(); + }; + +}).call(this); diff --git a/webpages/handlers/forge_modules.html b/webpages/handlers/forge_modules.html index a32fc37..4ae8516 100644 --- a/webpages/handlers/forge_modules.html +++ b/webpages/handlers/forge_modules.html @@ -3,7 +3,7 @@