Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@danj/audible-auth

Locked Audible gateway using one owner-provisioned Kody login.

FollowFork

Files

registration-identity.test.ts

45 lines · 2.5 KB · TypeScript
import assert from 'node:assert/strict'
import { beforeEach, test } from 'node:test'
import { fixture as f, reset } from './helpers/runtime.ts'
const request = (await import('../request.ts')).default
const { readBackoff } = await import('../backoff.ts')
const { disconnect } = await import('../disconnect.ts')
const a = '00000000-0000-4000-8000-000000000001', b = '00000000-0000-4000-8000-000000000002'
beforeEach(() => { reset(); f.description = JSON.stringify({ registration: a, deviceName: 'Before' }) })
test('registration: website metadata edits cannot clear an existing wait', async () => {
 f.provider = async () => new Response(null, { status: 401 })
 await assert.rejects(request({ path: '/1.0/library' }))
 const wait = await readBackoff()
 f.updatedAt = 'edited'; f.description = JSON.stringify({ registration: a, deviceName: 'After', note: 'owner edit' })
 f.provider = async () => Response.json({})
 await assert.rejects(request({ path: '/1.0/wishlist' }), /login wait/)
 assert.deepEqual(await readBackoff(), wait); assert.equal(f.fetches, 1)
})
test('registration: website metadata edits cannot clear a Disconnect', async () => {
 await disconnect()
 const state = await readBackoff()
 f.updatedAt = 'edited'; f.description = JSON.stringify({ registration: a, deviceName: 'After' })
 await assert.rejects(request({ path: '/1.0/library' }), { name: 'NotConnectedError' })
 assert.deepEqual(await readBackoff(), state); assert.equal(f.fetches, 1)
})
test('registration: a new UUID resets the wait even with unchanged updated_at', async () => {
 f.provider = async () => new Response(null, { status: 401 })
 await assert.rejects(request({ path: '/1.0/library' }))
 const wait = await readBackoff()
 f.description = JSON.stringify({ registration: b })
 f.provider = async () => Response.json({})
 await request({ path: '/1.0/wishlist' })
 const state = await readBackoff()
 assert.equal(state.generation, wait.generation + 1); assert.equal(state.failures, 0)
})
test('registration: missing, malformed and invalid markers fail closed without clearing state', async () => {
 f.provider = async () => new Response(null, { status: 401 })
 await assert.rejects(request({ path: '/1.0/library' }))
 const wait = await readBackoff()
 for (const description of ['', '{}', 'null', 'malformed', JSON.stringify({ registration: 'invalid' })]) {
  f.description = description; f.updatedAt = 'edited'
  await assert.rejects(request({ path: '/1.0/wishlist' }), /registration marker/)
  assert.deepEqual(await readBackoff(), wait)
 }
 assert.equal(f.fetches, 1)
})