Files
shared/packages/node-backend/test/auth.test.js
T

21 lines
649 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
createSessionToken,
hashPassword,
hashToken,
verifyPassword,
} from '../src/auth.js';
test('password hashes verify and reject a different password', () => {
const hash = hashPassword('correct horse battery staple');
assert.equal(verifyPassword('correct horse battery staple', hash), true);
assert.equal(verifyPassword('wrong password', hash), false);
});
test('session token hashes are not the raw token', () => {
const { token, tokenHash } = createSessionToken();
assert.notEqual(token, tokenHash);
assert.equal(hashToken(token), tokenHash);
});