From 1e2e853fc0d53e729135eaba03f225e08f5ea1b0 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Wed, 4 Mar 2020 13:21:54 +0100 Subject: [PATCH] add test --- .gitignore | 4 +++- index.js | 16 ++++++++-------- test/index.js | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 test/index.js diff --git a/.gitignore b/.gitignore index c85804c..e5c296b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /node_modules/ -/dist/ \ No newline at end of file +/dist/ +/.nyc_output/ +/coverage/ diff --git a/index.js b/index.js index 656aff8..1b54477 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ /* eslint-disable no-magic-numbers */ 'use strict'; -const argon2 = require('argon2'); +const argon2 = require ('argon2'); const argon_options = { hashLength: 64, @@ -17,12 +17,12 @@ const argon_options = { /** * verify a plain text against an argon2 hash * - * @param {string} hash argon hash + * @param {string} hash_str hash * @param {string} plain plain text * @returns {Promise} true if valid */ -function argon_verify (hash, plain) { - return argon2.verify (hash, plain, argon_options); +function verify (hash_str, plain) { + return argon2.verify (hash_str, plain, argon_options); } /** @@ -31,11 +31,11 @@ function argon_verify (hash, plain) { * @param {string} plain plain text * @returns {Promise} hash */ -function argon_hash (plain) { +function hash (plain) { return argon2.hash (plain, argon_options); } module.exports = { - argon_hash, - argon_verify -} + hash, + verify +}; diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..3fca307 --- /dev/null +++ b/test/index.js @@ -0,0 +1,21 @@ +'use strict'; + +const helper = require ('../index'); +const test = require ('ava'); + +test ('create hash', async (t) => { + const hash = await helper.hash ('foo'); + t.is (typeof hash, 'string'); +}); + +test ('validate', async (t) => { + const hash = await helper.hash ('foo'); + const valid = await helper.verify (hash, 'foo'); + t.is (valid, true); +}); + +test ('fail validation', async (t) => { + const hash = await helper.hash ('foo'); + const valid = await helper.verify (hash, 'bar'); + t.is (valid, false); +});