add test
This commit is contained in:
parent
8de034af69
commit
1e2e853fc0
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
/.nyc_output/
|
||||
/coverage/
|
||||
|
14
index.js
14
index.js
@ -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<boolean>} 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<string>} hash
|
||||
*/
|
||||
function argon_hash (plain) {
|
||||
function hash (plain) {
|
||||
return argon2.hash (plain, argon_options);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
argon_hash,
|
||||
argon_verify
|
||||
}
|
||||
hash,
|
||||
verify
|
||||
};
|
||||
|
21
test/index.js
Normal file
21
test/index.js
Normal file
@ -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);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user