ident
All repositories: gitoria
3.5 KB
// tests/oldstore-009.hl — THE MIGRATION FIXTURE (tests/migration.mjs): an ident store in the// OLD format (before mission 009: `*id` tables `<prefix>-<table>.*`, public ids = id + 1),// with known keys, secret hashes and per-app ids. OLD_PREFIX=/abs/dir/identimport { MPackDB } from 'hl:mpackdb'import { env } from 'hl:proc'import { now } from 'hl:time'import { sha256 } from 'hl:crypto'let p = env('OLD_PREFIX')let accounts = new MPackDB(file = p + '-accounts.db', primaryKey = '*id', indexes = ['!email'])let identities = new MPackDB(file = p + '-identities.db', primaryKey = '*id', indexes = ['account'])let otp = new MPackDB(file = p + '-otp.db', primaryKey = '*id', indexes = ['email'])let sends = new MPackDB(file = p + '-sends.db', primaryKey = '*id', indexes = ['email'])let apps = new MPackDB(file = p + '-apps.db', primaryKey = '*id', indexes = ['owner' '!apiKey'])let conns = new MPackDB(file = p + '-connections.db', primaryKey = '*id', indexes = ['!pair' 'app' '!appIdentity'])let requests = new MPackDB(file = p + '-requests.db', primaryKey = '*id', indexes = ['!rid'])let grants = new MPackDB(file = p + '-grants.db', primaryKey = '*id', indexes = ['!hash'])let t = now()let x = (c, n) => {let s = ''while (s.length < n) { s = s + c }return s}accounts.put({ email = '[email protected]' timeZone = 'Europe/Vienna' created = t - 90000 }) // public 1accounts.put({ email = '[email protected]' timeZone = 'Asia/Tokyo' created = t - 80000 }) // public 2identities.put({ account = 1 identityName = 'Default' nickname = 'Al' firstname = 'Alice' lastname = 'Example' created = t - 89000 updated = t - 1000 }) // 1identities.put({ account = 1 identityName = 'Work' nickname = '' firstname = '' lastname = '' created = t - 70000 updated = t - 70000 }) // 2identities.put({ account = 2 identityName = 'Default' nickname = '' firstname = '' lastname = '' created = t - 79000 updated = t - 79000 }) // 3let gone = identities.put({ account = 1 identityName = 'Old' nickname = '' firstname = '' lastname = '' created = t - 60000 updated = t - 60000 }) // 4, deleted belowapps.put({ owner = 1 name = 'Fixture app' origins = 'http://127.0.0.1:8396' apiKey = 'pk_' + x('1', 32) secretHash = sha256('sk_' + x('2', 48)) created = t - 50000 updated = t - 50000 }) // 1apps.put({ owner = 2 name = 'Bob app' origins = 'http://127.0.0.1:8397' apiKey = 'pk_' + x('3', 32) secretHash = sha256('sk_' + x('4', 48)) created = t - 40000 updated = t - 40000 }) // 2conns.put({ pair = '1:1' app = 1 identity = 1 appIdentity = x('a', 32) created = t - 49000 })conns.put({ pair = '1:2' app = 1 identity = 2 appIdentity = x('b', 32) created = t - 48000 })conns.put({ pair = '1:4' app = 1 identity = 4 appIdentity = x('c', 32) created = t - 47000 })conns.put({ pair = '2:3' app = 2 identity = 3 appIdentity = x('d', 32) created = t - 39000 })identities.delete(gone)sends.put({ email = '[email protected]' at = t - 1000 })otp.put({ email = '[email protected]' hash = sha256('[email protected]:123456') expires = t + 600000 tries = 0 })requests.put({ rid = x('f', 32) app = 1 returnUrl = 'http://127.0.0.1:8396/callback' expires = t + 1800000 })grants.put({ hash = sha256(x('e', 48)) app = 1 identity = 2 appIdentity = x('b', 32) expires = t + 3600000 })console.log('oldstore: accounts ' + accounts.count() + ' identities ' + identities.count() + ' apps ' + apps.count() + ' connections ' + conns.count() + ' otp ' + otp.count() + ' sends ' + sends.count() + ' requests ' + requests.count() + ' grants ' + grants.count())
Branches
- mainmain branch