Skip to content

Commit 2717f46

Browse files
committed
Fix tests
1 parent 354bac6 commit 2717f46

2 files changed

Lines changed: 69 additions & 66 deletions

File tree

src/classes/MFKDFDerivedKey/strengthening.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* @author Vivek Nair (https://nair.me) <vivek@nair.me>
99
*/
1010

11-
const { encrypt } = require("../../crypt");
12-
const { argon2id } = require("hash-wasm");
11+
const { encrypt } = require('../../crypt')
12+
const { argon2id } = require('hash-wasm')
1313

1414
/**
1515
* Update the time and/or memory cost of an existing multi-factor derived key.
@@ -44,29 +44,29 @@ const { argon2id } = require("hash-wasm");
4444
* @memberOf MFKDFDerivedKey
4545
* @async
4646
*/
47-
async function strengthen(time = 0, memory = 0) {
48-
if (typeof time !== "number" || time < 0 || !Number.isInteger(time)) {
49-
throw new TypeError("time must be a non-negative integer");
47+
async function strengthen (time = 0, memory = 0) {
48+
if (typeof time !== 'number' || time < 0 || !Number.isInteger(time)) {
49+
throw new TypeError('time must be a non-negative integer')
5050
}
51-
if (typeof memory !== "number" || memory < 0 || !Number.isInteger(memory)) {
52-
throw new TypeError("memory must be a non-negative integer");
51+
if (typeof memory !== 'number' || memory < 0 || !Number.isInteger(memory)) {
52+
throw new TypeError('memory must be a non-negative integer')
5353
}
5454

55-
this.policy.time = time;
56-
this.policy.memory = memory;
55+
this.policy.time = time
56+
this.policy.memory = memory
5757

5858
const kek = Buffer.from(
5959
await argon2id({
6060
password: this.secret,
61-
salt: Buffer.from(this.policy.salt, "base64"),
61+
salt: Buffer.from(this.policy.salt, 'base64'),
6262
hashLength: 32,
6363
parallelism: 1,
6464
iterations: 2 + Math.max(0, time),
6565
memorySize: 19456 + Math.max(0, memory),
66-
outputType: "binary",
66+
outputType: 'binary'
6767
})
68-
);
68+
)
6969

70-
this.policy.key = encrypt(this.key, kek).toString("base64");
70+
this.policy.key = encrypt(this.key, kek).toString('base64')
7171
}
72-
module.exports.strengthen = strengthen;
72+
module.exports.strengthen = strengthen

test/examples/site.js

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,102 @@
11
/* eslint no-unused-expressions: "off" */
2-
const chai = require("chai");
3-
const chaiAsPromised = require("chai-as-promised");
4-
chai.use(chaiAsPromised);
5-
chai.should();
2+
const chai = require('chai')
3+
const chaiAsPromised = require('chai-as-promised')
4+
chai.use(chaiAsPromised)
5+
chai.should()
66

7-
const mfkdf = require("../../src");
8-
const { suite, test } = require("mocha");
7+
const mfkdf = require('../../src')
8+
const { suite, test } = require('mocha')
99
// const crypto = require('crypto')
1010

11-
suite("site", () => {
12-
test("Go beyond passwords", async () => {
11+
suite('site', () => {
12+
test('Go beyond passwords', async () => {
1313
const keyPolicy = JSON.stringify(
1414
(
1515
await mfkdf.setup.key([
16-
await mfkdf.setup.factors.password("Tr0ub4dour"),
16+
await mfkdf.setup.factors.password('Tr0ub4dour'),
1717
await mfkdf.setup.factors.hotp({
18-
secret: Buffer.from("abcdefghijklmnopqrst"),
18+
secret: Buffer.from('abcdefghijklmnopqrst')
1919
}),
2020
await mfkdf.setup.factors.uuid({
21-
id: "recovery",
22-
uuid: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
23-
}),
21+
id: 'recovery',
22+
uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
23+
})
2424
])
2525
).policy
26-
);
26+
)
2727

2828
const derivedKey = await mfkdf.derive.key(JSON.parse(keyPolicy), {
29-
password: mfkdf.derive.factors.password("Tr0ub4dour"),
29+
password: mfkdf.derive.factors.password('Tr0ub4dour'),
3030
hotp: mfkdf.derive.factors.hotp(241063),
3131
recovery: mfkdf.derive.factors.uuid(
32-
"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
33-
),
34-
});
32+
'9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
33+
)
34+
})
3535

36-
derivedKey.should.be.a("object");
37-
});
36+
derivedKey.should.be.a('object')
37+
})
3838

39-
test("Increased key entropy", async () => {
39+
test('Increased key entropy', async () => {
4040
Math.floor(
4141
(
4242
await mfkdf.setup.key([
43-
await mfkdf.setup.factors.password("Tr0ub4dour"),
43+
await mfkdf.setup.factors.password('Tr0ub4dour')
4444
])
4545
).entropyBits.real
46-
).should.equal(16);
46+
).should.equal(16)
4747

4848
Math.floor(
4949
(
5050
await mfkdf.setup.key([
51-
await mfkdf.setup.factors.password("Tr0ub4dour"),
51+
await mfkdf.setup.factors.password('Tr0ub4dour'),
5252
await mfkdf.setup.factors.hotp(),
53-
await mfkdf.setup.factors.hmacsha1(),
53+
await mfkdf.setup.factors.hmacsha1()
5454
])
5555
).entropyBits.real
56-
).should.equal(196);
57-
});
56+
).should.equal(196)
57+
})
5858

