Commit 6e4c0873 authored by John Crepezzi's avatar John Crepezzi
Browse files

Remove hashlib dependency and switch to mocha for testing

parent b2519784
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -86,9 +86,9 @@ DocumentHandler.prototype.handlePost = function(request, response) {
  });
};

// Get a random key that hasn't been already used
// Keep choosing keys until one isn't taken
DocumentHandler.prototype.chooseKey = function(callback) {
  var key = this.keyGenerator.createKey(this.keyLength);
  var key = this.acceptableKey();
  var _this = this;
  this.store.get(key, function(ret) {
    if (ret) {
@@ -99,4 +99,8 @@ DocumentHandler.prototype.chooseKey = function(callback) {
  }); 
};

DocumentHandler.prototype.acceptableKey = function() {
  return this.keyGenerator.createKey(this.keyLength);
};

module.exports = DocumentHandler;
+10 −3
Original line number Diff line number Diff line
var fs = require('fs');
var crypto = require('crypto');

var winston = require('winston');
var hashlib = require('hashlib');

// For storing in files
// options[type] = file
@@ -12,12 +12,19 @@ var FileDocumentStore = function(options) {
  this.expire = options.expire;
};

// Generate md5 of a string
FileDocumentStore.md5 = function(str) {
  var md5sum = crypto.createHash('md5');
  md5sum.update(str);
  return md5sum.digest('hex');
};

// Save data in a file, key as md5 - since we don't know what we could be passed here
FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) {
  try {
    var _this = this;
    fs.mkdir(this.basePath, '700', function() {
      fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function(err) {
      fs.writeFile(_this.basePath + '/' + _this.md5(key), data, 'utf8', function(err) {
        if (err) {
          callback(false);
        }
@@ -37,7 +44,7 @@ FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) {
// Get data from a file from key
FileDocumentStore.prototype.get = function(key, callback, skipExpire) {
  var _this = this;
  fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) {
  fs.readFile(this.basePath + '/' + _this..md5(key), 'utf8', function(err, data) {
    if (err) {
      callback(false);
    }
+3 −0
Original line number Diff line number Diff line
var RandomKeyGenerator = function(options) {
  if (!options) {
    options = {};
  }
  this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
};

+0 −1
Original line number Diff line number Diff line
var redis = require('redis');
var winston = require('winston');
var hashlib = require('hashlib');

// For storing in redis
// options[type] = redis
+3 −3
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@

	"dependencies": {
		"winston": "*",
    "hashlib": "*",
    "connect": "*",
    "uglify-js": "*"
	},

	"devDependencies": {
    "jasmine-node": "*"
    "mocha": "*",
    "should": "*"
  },

	"bundledDependencies": [],
@@ -46,7 +46,7 @@

	"scripts": {
		"start": "node server.js",
    "test": "jasmine-node spec"
    "test": "mocha -r should spec/*"
	}

}
Loading