feat: ✨ Created a mini nodeJS server with NewMan for testing without PostMan GUI.
This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
41
node_modules/object-hash/test/blob.js
generated
vendored
Normal file
41
node_modules/object-hash/test/blob.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var hash = require('../index');
|
||||
|
||||
if (typeof Blob !== 'undefined') {
|
||||
describe('hash()ing Blob objects', function() {
|
||||
var blob;
|
||||
before('create blob', function() {
|
||||
try {
|
||||
blob = new Blob(['ABC']);
|
||||
} catch(e) {
|
||||
// https://github.com/ariya/phantomjs/issues/11013
|
||||
if (!e.message.match(/'\[object BlobConstructor\]' is not a constructor/)) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
var builder = new WebKitBlobBuilder();
|
||||
builder.append('ABC');
|
||||
blob = builder.getBlob();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw when trying to hash a blob', function() {
|
||||
assert.throws(function() {
|
||||
hash(blob);
|
||||
}, /not supported/);
|
||||
|
||||
assert.throws(function() {
|
||||
hash({abcdef: blob});
|
||||
}, /not supported/);
|
||||
});
|
||||
|
||||
it('should not throw when trying to hash a blob with ignoreUnknown', function() {
|
||||
var opt = {ignoreUnknown: true};
|
||||
|
||||
assert.ok(validSha1.test(hash(blob, opt)), 'ignore Blob');
|
||||
assert.ok(validSha1.test(hash({abcdef: blob}, opt)), 'ignore Blob');
|
||||
});
|
||||
});
|
||||
}
|
290
node_modules/object-hash/test/index.js
generated
vendored
Normal file
290
node_modules/object-hash/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var crypto = require('crypto');
|
||||
var hash = require('../index');
|
||||
var validSha1 = /^[0-9a-f]{40}$/i;
|
||||
|
||||
describe('hash', function() {
|
||||
it('throws when nothing to hash', function () {
|
||||
assert.throws(hash, 'no arguments');
|
||||
assert.throws(function() {
|
||||
hash(undefined, {algorithm: 'md5'});
|
||||
}, 'undefined');
|
||||
});
|
||||
|
||||
it('throws when passed an invalid options', function() {
|
||||
assert.throws(function() {
|
||||
hash({foo: 'bar'}, {algorithm: 'shalala'});
|
||||
}, 'bad algorithm');
|
||||
assert.throws(function() {
|
||||
hash({foo: 'bar'}, {encoding: 'base16'});
|
||||
}, 'bad encoding');
|
||||
});
|
||||
|
||||
it('hashes a simple object', function() {
|
||||
assert.ok(validSha1.test(hash({foo: 'bar', bar: 'baz'})), 'hash object');
|
||||
});
|
||||
|
||||
if (typeof Buffer !== 'undefined') {
|
||||
it('can return buffers', function() {
|
||||
assert.ok(Buffer.isBuffer(hash({foo: 'bar', bar: 'baz'}, {encoding: 'buffer'})), 'hash object');
|
||||
});
|
||||
}
|
||||
|
||||
it('hashes identical objects with different key ordering', function() {
|
||||
var hash1 = hash({foo: 'bar', bar: 'baz'});
|
||||
var hash2 = hash({bar: 'baz', foo: 'bar'});
|
||||
var hash3 = hash({bar: 'foo', foo: 'baz'});
|
||||
assert.equal(hash1, hash2, 'hashes are equal');
|
||||
assert.notEqual(hash1, hash3, 'different objects not equal');
|
||||
});
|
||||
|
||||
it('respects object key ordering when unorderedObjects = false', function() {
|
||||
var hash1 = hash({foo: 'bar', bar: 'baz'}, { unorderedObjects: false });
|
||||
var hash2 = hash({bar: 'baz', foo: 'bar'}, { unorderedObjects: false });
|
||||
assert.notEqual(hash1, hash2, 'hashes are not equal');
|
||||
});
|
||||
|
||||
it('hashes only object keys when excludeValues option is set', function() {
|
||||
var hash1 = hash({foo: false, bar: 'OK'}, { excludeValues: true });
|
||||
var hash2 = hash({foo: true, bar: 'NO'}, { excludeValues: true });
|
||||
var hash3 = hash({foo: true, bar: 'OK', baz: false}, { excludeValues: true });
|
||||
assert.equal(hash1, hash2, 'values not in hash digest');
|
||||
assert.notEqual(hash1, hash3, 'different keys not equal');
|
||||
});
|
||||
|
||||
it('array values are hashed', function() {
|
||||
var hash1 = hash({foo: ['bar', 'baz'], bax: true });
|
||||
var hash2 = hash({foo: ['baz', 'bar'], bax: true });
|
||||
assert.notEqual(hash1, hash2, 'different array orders are unique');
|
||||
});
|
||||
|
||||
it('nested object values are hashed', function() {
|
||||
var hash1 = hash({foo: {bar: true, bax: 1}});
|
||||
var hash2 = hash({foo: {bar: true, bax: 1}});
|
||||
var hash3 = hash({foo: {bar: false, bax: 1}});
|
||||
assert.equal(hash1, hash2, 'hashes are equal');
|
||||
assert.notEqual(hash1, hash3, 'different objects not equal');
|
||||
});
|
||||
|
||||
it('sugar methods should be equivalent', function() {
|
||||
var obj = {foo: 'bar', baz: true};
|
||||
assert.equal(hash.keys(obj), hash(obj, {excludeValues: true}), 'keys');
|
||||
assert.equal(hash.sha1(obj), hash(obj, {algorithm: 'sha1'}), 'sha1');
|
||||
assert.equal(hash.MD5(obj), hash(obj, {algorithm: 'md5'}), 'md5');
|
||||
assert.equal(hash.keysMD5(obj),
|
||||
hash(obj, {algorithm: 'md5', excludeValues: true}), 'keys md5');
|
||||
});
|
||||
|
||||
it('array of nested object values are hashed', function() {
|
||||
var hash1 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
|
||||
var hash2 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
|
||||
var hash3 = hash({foo: [ {bar: false, bax: 2} ] });
|
||||
assert.equal(hash1, hash2, 'hashes are equal');
|
||||
assert.notEqual(hash1, hash3, 'different objects not equal');
|
||||
});
|
||||
|
||||
it("recursive objects don't blow up stack", function() {
|
||||
var hash1 = {foo: 'bar'};
|
||||
hash1.recursive = hash1;
|
||||
assert.doesNotThrow(function() {hash(hash1);}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
|
||||
});
|
||||
|
||||
it("recursive arrays don't blow up stack", function() {
|
||||
var hash1 = ['foo', 'bar'];
|
||||
hash1.push(hash1);
|
||||
assert.doesNotThrow(function() {hash(hash1);}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
|
||||
});
|
||||
|
||||
it("recursive arrays don't blow up stack with unorderedArrays", function() {
|
||||
var hash1 = ['foo', 'bar'];
|
||||
hash1.push(hash1);
|
||||
assert.doesNotThrow(function() {hash(hash1, {unorderedArrays: true});}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
|
||||
});
|
||||
|
||||
it("recursive handling tracks identity", function() {
|
||||
var hash1 = {k1: {k: 'v'}, k2: {k: 'k2'}};
|
||||
hash1.k1.r1 = hash1.k1;
|
||||
hash1.k2.r2 = hash1.k2;
|
||||
var hash2 = {k1: {k: 'v'}, k2: {k: 'k2'}};
|
||||
hash2.k1.r1 = hash2.k2;
|
||||
hash2.k2.r2 = hash2.k1;
|
||||
assert.notEqual(hash(hash1), hash(hash2), "order of recursive objects should matter");
|
||||
});
|
||||
|
||||
it("object types are hashed", function() {
|
||||
var hash1 = hash({foo: 'bar'});
|
||||
var hash2 = hash(['foo', 'bar']);
|
||||
assert.notEqual(hash1, hash2, "arrays and objects should not produce identical hashes");
|
||||
});
|
||||
|
||||
it("utf8 strings are hashed correctly", function() {
|
||||
var hash1 = hash('\u03c3'); // cf 83 in utf8
|
||||
var hash2 = hash('\u01c3'); // c7 83 in utf8
|
||||
assert.notEqual(hash1, hash2, "different strings with similar utf8 encodings should produce different hashes");
|
||||
});
|
||||
|
||||
it("strings passed as new String are hashed correctly", function() {
|
||||
var hash1 = hash(new String('foo'));
|
||||
assert.equal(hash1, '7cd3edacc4c9dd43908177508c112608a398bb9a');
|
||||
var hash2 = hash({foo: new String('bar')});
|
||||
assert.equal(hash2, 'a75c05bdca7d704bdfcd761913e5a4e4636e956b');
|
||||
});
|
||||
|
||||
it("various hashes in crypto.getHashes() should be supported", function() {
|
||||
var hashes = ['sha1', 'md5'];
|
||||
|
||||
if (crypto.getHashes) {
|
||||
// take all hashes from crypto.getHashes() starting with MD or SHA
|
||||
hashes = crypto.getHashes().filter(RegExp.prototype.test.bind(/^(md|sha)/i));
|
||||
}
|
||||
|
||||
var obj = {randomText: 'bananas'};
|
||||
|
||||
for (var i = 0; i < hashes.length; i++) {
|
||||
assert.ok(hash(obj, {algorithm: hashes[i]}), 'Algorithm ' + hashes[i] + ' should be supported');
|
||||
}
|
||||
});
|
||||
|
||||
it("null and 'Null' string produce different hashes", function() {
|
||||
var hash1 = hash({foo: null});
|
||||
var hash2 = hash({foo: 'Null'});
|
||||
assert.notEqual(hash1, hash2, "null and 'Null' should not produce identical hashes");
|
||||
});
|
||||
|
||||
it('Distinguish functions based on their properties', function() {
|
||||
|
||||
var a, b, c, d;
|
||||
function Foo() {}
|
||||
a = hash(Foo);
|
||||
|
||||
Foo.foo = 22;
|
||||
b = hash(Foo);
|
||||
|
||||
Foo.bar = "42";
|
||||
c = hash(Foo);
|
||||
|
||||
Foo.foo = "22";
|
||||
d = hash(Foo);
|
||||
|
||||
assert.notEqual(a,b, 'adding a property changes the hash');
|
||||
assert.notEqual(b,c, 'adding another property changes the hash');
|
||||
assert.notEqual(c,d, 'changing a property changes the hash');
|
||||
});
|
||||
|
||||
it('respectFunctionProperties = false', function() {
|
||||
|
||||
var a, b;
|
||||
function Foo() {}
|
||||
a = hash(Foo, {respectFunctionProperties: false});
|
||||
|
||||
Foo.foo = 22;
|
||||
b = hash(Foo, {respectFunctionProperties: false});
|
||||
|
||||
assert.equal(a,b, 'function properties are ignored');
|
||||
});
|
||||
|
||||
it('Distinguish functions based on prototype properties', function() {
|
||||
|
||||
var a, b, c, d;
|
||||
function Foo() {}
|
||||
a = hash(Foo);
|
||||
|
||||
Foo.prototype.foo = 22;
|
||||
b = hash(Foo);
|
||||
|
||||
Foo.prototype.bar = "42";
|
||||
c = hash(Foo);
|
||||
|
||||
Foo.prototype.foo = "22";
|
||||
d = hash(Foo);
|
||||
|
||||
assert.notEqual(a,b, 'adding a property to the prototype changes the hash');
|
||||
assert.notEqual(b,c, 'adding another property to the prototype changes the hash');
|
||||
assert.notEqual(c,d, 'changing a property in the prototype changes the hash');
|
||||
});
|
||||
|
||||
it('Distinguish objects based on their type', function() {
|
||||
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
|
||||
var f = new Foo(), b = new Bar();
|
||||
|
||||
assert.notEqual(hash(Foo), hash(Bar), 'Functions with different names should produce a different Hash.');
|
||||
assert.notEqual(hash(f), hash(b), 'Objects with different constructor should have a different Hash.');
|
||||
});
|
||||
|
||||
it('respectType = false', function() {
|
||||
var opt = { respectType: false };
|
||||
|
||||
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
|
||||
var f = new Foo(), b = new Bar();
|
||||
assert.equal(hash(f, opt), hash(b, opt), 'Hashing should disregard the different constructor');
|
||||
|
||||
|
||||
var ha, hb;
|
||||
function F() {}
|
||||
ha = hash(F, opt);
|
||||
|
||||
F.prototype.meaningOfLife = 42;
|
||||
hb = hash(F, opt);
|
||||
|
||||
assert.equal(ha, hb, 'Hashing should disregard changes in the function\'s prototype');
|
||||
});
|
||||
|
||||
it('unorderedArrays = false', function() {
|
||||
var ha, hb;
|
||||
ha = hash([1, 2, 3]);
|
||||
hb = hash([3, 2, 1]);
|
||||
|
||||
assert.notEqual(ha, hb, 'Hashing should respect the order of array entries');
|
||||
});
|
||||
|
||||
it('unorderedArrays = true', function() {
|
||||
var opt = { unorderedArrays: true };
|
||||
|
||||
var ha, hb;
|
||||
ha = hash([1, 2, 3], opt);
|
||||
hb = hash([3, 2, 1], opt);
|
||||
|
||||
assert.equal(ha, hb, 'Hashing should not respect the order of array entries');
|
||||
|
||||
ha = hash([{a: 1}, {a: 2}], opt);
|
||||
hb = hash([{a: 2}, {a: 1}], opt);
|
||||
|
||||
assert.equal(ha, hb, 'Hashing should not respect the order of array entries');
|
||||
});
|
||||
|
||||
it('excludeKeys works', function() {
|
||||
var ha, hb;
|
||||
ha = hash({a: 1, b: 4}, { excludeKeys: function(key) { return key === 'b' } });
|
||||
hb = hash({a: 1});
|
||||
|
||||
assert.equal(ha, hb, 'Hashing should ignore key `b`');
|
||||
});
|
||||
|
||||
if (typeof Set !== 'undefined') {
|
||||
it('unorderedSets = false', function() {
|
||||
var opt = { unorderedSets: false };
|
||||
|
||||
var ha, hb;
|
||||
ha = hash(new Set([1, 2, 3]), opt);
|
||||
hb = hash(new Set([3, 2, 1]), opt);
|
||||
|
||||
assert.notEqual(ha, hb, 'Hashing should respect the order of Set entries');
|
||||
});
|
||||
|
||||
it('unorderedSets = true', function() {
|
||||
var ha, hb;
|
||||
ha = hash(new Set([1, 2, 3]));
|
||||
hb = hash(new Set([3, 2, 1]));
|
||||
|
||||
assert.equal(ha, hb, 'Hashing should not respect the order of Set entries');
|
||||
});
|
||||
}
|
||||
});
|
106
node_modules/object-hash/test/object-classes.js
generated
vendored
Normal file
106
node_modules/object-hash/test/object-classes.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var crypto = require('crypto');
|
||||
var stream = require('stream');
|
||||
var hash = require('../index');
|
||||
var validSha1 = /^[0-9a-f]{40}$/i;
|
||||
|
||||
describe('hash() objects with custom class names', function() {
|
||||
var builtinToString;
|
||||
beforeEach(function() {
|
||||
builtinToString = Object.prototype.toString;
|
||||
Object.prototype.toString = function() {
|
||||
if (this && typeof this.__className !== 'undefined') {
|
||||
return this.__className;
|
||||
}
|
||||
|
||||
return builtinToString.apply(this, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
Object.prototype.toString = builtinToString;
|
||||
});
|
||||
|
||||
it('should throw when trying to hash an unknown object', function() {
|
||||
assert.throws(function() {
|
||||
hash({a:1, __className: '[object Foo]'});
|
||||
}, /Unknown object type "foo"/);
|
||||
|
||||
assert.throws(function() {
|
||||
hash({a:1, __className: 'Foo'});
|
||||
}, /Unknown object type/);
|
||||
});
|
||||
|
||||
it('should not throw when trying to hash an unknown object with ignoreUnknown', function() {
|
||||
var opt = {ignoreUnknown: true};
|
||||
|
||||
assert.ok(validSha1.test(hash({a:1, __className: '[object Foo]'}, opt)));
|
||||
});
|
||||
|
||||
it('should not throw when trying to hash a weirdly-named object with ignoreUnknown', function() {
|
||||
var opt = {ignoreUnknown: true};
|
||||
|
||||
assert.ok(validSha1.test(hash({a:1, __className: 'Foo'}, opt)));
|
||||
});
|
||||
|
||||
it('should not delve further into a number of native types', function() {
|
||||
var nativeTypes = [
|
||||
'domwindow',
|
||||
'process', 'timer', 'pipe', 'tcp', 'udp', 'tty', 'statwatcher',
|
||||
'securecontext', 'connection', 'zlib', 'context', 'nodescript',
|
||||
'httpparser', 'dataview', 'signal', 'fsevent', 'tlswrap'
|
||||
];
|
||||
|
||||
for (var i = 0; i < nativeTypes.length; i++) {
|
||||
var obj = { foobar: 1, __className: '[object ' + nativeTypes[i] + ']' };
|
||||
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
|
||||
assert.strictEqual(serialized, nativeTypes[i]);
|
||||
}
|
||||
});
|
||||
|
||||
it('should hash xml based on its string representation', function() {
|
||||
var obj = {
|
||||
__className: '[object xml]',
|
||||
toString: function() { return 'Bananä' }
|
||||
};
|
||||
|
||||
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
|
||||
assert.strictEqual(serialized, 'xml:Bananä');
|
||||
});
|
||||
|
||||
it('should hash URLs based on its string representation', function() {
|
||||
var obj = {
|
||||
__className: '[object url]',
|
||||
toString: function() { return 'https://example.com/' }
|
||||
};
|
||||
|
||||
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
|
||||
assert.strictEqual(serialized, 'url:https://example.com/');
|
||||
});
|
||||
|
||||
it('should not hash blobs without ignoreUnknown', function() {
|
||||
var obj = {
|
||||
__className: '[object blob]'
|
||||
};
|
||||
|
||||
assert.throws(function() {
|
||||
hash(obj);
|
||||
}, /not supported/);
|
||||
});
|
||||
|
||||
it('should ignore blobs with ignoreUnknown', function() {
|
||||
var obj = {
|
||||
__className: '[object blob]'
|
||||
};
|
||||
|
||||
var serialized = hash(obj, {
|
||||
algorithm: 'passthrough',
|
||||
encoding: 'utf8',
|
||||
ignoreUnknown: true
|
||||
});
|
||||
|
||||
assert.strictEqual(serialized, '[blob]');
|
||||
});
|
||||
});
|
60
node_modules/object-hash/test/old-crypto.js
generated
vendored
Normal file
60
node_modules/object-hash/test/old-crypto.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var crypto = require('crypto');
|
||||
var hash = require('../index');
|
||||
var validSha1 = /^[0-9a-f]{40}$/i;
|
||||
var validBase64 = /^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/==]{4})$/;
|
||||
|
||||
describe('hash() without crypto.getHashes', function() {
|
||||
var getHashes_;
|
||||
beforeEach(function() {
|
||||
getHashes_ = crypto.getHashes;
|
||||
delete crypto.getHashes;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
crypto.getHashes = getHashes_;
|
||||
});
|
||||
|
||||
it('should work fine for SHA1', function() {
|
||||
assert.ok(validSha1.test(hash(42)), 'hash some value');
|
||||
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hash() without Duplex streams', function() {
|
||||
var createHash_;
|
||||
beforeEach(function() {
|
||||
createHash_ = crypto.createHash;
|
||||
crypto.createHash = function(algorithm) {
|
||||
var strm = createHash_(algorithm);
|
||||
|
||||
return {
|
||||
update: strm.write.bind(strm),
|
||||
digest: strm.digest.bind(strm)
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
crypto.createHash = createHash_;
|
||||
});
|
||||
|
||||
it('should work fine for SHA1 without .write()/.read()', function() {
|
||||
assert.ok(validSha1.test(hash(42)), 'hash some value');
|
||||
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
|
||||
});
|
||||
|
||||
it('should work fine for SHA1 without .write()/.read() with base64', function() {
|
||||
assert.ok(validBase64.test(hash(42, {encoding: 'base64'})), 'hash some value');
|
||||
assert.ok(validBase64.test(hash(NaN, {encoding: 'base64'})), 'hash some value');
|
||||
});
|
||||
|
||||
if (typeof Buffer !== 'undefined') {
|
||||
it('should work fine for SHA1 without .write()/.read() with buffer', function() {
|
||||
assert.ok(Buffer.isBuffer(hash(42, {encoding: 'buffer'})), 'hash some value');
|
||||
assert.ok(Buffer.isBuffer(hash(NaN, {encoding: 'buffer'})), 'hash some value');
|
||||
});
|
||||
}
|
||||
});
|
36
node_modules/object-hash/test/replacer.js
generated
vendored
Normal file
36
node_modules/object-hash/test/replacer.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var stream = require('stream');
|
||||
var hash = require('../index');
|
||||
|
||||
describe('replacer option', function() {
|
||||
it('should emit information about an object to a stream', function() {
|
||||
var strm = new stream.PassThrough();
|
||||
|
||||
var replacer = function(value) {
|
||||
try {
|
||||
return JSON.stringify(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
var obj = {foo: 'bar'};
|
||||
hash.writeToStream(obj, {replacer: replacer}, strm);
|
||||
var result = strm.read().toString();
|
||||
assert.strictEqual(typeof result, 'string');
|
||||
assert.notStrictEqual(result.indexOf(JSON.stringify(obj)), -1);
|
||||
});
|
||||
|
||||
it('should not reach property values when excludeValues = true', function() {
|
||||
var strm = new stream.PassThrough();
|
||||
|
||||
var replacer = function(k) {
|
||||
assert.notStrictEqual(k, 'bar');
|
||||
return k;
|
||||
};
|
||||
|
||||
hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
|
||||
});
|
||||
});
|
174
node_modules/object-hash/test/types.js
generated
vendored
Normal file
174
node_modules/object-hash/test/types.js
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var crypto = require('crypto');
|
||||
var hash = require('../index');
|
||||
var validSha1 = /^[0-9a-f]{40}$/i;
|
||||
|
||||
describe('hash()ing different types', function() {
|
||||
it('hashes non-object types', function() {
|
||||
var func = function(a){ return a + 1; };
|
||||
assert.ok(validSha1.test(hash('Shazbot!')), 'hash string');
|
||||
assert.ok(validSha1.test(hash(42)), 'hash number');
|
||||
assert.ok(validSha1.test(hash(NaN)), 'hash bool');
|
||||
assert.ok(validSha1.test(hash(true)), 'hash bool');
|
||||
assert.ok(validSha1.test(hash(func)), 'hash function');
|
||||
});
|
||||
|
||||
it('hashes special object types', function() {
|
||||
var dt = new Date();
|
||||
dt.setDate(dt.getDate() + 1);
|
||||
|
||||
assert.ok(validSha1.test(hash([1,2,3,4])), 'hash array');
|
||||
assert.notEqual(hash([1,2,3,4]), hash([4,3,2,1]), 'different arrays not equal');
|
||||
assert.ok(validSha1.test(hash(new Date())), 'hash date');
|
||||
assert.notEqual(hash(new Date()), hash(dt), 'different dates not equal');
|
||||
assert.ok(validSha1.test(hash(null)), 'hash Null');
|
||||
assert.ok(validSha1.test(hash(Number.NaN)), 'hash NaN');
|
||||
assert.ok(validSha1.test(hash({ foo: undefined })), 'hash Undefined value');
|
||||
assert.ok(validSha1.test(hash(new RegExp())), 'hash regex');
|
||||
assert.ok(validSha1.test(hash(new Error())), 'hash error');
|
||||
});
|
||||
|
||||
it('hashes node.js-internal object types', function() {
|
||||
if (typeof process !== 'undefined') {
|
||||
assert.ok(validSha1.test(hash(process)), 'hash process');
|
||||
}
|
||||
|
||||
var timer = setTimeout(function() {}, 0);
|
||||
assert.ok(validSha1.test(hash(timer)), 'hash timer');
|
||||
});
|
||||
|
||||
if (typeof Symbol !== 'undefined') {
|
||||
it('hashes Symbols', function() {
|
||||
assert.ok(validSha1.test(hash(Symbol('Banana'))), 'hash error');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Buffer !== 'undefined') {
|
||||
it("Buffers can be hashed", function() {
|
||||
assert.ok(validSha1.test(hash(new Buffer('Banana'))), 'hashes Buffers');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Uint8Array !== 'undefined') {
|
||||
it("Typed arrays can be hashed", function() {
|
||||
|
||||
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]))), 'hashes Uint8Array');
|
||||
assert.ok(validSha1.test(hash(new Int8Array([1,2,3,4]))), 'hashes Int8Array');
|
||||
assert.ok(validSha1.test(hash(new Uint16Array([1,2,3,4]))), 'hashes Uint16Array');
|
||||
assert.ok(validSha1.test(hash(new Int16Array([1,2,3,4]))), 'hashes Int16Array');
|
||||
assert.ok(validSha1.test(hash(new Uint32Array([1,2,3,4]))), 'hashes Uint32Array');
|
||||
assert.ok(validSha1.test(hash(new Int32Array([1,2,3,4]))), 'hashes Int32Array');
|
||||
assert.ok(validSha1.test(hash(new Float32Array([1,2,3,4]))), 'hashes Float32Array');
|
||||
if (typeof Float64Array !== 'undefined')
|
||||
assert.ok(validSha1.test(hash(new Float64Array([1,2,3,4]))), 'hashes Float64Array');
|
||||
if (typeof Uint8ClampedArray !== 'undefined')
|
||||
assert.ok(validSha1.test(hash(new Uint8ClampedArray([1,2,3,4]))), 'hashes Uint8ClampedArray');
|
||||
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]).buffer)), 'hashes ArrayBuffer');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Map !== 'undefined') {
|
||||
it("Maps can be hashed", function() {
|
||||
var map = new Map([['a',1],['b',2]]);
|
||||
assert.ok(validSha1.test(hash(map)), 'hashes Maps');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof WeakMap !== 'undefined') {
|
||||
it("WeakMaps can’t be hashed", function() {
|
||||
var map = new WeakMap([[{foo: 'bar'},1]]);
|
||||
assert.throws(function() {
|
||||
validSha1.test(hash(map))
|
||||
}, 'does not hash WeakMaps');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Set !== 'undefined') {
|
||||
it("Sets can be hashed", function() {
|
||||
var set = new Set(['you', 'du', 'tu', 'あなた', '您']);
|
||||
assert.ok(validSha1.test(hash(set)), 'hashes Sets');
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof WeakSet !== 'undefined') {
|
||||
it("WeakSets can’t be hashed", function() {
|
||||
var obj = {foo: 'bar'};
|
||||
var set = new WeakSet([obj]);
|
||||
assert.throws(function() {
|
||||
validSha1.test(hash(set))
|
||||
}, 'does not hash WeakSets');
|
||||
});
|
||||
}
|
||||
|
||||
it("Builtin types themselves can be hashed", function() {
|
||||
var hashcount = {};
|
||||
var types = [Object, Date, Number, String, Function, RegExp,
|
||||
Error, 0, null, NaN];
|
||||
if (typeof WeakSet !== 'undefined') types.push(WeakSet);
|
||||
if (typeof Set !== 'undefined') types.push(Set);
|
||||
if (typeof WeakMap !== 'undefined') types.push(WeakMap);
|
||||
if (typeof Map !== 'undefined') types.push(Map);
|
||||
if (typeof Symbol !== 'undefined') types.push(Symbol);
|
||||
if (typeof Uint8Array !== 'undefined') types.push(Uint8Array);
|
||||
|
||||
// Hash each type
|
||||
for (var idx in types) {
|
||||
var h = hash(types[idx]);
|
||||
assert.ok(validSha1.test(h));
|
||||
hashcount[h] = (hashcount[h] || 0) + 1;
|
||||
}
|
||||
|
||||
// Check for collisions
|
||||
var no = 0;
|
||||
for (var h in hashcount) {
|
||||
assert.equal(hashcount[h], 1);
|
||||
no++;
|
||||
}
|
||||
|
||||
// Self check; did we really hash all the types?
|
||||
assert.equal(no, types.length);
|
||||
});
|
||||
|
||||
it("Builtin types might result in identical hashes with respectFunctionNames = false", function() {
|
||||
var hashcount = {};
|
||||
var types = [Object, Date, Number, String, Function, RegExp,
|
||||
Error, 0, null, NaN];
|
||||
if (typeof WeakSet !== 'undefined') types.push(WeakSet);
|
||||
if (typeof Set !== 'undefined') types.push(Set);
|
||||
if (typeof WeakMap !== 'undefined') types.push(WeakMap);
|
||||
if (typeof Map !== 'undefined') types.push(Map);
|
||||
if (typeof Symbol !== 'undefined') types.push(Symbol);
|
||||
if (typeof Uint8Array !== 'undefined') types.push(Uint8Array);
|
||||
|
||||
// Hash each type
|
||||
for (var idx in types) {
|
||||
var h = hash(types[idx], { respectFunctionNames: false });
|
||||
assert.ok(validSha1.test(h));
|
||||
hashcount[h] = (hashcount[h] || 0) + 1;
|
||||
}
|
||||
|
||||
// Check for collisions
|
||||
var no = 0;
|
||||
for (var h in hashcount) {
|
||||
assert.ok(hashcount[h] >= 1);
|
||||
no += hashcount[h];
|
||||
}
|
||||
|
||||
// Self check; did we really hash all the types?
|
||||
assert.equal(no, types.length);
|
||||
});
|
||||
|
||||
it("Functions with identical bodies and different names result in identical hashes with respectFunctionNames = false", function() {
|
||||
var fn1 = function a() {};
|
||||
var fn2 = function b() {};
|
||||
var toStringDummy = function() { return '...'; };
|
||||
fn1.toString = toStringDummy;
|
||||
fn2.toString = toStringDummy;
|
||||
|
||||
var h1 = hash(fn1, { respectFunctionNames: false });
|
||||
var h2 = hash(fn2, { respectFunctionNames: false });
|
||||
assert.strictEqual(h1, h2);
|
||||
});
|
||||
});
|
27
node_modules/object-hash/test/writeToStream.js
generated
vendored
Normal file
27
node_modules/object-hash/test/writeToStream.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var stream = require('stream');
|
||||
var hash = require('../index');
|
||||
|
||||
describe('writeToStream', function() {
|
||||
it('should emit information about an object to a stream', function() {
|
||||
var strm = new stream.PassThrough();
|
||||
|
||||
hash.writeToStream({foo: 'bar'}, strm);
|
||||
var result = strm.read().toString();
|
||||
assert.strictEqual(typeof result, 'string');
|
||||
assert.notStrictEqual(result.indexOf('foo'), -1);
|
||||
assert.notStrictEqual(result.indexOf('bar'), -1);
|
||||
});
|
||||
|
||||
it('should leave out keys when excludeValues = true', function() {
|
||||
var strm = new stream.PassThrough();
|
||||
|
||||
hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
|
||||
var result = strm.read().toString();
|
||||
assert.strictEqual(typeof result, 'string');
|
||||
assert.notStrictEqual(result.indexOf('foo'), -1);
|
||||
assert. strictEqual(result.indexOf('bar'), -1);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user