ci: expand CI checks and make consumer sync opt-in
- Add Go, npm, Python, and Java validation to CI - Run Go tests against PostgreSQL - Record performance fixes in the report
This commit is contained in:
1 parent
199a5efaef
commit
22887fef03
100 files changed
+9740
-429
No files matched your search
@@ -1,11 +1,16 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import crypto from 'node:crypto';
|
||||
import {
|
||||
ResetManager,
|
||||
createSessionToken,
|
||||
hashPassword,
|
||||
hashPasswordAsync,
|
||||
hashToken,
|
||||
passwordHashNeedsUpgrade,
|
||||
verifyAndUpgradePasswordAsync,
|
||||
verifyPassword,
|
||||
verifyPasswordAsync,
|
||||
} from '../src/auth.js';
|
||||
import { totpProvisioningUri, verifyTotp } from '../src/totp.js';
|
||||
|
||||
@@ -33,6 +38,74 @@ test('password hashes verify and reject a different password', () => {
|
||||
assert.equal(verifyPassword('wrong password', hash), false);
|
||||
});
|
||||
|
||||
test('new password hashes record their iteration count', () => {
|
||||
const hash = hashPassword('correct horse battery staple');
|
||||
assert.match(hash, /^pbkdf2-sha256\$600000\$[0-9a-f]{32}\$[0-9a-f]{64}$/);
|
||||
});
|
||||
|
||||
test('legacy salt:hex hashes still verify at the original iteration count', () => {
|
||||
const salt = crypto.randomBytes(16).toString('hex');
|
||||
const hash = crypto.pbkdf2Sync('legacy password', salt, 100000, 32, 'sha256').toString('hex');
|
||||
assert.equal(verifyPassword('legacy password', `${salt}:${hash}`), true);
|
||||
assert.equal(verifyPassword('wrong password', `${salt}:${hash}`), false);
|
||||
});
|
||||
|
||||
test('a hash with a malformed iteration count never verifies', () => {
|
||||
assert.equal(verifyPassword('correct horse battery staple', 'pbkdf2-sha256$0$aa$bb'), false);
|
||||
assert.equal(verifyPassword('correct horse battery staple', 'pbkdf2-sha256$x$aa$bb'), false);
|
||||
});
|
||||
|
||||
test('async password helpers produce and verify the same format', async () => {
|
||||
const hash = await hashPasswordAsync('correct horse battery staple', { iterations: 1000 });
|
||||
assert.match(hash, /^pbkdf2-sha256\$1000\$/);
|
||||
assert.equal(await verifyPasswordAsync('correct horse battery staple', hash), true);
|
||||
assert.equal(await verifyPasswordAsync('wrong password', hash), false);
|
||||
assert.equal(verifyPassword('correct horse battery staple', hash), true);
|
||||
});
|
||||
|
||||
test('formats this module does not verify fail closed', () => {
|
||||
for (const stored of ['', '$2b$12$abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQ', 'bcrypt$$2a$12$abc', 'pbkdf2-sha256$600000$00$00$extra']) {
|
||||
assert.equal(verifyPassword('correct horse battery staple', stored), false);
|
||||
}
|
||||
assert.equal(passwordHashNeedsUpgrade('$2b$12$abc'), true);
|
||||
});
|
||||
|
||||
test('a legacy salt:hex hash is rewritten in the current scheme after a successful login', async () => {
|
||||
const salt = crypto.randomBytes(16).toString('hex');
|
||||
const legacy = `${salt}:${crypto.pbkdf2Sync('legacy password', salt, 100000, 32, 'sha256').toString('hex')}`;
|
||||
assert.equal(passwordHashNeedsUpgrade(legacy), true);
|
||||
|
||||
const result = await verifyAndUpgradePasswordAsync('legacy password', legacy);
|
||||
assert.equal(result.valid, true);
|
||||
assert.match(result.upgradedHash, /^pbkdf2-sha256\$600000\$/);
|
||||
assert.equal(passwordHashNeedsUpgrade(result.upgradedHash), false);
|
||||
assert.equal(verifyPassword('legacy password', result.upgradedHash), true);
|
||||
});
|
||||
|
||||
test('a hash below the current iteration count is rewritten, and a short legacy password still upgrades', async () => {
|
||||
const low = await hashPasswordAsync('correct horse battery staple', { iterations: 1000 });
|
||||
const lowResult = await verifyAndUpgradePasswordAsync('correct horse battery staple', low);
|
||||
assert.match(lowResult.upgradedHash, /^pbkdf2-sha256\$600000\$/);
|
||||
|
||||
const salt = crypto.randomBytes(16).toString('hex');
|
||||
const shortLegacy = `${salt}:${crypto.pbkdf2Sync('short', salt, 100000, 32, 'sha256').toString('hex')}`;
|
||||
const shortResult = await verifyAndUpgradePasswordAsync('short', shortLegacy);
|
||||
assert.equal(shortResult.valid, true);
|
||||
assert.equal(verifyPassword('short', shortResult.upgradedHash), true);
|
||||
});
|
||||
|
||||
test('a wrong password neither verifies nor upgrades, and a current hash is not rewritten', async () => {
|
||||
const hash = await hashPasswordAsync('correct horse battery staple', { iterations: 1000 });
|
||||
assert.deepEqual(await verifyAndUpgradePasswordAsync('wrong password', hash), { valid: false, upgradedHash: null });
|
||||
|
||||
const current = await hashPasswordAsync('correct horse battery staple');
|
||||
assert.equal(passwordHashNeedsUpgrade(current), false);
|
||||
assert.deepEqual(await verifyAndUpgradePasswordAsync('correct horse battery staple', current), {
|
||||
valid: true,
|
||||
upgradedHash: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('TOTP verifies RFC 6238 SHA-1 vectors', () => {
|
||||
const secret = 'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ';
|
||||
const vectors = [
|
||||
|
||||
Reference in new issue
Block a user