Merge branch 'master' of https://github.com/seejohnrun/haste-server.git
This commit is contained in:
commit
7514df5d98
|
@ -40,7 +40,7 @@ STDOUT. Check the README there for more details and usages.
|
||||||
* `keyLength` - the length of the keys to user (default 10)
|
* `keyLength` - the length of the keys to user (default 10)
|
||||||
* `maxLength` - maximum length of a paste (default none)
|
* `maxLength` - maximum length of a paste (default none)
|
||||||
* `staticMaxAge` - max age for static assets (86400)
|
* `staticMaxAge` - max age for static assets (86400)
|
||||||
* `recompressStatisAssets` - whether or not to compile static js assets (true)
|
* `recompressStaticAssets` - whether or not to compile static js assets (true)
|
||||||
* `documents` - static documents to serve (ex: http://hastebin.com/about.com)
|
* `documents` - static documents to serve (ex: http://hastebin.com/about.com)
|
||||||
in addition to static assets. These will never expire.
|
in addition to static assets. These will never expire.
|
||||||
* `storage` - storage options (see below)
|
* `storage` - storage options (see below)
|
||||||
|
|
|
@ -1,24 +1,32 @@
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var DictionaryGenerator = function(options) {
|
module.exports = class DictionaryGenerator {
|
||||||
//Options
|
|
||||||
|
constructor(options, readyCallback) {
|
||||||
|
// Check options format
|
||||||
if (!options) throw Error('No options passed to generator');
|
if (!options) throw Error('No options passed to generator');
|
||||||
if (!options.path) throw Error('No dictionary path specified in options');
|
if (!options.path) throw Error('No dictionary path specified in options');
|
||||||
|
|
||||||
//Load dictionary
|
// Load dictionary
|
||||||
fs.readFile(options.path, 'utf8', (err, data) => {
|
fs.readFile(options.path, 'utf8', (err, data) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
this.dictionary = data.split(/[\n\r]+/);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
//Generates a dictionary-based key, of keyLength words
|
this.dictionary = data.split(/[\n\r]+/);
|
||||||
DictionaryGenerator.prototype.createKey = function(keyLength) {
|
|
||||||
var text = '';
|
if (readyCallback) readyCallback();
|
||||||
for(var i = 0; i < keyLength; i++)
|
});
|
||||||
text += this.dictionary[Math.floor(Math.random() * this.dictionary.length)];
|
}
|
||||||
|
|
||||||
|
// Generates a dictionary-based key, of keyLength words
|
||||||
|
createKey(keyLength) {
|
||||||
|
let text = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < keyLength; i++) {
|
||||||
|
const index = Math.floor(Math.random() * this.dictionary.length);
|
||||||
|
text += this.dictionary[index];
|
||||||
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = DictionaryGenerator;
|
};
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
||||||
var PhoneticKeyGenerator = function() {
|
|
||||||
// No options
|
const randOf = (collection) => {
|
||||||
|
return () => {
|
||||||
|
return collection[Math.floor(Math.random() * collection.length)];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate a phonetic key
|
// Helper methods to get an random vowel or consonant
|
||||||
PhoneticKeyGenerator.prototype.createKey = function(keyLength) {
|
const randVowel = randOf('aeiou');
|
||||||
var text = '';
|
const randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
|
||||||
var start = Math.round(Math.random());
|
|
||||||
for (var i = 0; i < keyLength; i++) {
|
module.exports = class PhoneticKeyGenerator {
|
||||||
text += (i % 2 == start) ? this.randConsonant() : this.randVowel();
|
|
||||||
|
// Generate a phonetic key of alternating consonant & vowel
|
||||||
|
createKey(keyLength) {
|
||||||
|
let text = '';
|
||||||
|
const start = Math.round(Math.random());
|
||||||
|
|
||||||
|
for (let i = 0; i < keyLength; i++) {
|
||||||
|
text += (i % 2 == start) ? randConsonant() : randVowel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxyz';
|
|
||||||
PhoneticKeyGenerator.vowels = 'aeiou';
|
|
||||||
|
|
||||||
// Get an random vowel
|
|
||||||
PhoneticKeyGenerator.prototype.randVowel = function() {
|
|
||||||
return PhoneticKeyGenerator.vowels[
|
|
||||||
Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get an random consonant
|
|
||||||
PhoneticKeyGenerator.prototype.randConsonant = function() {
|
|
||||||
return PhoneticKeyGenerator.consonants[
|
|
||||||
Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = PhoneticKeyGenerator;
|
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
var RandomKeyGenerator = function(options) {
|
module.exports = class RandomKeyGenerator {
|
||||||
if (!options) {
|
|
||||||
options = {};
|
|
||||||
}
|
|
||||||
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
};
|
|
||||||
|
|
||||||
// Generate a random key
|
// Initialize a new generator with the given keySpace
|
||||||
RandomKeyGenerator.prototype.createKey = function(keyLength) {
|
constructor(options = {}) {
|
||||||
|
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a key of the given length
|
||||||
|
createKey(keyLength) {
|
||||||
var text = '';
|
var text = '';
|
||||||
var index;
|
|
||||||
for (var i = 0; i < keyLength; i++) {
|
for (var i = 0; i < keyLength; i++) {
|
||||||
index = Math.floor(Math.random() * this.keyspace.length);
|
const index = Math.floor(Math.random() * this.keyspace.length);
|
||||||
text += this.keyspace.charAt(index);
|
text += this.keyspace.charAt(index);
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = RandomKeyGenerator;
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "haste",
|
"name": "haste",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": {
|
"async": {
|
||||||
"version": "0.1.22",
|
"version": "0.1.22",
|
||||||
|
@ -11,7 +12,10 @@
|
||||||
"async-cache": {
|
"async-cache": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/async-cache/-/async-cache-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/async-cache/-/async-cache-1.0.0.tgz",
|
||||||
"integrity": "sha1-yH9tgMcrOU7g+QYe3rJNjEtiKto="
|
"integrity": "sha1-yH9tgMcrOU7g+QYe3rJNjEtiKto=",
|
||||||
|
"requires": {
|
||||||
|
"lru-cache": "2.3.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -23,6 +27,9 @@
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/bl/-/bl-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/bl/-/bl-1.0.3.tgz",
|
||||||
"integrity": "sha1-/FQhoo/UImA2w7OJGmaiW8ZNIm4=",
|
"integrity": "sha1-/FQhoo/UImA2w7OJGmaiW8ZNIm4=",
|
||||||
|
"requires": {
|
||||||
|
"readable-stream": "2.0.6"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isarray": {
|
"isarray": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -32,7 +39,15 @@
|
||||||
"readable-stream": {
|
"readable-stream": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz",
|
||||||
"integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44="
|
"integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=",
|
||||||
|
"requires": {
|
||||||
|
"core-util-is": "1.0.2",
|
||||||
|
"inherits": "2.0.3",
|
||||||
|
"isarray": "1.0.0",
|
||||||
|
"process-nextick-args": "1.0.7",
|
||||||
|
"string_decoder": "0.10.31",
|
||||||
|
"util-deprecate": "1.0.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -40,7 +55,11 @@
|
||||||
"version": "1.1.8",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"balanced-match": "1.0.0",
|
||||||
|
"concat-map": "0.0.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"browser-stdout": {
|
"browser-stdout": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
|
@ -56,7 +75,11 @@
|
||||||
"busboy": {
|
"busboy": {
|
||||||
"version": "0.2.4",
|
"version": "0.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.4.tgz",
|
||||||
"integrity": "sha1-GXfpbh7ohGSWUevfVIypAHWLp/M="
|
"integrity": "sha1-GXfpbh7ohGSWUevfVIypAHWLp/M=",
|
||||||
|
"requires": {
|
||||||
|
"dicer": "0.2.3",
|
||||||
|
"readable-stream": "1.1.14"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"colors": {
|
"colors": {
|
||||||
"version": "0.6.2",
|
"version": "0.6.2",
|
||||||
|
@ -67,7 +90,10 @@
|
||||||
"version": "2.9.0",
|
"version": "2.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
|
||||||
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
|
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"graceful-readlink": "1.0.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
|
@ -78,7 +104,13 @@
|
||||||
"connect": {
|
"connect": {
|
||||||
"version": "3.4.1",
|
"version": "3.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/connect/-/connect-3.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/connect/-/connect-3.4.1.tgz",
|
||||||
"integrity": "sha1-ohNh0/QJnvdhzabcSpc7seuwo00="
|
"integrity": "sha1-ohNh0/QJnvdhzabcSpc7seuwo00=",
|
||||||
|
"requires": {
|
||||||
|
"debug": "2.2.0",
|
||||||
|
"finalhandler": "0.4.1",
|
||||||
|
"parseurl": "1.3.1",
|
||||||
|
"utils-merge": "1.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"connect-ratelimit": {
|
"connect-ratelimit": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
|
@ -103,12 +135,19 @@
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
||||||
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo="
|
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
|
||||||
|
"requires": {
|
||||||
|
"ms": "0.7.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"dicer": {
|
"dicer": {
|
||||||
"version": "0.2.3",
|
"version": "0.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.3.tgz",
|
||||||
"integrity": "sha1-8AKBGJpVwjUe+ASQpP6fssWcSTk="
|
"integrity": "sha1-8AKBGJpVwjUe+ASQpP6fssWcSTk=",
|
||||||
|
"requires": {
|
||||||
|
"readable-stream": "1.1.14",
|
||||||
|
"streamsearch": "0.1.2"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"diff": {
|
"diff": {
|
||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
|
@ -145,7 +184,13 @@
|
||||||
"finalhandler": {
|
"finalhandler": {
|
||||||
"version": "0.4.1",
|
"version": "0.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-0.4.1.tgz",
|
||||||
"integrity": "sha1-haF8bFmpRxfSYtYSMNSw6+PUoU0="
|
"integrity": "sha1-haF8bFmpRxfSYtYSMNSw6+PUoU0=",
|
||||||
|
"requires": {
|
||||||
|
"debug": "2.2.0",
|
||||||
|
"escape-html": "1.0.3",
|
||||||
|
"on-finished": "2.3.0",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -162,7 +207,15 @@
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
|
||||||
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
|
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"fs.realpath": "1.0.0",
|
||||||
|
"inflight": "1.0.6",
|
||||||
|
"inherits": "2.0.3",
|
||||||
|
"minimatch": "3.0.4",
|
||||||
|
"once": "1.4.0",
|
||||||
|
"path-is-absolute": "1.0.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"graceful-fs": {
|
"graceful-fs": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.11",
|
||||||
|
@ -188,11 +241,21 @@
|
||||||
"integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=",
|
"integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"he": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
|
||||||
|
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"inflight": {
|
"inflight": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"once": "1.4.0",
|
||||||
|
"wrappy": "1.0.2"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
|
@ -204,66 +267,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
|
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
|
||||||
},
|
},
|
||||||
"json3": {
|
|
||||||
"version": "3.3.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
|
|
||||||
"integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash._baseassign": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
|
|
||||||
"integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash._basecopy": {
|
|
||||||
"version": "3.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
|
|
||||||
"integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash._basecreate": {
|
|
||||||
"version": "3.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz",
|
|
||||||
"integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash._getnative": {
|
|
||||||
"version": "3.9.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
|
|
||||||
"integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash._isiterateecall": {
|
|
||||||
"version": "3.0.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
|
|
||||||
"integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash.create": {
|
|
||||||
"version": "3.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz",
|
|
||||||
"integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash.isarguments": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
|
|
||||||
"integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash.isarray": {
|
|
||||||
"version": "3.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
|
|
||||||
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lodash.keys": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
|
|
||||||
"integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"lru-cache": {
|
"lru-cache": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.3.1.tgz",
|
||||||
|
@ -278,7 +281,10 @@
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"brace-expansion": "1.1.8"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
|
@ -290,26 +296,27 @@
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"minimist": "0.0.8"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"mocha": {
|
"mocha": {
|
||||||
"version": "3.4.2",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-3.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/mocha/-/mocha-4.0.1.tgz",
|
||||||
"integrity": "sha1-0O9NMyEm2/GNDWQMmzgt1IvpdZQ=",
|
"integrity": "sha512-evDmhkoA+cBNiQQQdSKZa2b9+W2mpLoj50367lhy+Klnx9OV8XlCIhigUnn1gaTFLQCa0kdNhEGDr0hCXOQFDw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"requires": {
|
||||||
"debug": {
|
"browser-stdout": "1.3.0",
|
||||||
"version": "2.6.0",
|
"commander": "2.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.0.tgz",
|
"debug": "2.2.0",
|
||||||
"integrity": "sha1-vFlryr52F/Edn6FTYe3tVgi4SZs=",
|
"diff": "3.2.0",
|
||||||
"dev": true
|
"escape-string-regexp": "1.0.5",
|
||||||
},
|
"glob": "7.1.1",
|
||||||
"ms": {
|
"growl": "1.9.2",
|
||||||
"version": "0.7.2",
|
"he": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz",
|
"mkdirp": "0.5.1",
|
||||||
"integrity": "sha1-riXPJRKziFodldfwN4aNhDESR2U=",
|
"supports-color": "3.1.2"
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
|
@ -325,13 +332,19 @@
|
||||||
"on-finished": {
|
"on-finished": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||||
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc="
|
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
|
||||||
|
"requires": {
|
||||||
|
"ee-first": "1.1.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"wrappy": "1.0.2"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"packet-reader": {
|
"packet-reader": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
|
@ -352,7 +365,16 @@
|
||||||
"pg": {
|
"pg": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/pg/-/pg-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/pg/-/pg-4.1.1.tgz",
|
||||||
"integrity": "sha1-mEgKz8089qP5Yhyl1FiUFVgqVzI="
|
"integrity": "sha1-mEgKz8089qP5Yhyl1FiUFVgqVzI=",
|
||||||
|
"requires": {
|
||||||
|
"buffer-writer": "1.0.0",
|
||||||
|
"generic-pool": "2.1.1",
|
||||||
|
"packet-reader": "0.2.0",
|
||||||
|
"pg-connection-string": "0.1.3",
|
||||||
|
"pg-types": "1.6.0",
|
||||||
|
"pgpass": "0.0.3",
|
||||||
|
"semver": "4.3.6"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"pg-connection-string": {
|
"pg-connection-string": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
|
@ -367,7 +389,10 @@
|
||||||
"pgpass": {
|
"pgpass": {
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-0.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-0.0.3.tgz",
|
||||||
"integrity": "sha1-EuZ+NDsxicLzEgbrycwL7//PkUA="
|
"integrity": "sha1-EuZ+NDsxicLzEgbrycwL7//PkUA=",
|
||||||
|
"requires": {
|
||||||
|
"split": "0.3.3"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"pkginfo": {
|
"pkginfo": {
|
||||||
"version": "0.2.3",
|
"version": "0.2.3",
|
||||||
|
@ -382,7 +407,13 @@
|
||||||
"readable-stream": {
|
"readable-stream": {
|
||||||
"version": "1.1.14",
|
"version": "1.1.14",
|
||||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||||
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk="
|
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
|
||||||
|
"requires": {
|
||||||
|
"core-util-is": "1.0.2",
|
||||||
|
"inherits": "2.0.3",
|
||||||
|
"isarray": "0.0.1",
|
||||||
|
"string_decoder": "0.10.31"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"redis": {
|
"redis": {
|
||||||
"version": "0.8.1",
|
"version": "0.8.1",
|
||||||
|
@ -392,7 +423,10 @@
|
||||||
"redis-url": {
|
"redis-url": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/redis-url/-/redis-url-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/redis-url/-/redis-url-0.1.0.tgz",
|
||||||
"integrity": "sha1-TaXlsYG2wMrW4aVcf1Co5u53ebs="
|
"integrity": "sha1-TaXlsYG2wMrW4aVcf1Co5u53ebs=",
|
||||||
|
"requires": {
|
||||||
|
"redis": "0.8.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"request": {
|
"request": {
|
||||||
"version": "2.9.203",
|
"version": "2.9.203",
|
||||||
|
@ -404,51 +438,31 @@
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
|
||||||
"integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto="
|
"integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto="
|
||||||
},
|
},
|
||||||
"should": {
|
"source-map": {
|
||||||
"version": "11.2.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/should/-/should-11.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
"integrity": "sha1-kPVRRVUtAc/CAGZuToGKHJZw7aI=",
|
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"should-equal": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-C26VFvJgGp+wuy3MNpr6HH4gCvc=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"should-format": {
|
|
||||||
"version": "3.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz",
|
|
||||||
"integrity": "sha1-m/yPdPo5IFxT04w01xcwPidxJPE=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"should-type": {
|
|
||||||
"version": "1.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/should-type/-/should-type-1.4.0.tgz",
|
|
||||||
"integrity": "sha1-B1bYzoRt/QmEOmlHcZ36DUz/XPM=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"should-type-adaptors": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-7+VVPN9oz/ZuXF9RtxLcNRx3vqo=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"should-util": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/should-util/-/should-util-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-yYzaN0qmsZDfi6h8mInCtNtiAGM=",
|
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"split": {
|
"split": {
|
||||||
"version": "0.3.3",
|
"version": "0.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz",
|
||||||
"integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8="
|
"integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=",
|
||||||
|
"requires": {
|
||||||
|
"through": "2.3.8"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"st": {
|
"st": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/st/-/st-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/st/-/st-1.1.0.tgz",
|
||||||
"integrity": "sha1-c7ltsLdkTZp4zjg0o+T37G6Hz3Y="
|
"integrity": "sha1-c7ltsLdkTZp4zjg0o+T37G6Hz3Y=",
|
||||||
|
"requires": {
|
||||||
|
"async-cache": "1.0.0",
|
||||||
|
"bl": "1.0.3",
|
||||||
|
"fd": "0.0.2",
|
||||||
|
"graceful-fs": "4.1.11",
|
||||||
|
"mime": "1.3.6",
|
||||||
|
"negotiator": "0.6.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"stack-trace": {
|
"stack-trace": {
|
||||||
"version": "0.0.10",
|
"version": "0.0.10",
|
||||||
|
@ -469,7 +483,10 @@
|
||||||
"version": "3.1.2",
|
"version": "3.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
|
||||||
"integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
|
"integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "1.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"through": {
|
"through": {
|
||||||
"version": "2.3.8",
|
"version": "2.3.8",
|
||||||
|
@ -477,9 +494,20 @@
|
||||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
|
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
|
||||||
},
|
},
|
||||||
"uglify-js": {
|
"uglify-js": {
|
||||||
"version": "1.3.3",
|
"version": "3.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.6.tgz",
|
||||||
"integrity": "sha1-3dPpiqJ/X0flic+z+VzduiYJYZA="
|
"integrity": "sha512-/rseyxEKEVMBo8279lqpoJgD6C/i/CIi+9TJDvWmb+Xo6mqMKwjA8Io3IMHlcXQzj99feR6zrN8m3wqqvm/nYA==",
|
||||||
|
"requires": {
|
||||||
|
"commander": "2.11.0",
|
||||||
|
"source-map": "0.6.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"commander": {
|
||||||
|
"version": "2.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
|
||||||
|
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ=="
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"unpipe": {
|
"unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -499,7 +527,16 @@
|
||||||
"winston": {
|
"winston": {
|
||||||
"version": "0.6.2",
|
"version": "0.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/winston/-/winston-0.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/winston/-/winston-0.6.2.tgz",
|
||||||
"integrity": "sha1-QUT+JYbNwZphK/jANVkBMskGS9I="
|
"integrity": "sha1-QUT+JYbNwZphK/jANVkBMskGS9I=",
|
||||||
|
"requires": {
|
||||||
|
"async": "0.1.22",
|
||||||
|
"colors": "0.6.2",
|
||||||
|
"cycle": "1.0.3",
|
||||||
|
"eyes": "0.1.8",
|
||||||
|
"pkginfo": "0.2.3",
|
||||||
|
"request": "2.9.203",
|
||||||
|
"stack-trace": "0.0.10"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
|
|
11
package.json
11
package.json
|
@ -21,18 +21,17 @@
|
||||||
"winston": "0.6.2",
|
"winston": "0.6.2",
|
||||||
"redis-url": "0.1.0",
|
"redis-url": "0.1.0",
|
||||||
"redis": "0.8.1",
|
"redis": "0.8.1",
|
||||||
"uglify-js": "1.3.3",
|
"uglify-js": "3.1.6",
|
||||||
"busboy": "0.2.4",
|
"busboy": "0.2.4",
|
||||||
"pg": "4.1.1"
|
"pg": "4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "*",
|
"mocha": "^4.0.1"
|
||||||
"should": "*"
|
|
||||||
},
|
},
|
||||||
"bundledDependencies": [],
|
"bundledDependencies": [],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "0.10.35",
|
"node": "8.1.4",
|
||||||
"npm": "1.1.49"
|
"npm": "5.2.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"haste-server": "./server.js"
|
"haste-server": "./server.js"
|
||||||
|
@ -47,6 +46,6 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
"test": "mocha -r should spec/*"
|
"test": "mocha --recursive"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
server.js
14
server.js
|
@ -1,6 +1,7 @@
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var uglify = require('uglify-js');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
var connect = require('connect');
|
var connect = require('connect');
|
||||||
var route = require('connect-route');
|
var route = require('connect-route');
|
||||||
|
@ -54,19 +55,14 @@ else {
|
||||||
|
|
||||||
// Compress the static javascript assets
|
// Compress the static javascript assets
|
||||||
if (config.recompressStaticAssets) {
|
if (config.recompressStaticAssets) {
|
||||||
var jsp = require('uglify-js').parser;
|
|
||||||
var pro = require('uglify-js').uglify;
|
|
||||||
var list = fs.readdirSync('./static');
|
var list = fs.readdirSync('./static');
|
||||||
for (var j = 0; j < list.length; j++) {
|
for (var j = 0; j < list.length; j++) {
|
||||||
var item = list[i];
|
var item = list[j];
|
||||||
var orig_code, ast;
|
|
||||||
if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) {
|
if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) {
|
||||||
var dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3);
|
var dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3);
|
||||||
orig_code = fs.readFileSync('./static/' + item, 'utf8');
|
var orig_code = fs.readFileSync('./static/' + item, 'utf8');
|
||||||
ast = jsp.parse(orig_code);
|
|
||||||
ast = pro.ast_mangle(ast);
|
fs.writeFileSync('./static/' + dest, uglify.minify(orig_code).code, 'utf8');
|
||||||
ast = pro.ast_squeeze(ast);
|
|
||||||
fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8');
|
|
||||||
winston.info('compressed ' + item + ' into ' + dest);
|
winston.info('compressed ' + item + ' into ' + dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,7 @@
|
||||||
/* global describe, it */
|
/* global describe, it */
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
var DocumentHandler = require('../lib/document_handler');
|
var DocumentHandler = require('../lib/document_handler');
|
||||||
var Generator = require('../lib/key_generators/random');
|
var Generator = require('../lib/key_generators/random');
|
||||||
|
|
||||||
|
@ -10,13 +12,13 @@ describe('document_handler', function() {
|
||||||
it('should choose a key of the proper length', function() {
|
it('should choose a key of the proper length', function() {
|
||||||
var gen = new Generator();
|
var gen = new Generator();
|
||||||
var dh = new DocumentHandler({ keyLength: 6, keyGenerator: gen });
|
var dh = new DocumentHandler({ keyLength: 6, keyGenerator: gen });
|
||||||
dh.acceptableKey().length.should.equal(6);
|
assert.equal(6, dh.acceptableKey().length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should choose a default key length', function() {
|
it('should choose a default key length', function() {
|
||||||
var gen = new Generator();
|
var gen = new Generator();
|
||||||
var dh = new DocumentHandler({ keyGenerator: gen });
|
var dh = new DocumentHandler({ keyGenerator: gen });
|
||||||
dh.keyLength.should.equal(DocumentHandler.defaultKeyLength);
|
assert.equal(dh.keyLength, DocumentHandler.defaultKeyLength);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* global describe, it */
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const Generator = require('../../lib/key_generators/dictionary');
|
||||||
|
|
||||||
|
describe('RandomKeyGenerator', function() {
|
||||||
|
describe('randomKey', function() {
|
||||||
|
it('should throw an error if given no options', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
new Generator();
|
||||||
|
}, Error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if given no path', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
new Generator({});
|
||||||
|
}, Error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a key of the proper number of words from the given dictionary', () => {
|
||||||
|
const path = '/tmp/haste-server-test-dictionary';
|
||||||
|
const words = ['cat'];
|
||||||
|
fs.writeFileSync(path, words.join('\n'));
|
||||||
|
|
||||||
|
const gen = new Generator({path}, () => {
|
||||||
|
assert.equal('catcatcat', gen.createKey(3));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* global describe, it */
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const Generator = require('../../lib/key_generators/phonetic');
|
||||||
|
|
||||||
|
const vowels = 'aeiou';
|
||||||
|
const consonants = 'bcdfghjklmnpqrstvwxyz';
|
||||||
|
|
||||||
|
describe('RandomKeyGenerator', () => {
|
||||||
|
describe('randomKey', () => {
|
||||||
|
it('should return a key of the proper length', () => {
|
||||||
|
const gen = new Generator();
|
||||||
|
assert.equal(6, gen.createKey(6).length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should alternate consonants and vowels', () => {
|
||||||
|
const gen = new Generator();
|
||||||
|
|
||||||
|
const key = gen.createKey(3);
|
||||||
|
|
||||||
|
assert.ok(consonants.includes(key[0]));
|
||||||
|
assert.ok(consonants.includes(key[2]));
|
||||||
|
assert.ok(vowels.includes(key[1]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* global describe, it */
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const Generator = require('../../lib/key_generators/random');
|
||||||
|
|
||||||
|
describe('RandomKeyGenerator', () => {
|
||||||
|
describe('randomKey', () => {
|
||||||
|
it('should return a key of the proper length', () => {
|
||||||
|
const gen = new Generator();
|
||||||
|
assert.equal(6, gen.createKey(6).length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use a key from the given keyset if given', () => {
|
||||||
|
const gen = new Generator({keyspace: 'A'});
|
||||||
|
assert.equal('AAAAAA', gen.createKey(6));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,10 +1,12 @@
|
||||||
/* global it, describe, afterEach */
|
/* global it, describe, afterEach */
|
||||||
|
|
||||||
var RedisDocumentStore = require('../lib/document_stores/redis');
|
var assert = require('assert');
|
||||||
|
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
winston.remove(winston.transports.Console);
|
winston.remove(winston.transports.Console);
|
||||||
|
|
||||||
|
var RedisDocumentStore = require('../lib/document_stores/redis');
|
||||||
|
|
||||||
describe('redis_document_store', function() {
|
describe('redis_document_store', function() {
|
||||||
|
|
||||||
/* reconnect to redis on each test */
|
/* reconnect to redis on each test */
|
||||||
|
@ -21,7 +23,7 @@ describe('redis_document_store', function() {
|
||||||
var store = new RedisDocumentStore({ expire: 10 });
|
var store = new RedisDocumentStore({ expire: 10 });
|
||||||
store.set('hello1', 'world', function() {
|
store.set('hello1', 'world', function() {
|
||||||
RedisDocumentStore.client.ttl('hello1', function(err, res) {
|
RedisDocumentStore.client.ttl('hello1', function(err, res) {
|
||||||
res.should.be.above(1);
|
assert.ok(res > 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,7 +33,7 @@ describe('redis_document_store', function() {
|
||||||
var store = new RedisDocumentStore({ expire: 10 });
|
var store = new RedisDocumentStore({ expire: 10 });
|
||||||
store.set('hello2', 'world', function() {
|
store.set('hello2', 'world', function() {
|
||||||
RedisDocumentStore.client.ttl('hello2', function(err, res) {
|
RedisDocumentStore.client.ttl('hello2', function(err, res) {
|
||||||
res.should.equal(-1);
|
assert.equal(-1, res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -41,7 +43,7 @@ describe('redis_document_store', function() {
|
||||||
var store = new RedisDocumentStore({ expire: false });
|
var store = new RedisDocumentStore({ expire: false });
|
||||||
store.set('hello3', 'world', function() {
|
store.set('hello3', 'world', function() {
|
||||||
RedisDocumentStore.client.ttl('hello3', function(err, res) {
|
RedisDocumentStore.client.ttl('hello3', function(err, res) {
|
||||||
res.should.equal(-1);
|
assert.equal(-1, res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue