test(e2e): add SessionFactory with sha256 token hashing

This commit is contained in:
kolaente 2026-04-21 10:44:19 +02:00 committed by kolaente
parent 726a4df539
commit fff7f80994
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import {createHash, randomUUID} from 'node:crypto'
import {Factory} from '../support/factory'
// Mirrors pkg/models/sessions.go HashSessionToken(). Unsalted because refresh
// tokens are high-entropy (128 random bytes hex-encoded), not human passwords.
export function hashSessionToken(raw: string): string {
return createHash('sha256').update(raw).digest('hex')
}
export class SessionFactory extends Factory {
static table = 'sessions'
static factory() {
const now = new Date()
return {
id: randomUUID(),
user_id: 1,
token_hash: hashSessionToken('placeholder-override-me'),
device_info: 'Firefox on Linux',
ip_address: '192.0.2.5',
is_long_session: false,
last_active: now.toISOString(),
created: now.toISOString(),
}
}
}