From 2d2171fdbc10462457dd4f6ad0a10ef4afa84607 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Fri, 27 Mar 2020 09:15:32 +0100 Subject: [PATCH] fix mutant --- package.json | 4 ++++ test/index.js | 27 ++++++++++++++++++++++++++- yarn.lock | 5 +++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d1e45e5..2f8d5de 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "author": "Timo Hocker ", "license": "MIT", "devDependencies": { + "@scode/encoding-helper": "^1.0.10", "@scode/eslint-config": "^1.2.25", "@stryker-mutator/core": "^3.0.2", "@stryker-mutator/javascript-mutator": "^3.0.2", @@ -19,5 +20,8 @@ }, "dependencies": { "argon2": "^0.26.1" + }, + "engines": { + "node": ">=10.0.0" } } diff --git a/test/index.js b/test/index.js index cfcf394..f3c6761 100644 --- a/test/index.js +++ b/test/index.js @@ -5,18 +5,43 @@ * Created by Timo Hocker , March 2020 */ +/* eslint-disable no-magic-numbers */ + 'use strict'; const helper = require ('../index'); +const argon2 = require ('argon2'); const test = require ('ava'); +const encoding_helper = require ('@scode/encoding-helper'); + +const required_options = { + hashLength: 64, + saltLength: 32, + type: argon2.argon2id +}; +const type_str = 'argon2id'; test ('create hash', async (t) => { const hash = await helper.hash ('foo'); + const regex = /\$(?.*?)\$.*?\$.*?\$(?.*?)\$(?.*)/u; + const res = regex.exec (hash); t.is (typeof hash, 'string'); + t.not (res, null); + t.is (res.groups.type, type_str); + t.is ( + encoding_helper.to_hex (res.groups.salt, 'base64').length, + required_options.saltLength * 2 + ); + t.is ( + encoding_helper.to_hex (res.groups.hash, 'base64').length, + required_options.hashLength * 2 + ); + t.is (await argon2.verify (hash, 'foo', required_options), true); }); test ('validate', async (t) => { - const hash = await helper.hash ('foo'); + // eslint-disable-next-line max-len + const hash = '$argon2id$v=19$m=4096,t=3,p=1$IxY4EsXRazKmYijrGMEKap6MWeSjVaBIKykCu2fzNwg$ffJ4aOJTITnakX5NXVTAVvQZFIrj47mKVDuqcStu6uw1Ouo0LfILHP9z3beaZscGGR5BXJZhUFlXSsdsi/4pOg'; const valid = await helper.verify (hash, 'foo'); t.is (valid, true); }); diff --git a/yarn.lock b/yarn.lock index 139c783..ce89e4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -257,6 +257,11 @@ dependencies: safe-buffer "^5.1.2" +"@scode/encoding-helper@^1.0.10": + version "1.0.10" + resolved "https://npm.scode.ovh/@scode%2fencoding-helper/-/encoding-helper-1.0.10.tgz#2a53fdf6230f86391887e06e2485a3f7e3db4fb4" + integrity sha512-aP4rcsnnOXty2riSz1IBTaLpZz0uCa/htbFEeAf0U+JQ6b7cHKd92YNDpImxkfHlVQAUplLWlK/Anxz7/ojupQ== + "@scode/eslint-config@^1.2.25": version "1.2.30" resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.2.30.tgz#fa8c22dc62d3bcfa1a3e20a54f9b593e90fcec00"