;(async () => { const assert = (value, message) => { if (!value) throw new Error(message) } const phase = sessionStorage.getItem('auth-flow-phase') || 'login' if (phase === 'login') { const form = document.querySelector('form[action="/_/auth/login"]') assert(form, 'Login form missing') form.elements.username.value = 'admin' form.elements.password.value = 'a long test password' sessionStorage.setItem('auth-flow-phase', 'authenticated') form.requestSubmit() return } if (phase === 'authenticated') { assert(location.pathname === '/-/sys/config', 'Cookie login did not return to configuration') assert(document.querySelector('.auth-user-name')?.textContent.includes('Test Admin'), 'Authenticated account missing') assert(!document.cookie.includes('pageswiki_session'), 'Session cookie is not HttpOnly') const confirmation = await fetch('/_/auth/logout') assert(confirmation.ok && (await confirmation.text()).includes('action="/_/auth/logout"'), 'Logout GET is not confirmation') const api = await fetch('/_/api/v1/queue') assert(api.ok, 'Logout GET revoked the browser session') const form = document.querySelector('.auth-menu-popover form[action="/_/auth/logout"]') assert(form?.method === 'post', 'Account menu logout is not POST') sessionStorage.setItem('auth-flow-phase', 'logged-out') form.requestSubmit() return } assert(location.pathname === '/_/auth/login', 'Logout did not return to login') const denied = await fetch('/_/api/v1/queue') assert(denied.status === 401, 'Logged-out cookie still authenticated') document.body.dataset.vimReady = 'true' })().catch(error => { const element = document.createElement('pre') element.id = 'error' element.textContent = error.stack || String(error) document.body.append(element) })