86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
import test from 'brittle'
|
|
import b4a from 'b4a'
|
|
import {
|
|
applyGuestEnv,
|
|
exportPersonalDriveNamespace,
|
|
invalidateIdentityCachesAndHistory,
|
|
importPersonalDriveNamespace
|
|
} from './lib/identity/identity-session.js'
|
|
|
|
test('exportPersonalDriveNamespace derives uid account prefix for unlocked users', (t) => {
|
|
const ns = exportPersonalDriveNamespace({
|
|
BARE_OS_PERSONAL_ACCT_PREFIX: '1',
|
|
HOME: '/home/alice',
|
|
UID: '4242'
|
|
})
|
|
t.is(ns.schema, 1)
|
|
t.is(ns.accountPrefixRouting, true)
|
|
t.is(ns.homeSegment, 'alice')
|
|
t.is(ns.vaultAcctPrefix, 'bare-os/acct/u4242/')
|
|
})
|
|
|
|
test('exportPersonalDriveNamespace uses guest prefix for guest session', (t) => {
|
|
const ns = exportPersonalDriveNamespace({
|
|
BARE_OS_PERSONAL_ACCT_PREFIX: 'true',
|
|
HOME: '/home/guest',
|
|
UID: '65534'
|
|
})
|
|
t.is(ns.accountPrefixRouting, true)
|
|
t.is(ns.vaultAcctPrefix, 'bare-os/acct/_guest/')
|
|
})
|
|
|
|
test('importPersonalDriveNamespace accepts schema 1 snapshots', (t) => {
|
|
const imported = importPersonalDriveNamespace({
|
|
schema: 1,
|
|
accountPrefixRouting: true,
|
|
homeSegment: 'alice',
|
|
vaultAcctPrefix: 'bare-os/acct/u4242/'
|
|
})
|
|
t.ok(imported.accepted)
|
|
t.is(imported.schema, 1)
|
|
t.is(imported.homeSegment, 'alice')
|
|
t.is(imported.vaultAcctPrefix, 'bare-os/acct/u4242/')
|
|
})
|
|
|
|
test('importPersonalDriveNamespace rejects malformed snapshots', (t) => {
|
|
const imported = importPersonalDriveNamespace(null)
|
|
t.absent(imported.accepted)
|
|
t.is(imported.schema, 0)
|
|
t.is(imported.vaultAcctPrefix, '')
|
|
})
|
|
|
|
test('guest-to-login identity switch invalidates /bin cache and fish history', async (t) => {
|
|
let warmCacheClears = 0
|
|
/** @type {string[]} */
|
|
const invalidateReasons = []
|
|
let fishReloads = 0
|
|
const ctx = {
|
|
vfs: {
|
|
env: {},
|
|
bareOsClearWarmReadCaches() {
|
|
warmCacheClears++
|
|
},
|
|
async chdir() {}
|
|
},
|
|
console: { error() {} },
|
|
bareOsInvalidateWarmReadCaches(reason) {
|
|
invalidateReasons.push(String(reason || ''))
|
|
},
|
|
async bareOsReloadFishHistoryForIdentity() {
|
|
fishReloads++
|
|
}
|
|
}
|
|
|
|
await applyGuestEnv(ctx)
|
|
ctx.identity = {
|
|
state: 'unlocked',
|
|
publicKey: b4a.alloc(32, 7),
|
|
secretKey: b4a.alloc(64, 9)
|
|
}
|
|
await invalidateIdentityCachesAndHistory(ctx)
|
|
|
|
t.is(warmCacheClears, 2)
|
|
t.alike(invalidateReasons, ['identity-switch', 'identity-switch'])
|
|
t.is(fishReloads, 2)
|
|
})
|