From d6eb2f040aac66541bde5dbc1f3d8ad4478ea570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 13 Mar 2017 03:25:06 -0700 Subject: [PATCH] fix(index): set default hashAlgorithm omfg config really needs to be more centralized soon --- lib/entry-index.js | 2 +- test/index.insert.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/entry-index.js b/lib/entry-index.js index e0eb549..52b620a 100644 --- a/lib/entry-index.js +++ b/lib/entry-index.js @@ -36,7 +36,7 @@ function insert (cache, key, digest, opts) { const entry = { key: key, digest: digest, - hashAlgorithm: opts.hashAlgorithm, + hashAlgorithm: opts.hashAlgorithm || 'sha512', time: +(new Date()), metadata: opts.metadata } diff --git a/test/index.insert.js b/test/index.insert.js index 95d5c5e..7dce6cb 100644 --- a/test/index.insert.js +++ b/test/index.insert.js @@ -63,10 +63,12 @@ test('inserts additional entries into existing key', function (t) { t.deepEqual(entries, [{ key: KEY, digest: DIGEST, + hashAlgorithm: 'sha512', metadata: 1 }, { key: KEY, digest: DIGEST, + hashAlgorithm: 'sha512', metadata: 2 }], 'all entries present') }) @@ -91,7 +93,8 @@ test('separates entries even if one is corrupted', function (t) { delete entry.time t.deepEqual(entry, { key: KEY, - digest: DIGEST + digest: DIGEST, + hashAlgorithm: 'sha512' }, 'new entry unaffected by corruption') }) }) @@ -108,6 +111,7 @@ test('optional arbitrary metadata', function (t) { t.deepEqual(entry, { key: KEY, digest: DIGEST, + hashAlgorithm: 'sha512', metadata: metadata }, 'entry includes inserted metadata') }) @@ -155,7 +159,8 @@ test('path-breaking characters', function (t) { delete entry.time t.deepEqual(entry, { key: newKey, - digest: DIGEST + digest: DIGEST, + hashAlgorithm: 'sha512' }, 'entry exists and matches original key with invalid chars') }) }) @@ -175,7 +180,8 @@ test('extremely long keys', function (t) { delete entry.time t.deepEqual(entry, { key: newKey, - digest: DIGEST + digest: DIGEST, + hashAlgorithm: 'sha512' }, 'entry exists in spite of INCREDIBLY LONG key') }) })