Skip to content

Commit

Permalink
Working on unit tests and fixing found bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jurcovicovam committed Nov 28, 2014
1 parent e5857ce commit 75bfc89
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
11 changes: 10 additions & 1 deletion lib/createCrxWithOpenSSL.js
Expand Up @@ -15,6 +15,7 @@ module.exports = function() {
privateKey = pem.toString('ascii').trim();

generateSignature(privateKey, zipFileName, function(signatureBuffer) {
console.info('succesfully signed: (' + signatureBuffer.length + ') ' + signatureBuffer);
generatePublicKey(privateKey, function(publicKey) {
generatePackage(signatureBuffer, publicKey, zipFileName, outputFileName);
});
Expand Down Expand Up @@ -116,15 +117,20 @@ module.exports = function() {
* @param callback - must accept one parametner - binary buffer with generated signature
*/
function generateSignature(privateKey, zipFileName, callback) {
var signObj, inStream, onDone;
var signObj, inStream, onDone, onError;

onDone = function() {
console.info('onDone in stream');
var signatureBuffer = signObj.sign(privateKey);
if (callback){
callback.call(this, signatureBuffer);
}
};

onError = function() {
console.info('error in stream');
};

inStream = fs.createReadStream(zipFileName, {
flags: "r",
encoding: null,
Expand All @@ -133,9 +139,12 @@ module.exports = function() {
bufferSize: 64*1024
});
inStream.on("end", onDone);
inStream.on("error", onError);
signObj = crypto.createSign("sha1");
signObj.on("error", onError);
//this will call the onDone method
inStream.pipe(signObj);
console.info('end of method');
}

};
7 changes: 4 additions & 3 deletions lib/zips-list-to-crx.js
@@ -1,7 +1,8 @@
module.exports = function() {
var grunt = require("grunt"), CrxCreatorConstructor = require('./createCrxWithOpenSSL.js'), crxCreator = new CrxCreatorConstructor();
var grunt = require("grunt"), CrxCreatorConstructor = require('./createCrxWithOpenSSL.js'),
crxCreator = new CrxCreatorConstructor(), async = require("async");

this.thickThing = function (options, allSrcZips, crxDestination, originalSrcZip, originalCrxDestination, onError) {
this.thickThing = function (options, allSrcZips, crxDestination, originalSrcZip, originalCrxDestination, onDone, onError) {
var destinationDirectory, destinationFilename, destinationIsDir = false;
if (allSrcZips == null || allSrcZips.length===0) {
onError('The `'+ originalSrcZip+'` file(s) specification matched no files.');
Expand Down Expand Up @@ -30,7 +31,7 @@ module.exports = function() {
}
fullDestination = destinationCoordinates.directory+destinationCoordinates.filename;
if (grunt.file.isDir(fullDestination)) {
onError('Supposed output file `'+originalCrxDestination+'` is an existing directory. Use slash in the end if you meant to place file inside that directory.');
onError('Supposed output file `' + fullDestination + '` is an existing directory. Use slash in the end if you meant to place file inside that directory.');
return ;
}
crxCreator.generateCrxFile(srcPath, fullDestination, options.privateKey);
Expand Down
2 changes: 1 addition & 1 deletion tasks/zip_to_crx.js
Expand Up @@ -39,7 +39,7 @@ module.exports = function(grunt) {
allInputFilesTripples = this.files;
allInputFilesTripples.forEach(function(filesTripple) {
var allSrcZips = filesTripple.src, crxDestination = filesTripple.dest, originalSrcZip = filesTripple.orig.src, error;
error = zipsToCrx.thickThing(options, allSrcZips, crxDestination, originalSrcZip, filesTripple.orig.dest, function(error) {
error = zipsToCrx.thickThing(options, allSrcZips, crxDestination, originalSrcZip, filesTripple.orig.dest, function(){}, function(error) {
grunt.log.warn(error);
});
});
Expand Down
28 changes: 21 additions & 7 deletions test/zip_to_crx_test.js
Expand Up @@ -28,6 +28,7 @@ exports.zip_to_crx = {
setUp: function(done) {
this.wrongPrivateKey = { privateKey: 'doesNotExists.pem' };
this.goodPrivateKey = { privateKey: 'test/ssl-keys/private-key.pem' };
this.faultyPrivateKey = { privateKey: 'test/ssl-keys/faulty-key.pem' };
this.nullSrcZips = null;
this.emptySrcZips = [];
this.doesNotExistsSrcZips = ['doesNotExists.zip'];
Expand All @@ -44,7 +45,7 @@ exports.zip_to_crx = {
// setup here if necessary
done();
},
error_in_configuration: function(test) {
/*error_in_configuration: function(test) {
var originalSrcZip = this.originalSrcZip;
var doesNotExistsSrcZip = this.doesNotExistsSrcZips[0];
var multipleGoodSrcZips = this.multipleGoodSrcZips;
Expand All @@ -68,22 +69,35 @@ exports.zip_to_crx = {
test.equal(onError, 'Source specification `'+originalSrcZip+'` matches multiple ('+multipleGoodSrcZips.length+') files. Corresponding `dest` must be a directory.', 'should be ');
});
test.done();
}/*,
default_options: function(test) {
},*/
faulty_pem_file: function(test) {
var originalSrcZip = this.originalSrcZip;
var multipleGoodSrcZips = this.multipleGoodSrcZips;
test.expect(1);
zipsListToCrx.thickThing(this.faultyPrivateKey, this.goodSrcZips, this.fileCrxDestination, this.originalSrcZip, this.originalCrxDestination, function(onError){
test.equal(onError, 'wtf', 'should be ');
});
test.done();
}/*,
multiple_crx: function(test) {
//this.multipleGoodSrcZips = ['test/data/test-1.zip', 'test/data/test-2.zip'];
//this.directoryCrxDestination = 'tmp/distribution/';
test.expect(2);
var actual = grunt.file.read('tmp/default_options');
var expected = grunt.file.read('test/expected/default_options');
test.equal(actual, expected, 'should describe what the default behavior is.');
test.done();
},
custom_options: function(test) {
single_crx: function(test) {
//this.goodSrcZips = ['test/data/test-1.zip'];
//this.fileCrxDestination = 'tmp/distribution/file.crx';
test.expect(1);
var actual = grunt.file.read('tmp/custom_options');
var expected = grunt.file.read('test/expected/custom_options');
test.equal(actual, expected, 'should describe what the custom option(s) behavior is.');
var actual = grunt.file.read('tmp/default_options');
var expected = grunt.file.read('test/expected/default_options');
test.equal(actual, expected, 'should describe what the default behavior is.');
test.done();
}*/
Expand Down

0 comments on commit 75bfc89

Please sign in to comment.