59-
test("Enforce advanced policies", async () => {
59+
test('Enforce advanced policies', async () => {
6060
const policyBasedKey = await mfkdf.policy.setup(
6161
await mfkdf.policy.or(
62-
await mfkdf.setup.factors.uuid({ id: "recoveryCode" }),
62+
await mfkdf.setup.factors.uuid({ id: 'recoveryCode' }),
6363
await mfkdf.policy.and(
64-
await mfkdf.setup.factors.password("Tr0ub4dour"),
64+
await mfkdf.setup.factors.password('Tr0ub4dour'),
6565
await mfkdf.setup.factors.totp()
6666
)
6767
)
68-
);
69-
policyBasedKey.should.be.a("object");
70-
});
68+
)
69+
policyBasedKey.should.be.a('object')
70+
})
7171

72-
test("Self-service factor recovery", async () => {
72+
test('Self-service factor recovery', async () => {
7373
const keyPolicy = JSON.stringify(
7474
(
75-
await mfkdf.setup.key([
76-
await mfkdf.setup.factors.password("password"),
77-
await mfkdf.setup.factors.hotp({
78-
secret: Buffer.from("abcdefghijklmnopqrst"),
79-
}),
80-
await mfkdf.setup.factors.uuid({
81-
id: "recoveryCode",
82-
uuid: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
83-
}),
84-
])
75+
await mfkdf.setup.key(
76+
[
77+
await mfkdf.setup.factors.password('password'),
78+
await mfkdf.setup.factors.hotp({
79+
secret: Buffer.from('abcdefghijklmnopqrst')
80+
}),
81+
await mfkdf.setup.factors.uuid({
82+
id: 'recoveryCode',
83+
uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
84+
})
85+
],
86+
{ threshold: 2 }
87+
)
8588
).policy
86-
);
89+
)
8790

8891
const key = await mfkdf.derive.key(JSON.parse(keyPolicy), {
8992
hotp: mfkdf.derive.factors.hotp(241063),
9093
recoveryCode: mfkdf.derive.factors.uuid(
91-
"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
92-
),
93-
});
94+
'9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
95+
)
96+
})
9497

9598
await key.recoverFactor(
96-
await mfkdf.setup.factors.password("myNewPassword", { id: "password" })
97-
); // modify key to use new password factor
98-
});
99-
});
99+
await mfkdf.setup.factors.password('myNewPassword', { id: 'password' })
100+
) // modify key to use new password factor
101+
})
102+
})

0 commit comments

Comments
 (0)