test(cua): type consent storage fixtures for lint
This commit is contained in:
1 parent
0c59501534
commit
e8b7565454
4 files changed
+9
-7
No files matched your search
@@ -456,8 +456,8 @@ it('does not store a cancellation decision after provider disposal starts', asyn
|
||||
|
||||
it('rejects persistent consent when storage capability disappears before the commit', async () => {
|
||||
const f = await setup('Always allow')
|
||||
const original = vi.mocked(f.store.withState).getMockImplementation()!
|
||||
vi.mocked(f.store.withState).mockImplementationOnce(original).mockImplementationOnce((signal, operation) => {
|
||||
const original = f.withState.getMockImplementation()!
|
||||
f.withState.mockImplementationOnce(original).mockImplementationOnce((signal, operation) => {
|
||||
f.setWritable(false)
|
||||
return original(signal, operation)
|
||||
})
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
/** External file writer used to verify that an open provider reloads durable authorization. */
|
||||
import { readFile, rename, writeFile } from 'node:fs/promises'
|
||||
import type { PermissionState } from '../../src/permission-store.ts'
|
||||
import type { CuaApplicationId } from '../../src/application-types.ts'
|
||||
|
||||
const [file, id] = process.argv.slice(2)
|
||||
if (!file || !id) throw new Error('Expected storage file and application id')
|
||||
const record = JSON.parse(await readFile(file, 'utf8'))
|
||||
const record = JSON.parse(await readFile(file, 'utf8')) as { global: PermissionState }
|
||||
const existing = record.global.applications[id]
|
||||
record.global.applications[id] = {
|
||||
revoked: (existing?.revoked ?? 0) + 1,
|
||||
sessions: {},
|
||||
always: { id, name: 'Other process', executablePath: '/other' },
|
||||
always: { id: id as CuaApplicationId, name: 'Other process', executablePath: '/other' },
|
||||
}
|
||||
const temporary = `${file}.writer-${process.pid}`
|
||||
await writeFile(temporary, JSON.stringify(record))
|
||||
|
||||
@@ -32,7 +32,7 @@ export function permissionFixture(ctx: Context, initial: readonly CuaApplication
|
||||
observed = [...grants]
|
||||
})
|
||||
})
|
||||
vi.spyOn(store, 'withState').mockImplementation((signal, operation) => original(signal, async (transaction) => {
|
||||
const withState = vi.spyOn(store, 'withState').mockImplementation((signal, operation) => original(signal, async (transaction) => {
|
||||
observed = grantsOf(transaction.state)
|
||||
return operation({ ...transaction, save: async (next) => {
|
||||
const nextGrants = grantsOf(next)
|
||||
@@ -41,7 +41,7 @@ export function permissionFixture(ctx: Context, initial: readonly CuaApplication
|
||||
else await save(nextGrants, commit)
|
||||
} })
|
||||
}))
|
||||
return { store, save, grants: () => observed,
|
||||
return { store, save, withState, grants: () => observed,
|
||||
setWritable(value: boolean) { writable = value; capability.mockImplementation(() => writable) },
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ it('rejects malformed or identity-mismatched data without replacing it with lega
|
||||
await writeFile(file, '{broken')
|
||||
await expect(a.store.withState(signal, transaction => transaction.state)).rejects.toThrow()
|
||||
expect(await readFile(file, 'utf8')).toBe('{broken')
|
||||
const altered: { global: { applications: Record<string, { always: CuaApplicationGrant }> } } = JSON.parse(valid)
|
||||
const altered = JSON.parse(valid) as { global: { applications: Record<string, { always: CuaApplicationGrant }> } }
|
||||
altered.global.applications[grant.id]!.always.id = 'b'.repeat(64) as CuaApplicationId
|
||||
const mismatch = JSON.stringify(altered); await writeFile(file, mismatch)
|
||||
await expect(a.store.withState(signal, transaction => transaction.state)).rejects.toMatchObject({ code: 'invalid-record' })
|
||||
|
||||
Reference in new issue
Block a user