From b77affb86a3eac7b542f04b1bfa8bea380aea8ff Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 21 May 2013 15:38:18 +0200 Subject: [PATCH] added grunt test runner --- Gruntfile.js | 25 +++++++++++++++++++++++++ package.json | 9 ++++++++- src/js/crypto/rsa.js | 18 ++++++++++++------ test/test.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 Gruntfile.js create mode 100755 test/test.sh diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..fd74b1e --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,25 @@ +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + jshint: { + all: ['Gruntfile.js', 'src/js/**/*.js'] + }, + qunit: { + all: { + options: { + urls: ['http://localhost:8580/unit/index.html'] + } + } + } + }); + + // Load the plugin(s) + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + + // Default task(s). + grunt.registerTask('test', ['jshint', 'qunit']); + +}; \ No newline at end of file diff --git a/package.json b/package.json index 129eece..13c3244 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,17 @@ "node": ">=0.8" }, "scripts": { - "postinstall": "./res/copy-deps.sh" + "preinstall": "rm -rf node_modules/", + "postinstall": "./res/copy-deps.sh", + "test": "test/test.sh" }, "dependencies": { "express": "latest", "crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-jshint": "~0.5.3", + "grunt-contrib-qunit": "~0.2.1" } } \ No newline at end of file diff --git a/src/js/crypto/rsa.js b/src/js/crypto/rsa.js index ecf2e05..c9ecf21 100644 --- a/src/js/crypto/rsa.js +++ b/src/js/crypto/rsa.js @@ -6,7 +6,7 @@ var RSA = function(forge, util) { var utl = forge.util; - var keypair = null; + var keypair = {}; /** * Initializes the RSA module by passing the user's keypair @@ -14,13 +14,15 @@ var RSA = function(forge, util) { * and signing */ this.init = function(pubkeyPem, privkeyPem, keyId) { - keypair = { - _id: keyId, - publicKey: forge.pki.publicKeyFromPem(pubkeyPem) - }; + if (pubkeyPem) { + keypair.publicKey = forge.pki.publicKeyFromPem(pubkeyPem); + } if (privkeyPem) { keypair.privateKey = forge.pki.privateKeyFromPem(privkeyPem); } + if (keyId) { + keypair._id = keyId; + } }; /** @@ -43,7 +45,11 @@ var RSA = function(forge, util) { // generate unique keypair ID keypair._id = util.UUID(); - callback(); + callback(null, { + _id: keypair._id, + pubkeyPem: forge.pki.publicKeyToPem(keypair.publicKey), + privkeyPem: forge.pki.privateKeyToPem(keypair.privateKey) + }); }); }; diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..3e6270f --- /dev/null +++ b/test/test.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# go to root +cd `dirname $0` +cd .. + +PORT=8580 + +# start server for integration tests +echo "--> starting test server...\n" +PORT=$PORT node server.js --dev & +# get process id +PID=$! +# wait the service to init +sleep 1 + +# run integration tests +echo "\n--> run tests via grunt...\n" +grunt test + +# stop server for integration tests +echo "\n--> stoping test server..." +# wait for request to terminate +sleep 0.5 +# kill server process +kill $PID +echo "\n--> all done!\n"