Skip to content

Commit

Permalink
style: fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Feb 10, 2021
1 parent b86ef77 commit 18d1627
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
54 changes: 27 additions & 27 deletions test/hash.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
import test from 'ava';

import m from '..';
import m from '../index.js';

test("should throw an error if the 'iterations' option is not a number", async (t) => {
const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.hash('password', {iterations: 'iterations'});
});
t.is(err.message, "The 'iterations' option must be an integer");
t.is(error.message, "The 'iterations' option must be an integer");
});

test("should throw an error if the 'iterations' option is out of range", async (t) => {
let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.hash('password', {iterations: -1});
});
t.regex(err.message, /The 'iterations' option must be in the range/);
t.regex(error.message, /The 'iterations' option must be in the range/);

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.hash('password', {iterations: 2 ** 32});
});
t.regex(err.message, /The 'iterations' option must be in the range/);
t.regex(error.message, /The 'iterations' option must be in the range/);
});

test("should throw an error if the 'memory' option is not a number", async (t) => {
const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.hash('password', {memory: 'memory'});
});
t.is(err.message, "The 'memory' option must be an integer");
t.is(error.message, "The 'memory' option must be an integer");
});

test("should throw an error if the 'memory' option is out of range", async (t) => {
let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.hash('password', {memory: -1});
});
t.regex(err.message, /The 'memory' option must be in the range/);
t.regex(error.message, /The 'memory' option must be in the range/);

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.hash('password', {memory: 2 ** 32});
});
t.regex(err.message, /The 'memory' option must be in the range/);
t.regex(error.message, /The 'memory' option must be in the range/);
});

test("should throw an error if the 'parallelism' option is not a number", async (t) => {
const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.hash('password', {parallelism: 'parallelism'});
});
t.is(err.message, "The 'parallelism' option must be an integer");
t.is(error.message, "The 'parallelism' option must be an integer");
});

test("should throw an error if the 'parallelism' option is out of range", async (t) => {
let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.hash('password', {parallelism: -1});
});
t.regex(err.message, /The 'parallelism' option must be in the range/);
t.regex(error.message, /The 'parallelism' option must be in the range/);

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.hash('password', {parallelism: 2 ** 24});
});
t.regex(err.message, /The 'parallelism' option must be in the range/);
t.regex(error.message, /The 'parallelism' option must be in the range/);
});

test("should throw an error if the 'variant' option is not a string", async (t) => {
const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.hash('password', {variant: 1});
});
t.is(err.message, "The 'variant' option must be a string");
t.is(error.message, "The 'variant' option must be a string");
});

test("should throw an error if the 'variant' option is unsupported", async (t) => {
const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.hash('password', {variant: 's'});
});
t.regex(err.message, /The 'variant' option must be one of:/);
t.regex(error.message, /The 'variant' option must be one of:/);
});

test("should throw an error if the 'saltSize' option is out of range", async (t) => {
let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.hash('password', {saltSize: -1});
});
t.regex(err.message, /The 'saltSize' option must be in the range/);
t.regex(error.message, /The 'saltSize' option must be in the range/);

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.hash('password', {saltSize: 1025});
});
t.regex(err.message, /The 'saltSize' option must be in the range/);
t.regex(error.message, /The 'saltSize' option must be in the range/);
});
2 changes: 1 addition & 1 deletion test/identifiers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';

import m from '..';
import m from '../index.js';

test('should return the full list of identifiers', (t) => {
t.deepEqual(m.identifiers(), ['argon2i', 'argon2d', 'argon2id']);
Expand Down
2 changes: 1 addition & 1 deletion test/others.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';

import m from '..';
import m from '../index.js';

test('should hash and verify a short password', async (t) => {
const password = 'p';
Expand Down
62 changes: 31 additions & 31 deletions test/verify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';

import m from '..';
import m from '../index.js';

test('should verify a precomputed hash', async (t) => {
// Precomputed hash for "password"
Expand All @@ -14,142 +14,142 @@ test('should throw an error if the identifier does not contain the variant used'
const wrong =
'$argon2$i=6400$0ZrzXitFSGltTQnBWOsdAw$Y11AchqV4b0sUisdZd0Xr97KWoymNE0LNNrnEgY4H9M';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'Incompatible argon2 identifier found in the hash');
t.is(error.message, 'Incompatible argon2 identifier found in the hash');
});

test('should throw an error if the identifier contains an unsupported variant', async (t) => {
const wrong =
'$argon2s$v=19$m=4096,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'Unsupported s variant function');
t.is(error.message, 'Unsupported s variant function');
});

test('should throw an error if the version is not supported', async (t) => {
const wrong =
'$argon2id$v=10$m=4096,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'Unsupported 10 version');
t.is(error.message, 'Unsupported 10 version');
});

test('should throw an error if the param section is empty', async (t) => {
const wrong =
'$argon2id$v=19$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'The param section cannot be empty');
t.is(error.message, 'The param section cannot be empty');
});

test("should throw an error if the 't' parameter is missing", async (t) => {
const wrong =
'$argon2id$v=19$m=4096,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, "The 't' param must be an integer");
t.is(error.message, "The 't' param must be an integer");
});

test("should throw an error if the 't' parameter is out of range", async (t) => {
let wrong =
'$argon2id$v=19$m=4096,t=-1,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 't' param must be in the range/);
t.regex(error.message, /The 't' param must be in the range/);

wrong =
'$argon2id$v=19$m=4096,t=4294967296,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 't' param must be in the range/);
t.regex(error.message, /The 't' param must be in the range/);
});

test("should throw an error if the 'm' parameter is missing", async (t) => {
const wrong =
'$argon2id$v=19$t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, "The 'm' param must be an integer");
t.is(error.message, "The 'm' param must be an integer");
});

test("should throw an error if the 'm' parameter is out of range", async (t) => {
let wrong =
'$argon2id$v=19$m=0,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 'm' param must be in the range/);
t.regex(error.message, /The 'm' param must be in the range/);

wrong =
'$argon2id$v=19$m=4294967296,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 'm' param must be in the range/);
t.regex(error.message, /The 'm' param must be in the range/);
});

test("should throw an error if the 'p' parameter is missing", async (t) => {
const wrong =
'$argon2id$v=19$m=4096,t=3$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, "The 'p' param must be an integer");
t.is(error.message, "The 'p' param must be an integer");
});

test("should throw an error if the 'p' parameter is out of range", async (t) => {
let wrong =
'$argon2id$v=19$m=4096,t=3,p=0$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

let err = await t.throwsAsync(async () => {
let error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 'p' param must be in the range/);
t.regex(error.message, /The 'p' param must be in the range/);

wrong =
'$argon2id$v=19$m=4096,t=3,p=16777216$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI';

err = await t.throwsAsync(async () => {
error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.regex(err.message, /The 'p' param must be in the range/);
t.regex(error.message, /The 'p' param must be in the range/);
});

test('should throw an error if salt is not given', async (t) => {
const wrong = '$argon2id$v=19$m=4096,t=3,p=1';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'No salt found in the given string');
t.is(error.message, 'No salt found in the given string');
});

test('should throw an error if hash is not given', async (t) => {
const wrong = '$argon2id$v=19$m=4096,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg';

const err = await t.throwsAsync(async () => {
const error = await t.throwsAsync(async () => {
await m.verify(wrong, 'password');
});
t.is(err.message, 'No hash found in the given string');
t.is(error.message, 'No hash found in the given string');
});

test('should throw an error if the hash is not in PHC format', async (t) => {
Expand Down

0 comments on commit 18d1627

Please sign in to comment.