Files
moyi-model-intelligence-hub/prototype/tests/auth-security-preview.ts
T

20 lines
1.8 KiB
TypeScript

// Isolated UI fixture; every API request is intercepted. No real account or credentials are used.
import { createApp, h, ref } from 'vue'
import AccountSettings from '../src/components/AccountSettings.vue'
import AuthView from '../src/views/AuthView.vue'
import '../src/styles.css'
const user = { id: 'isolated-security-user', account: 'test@example.test', accountKind: 'email' as const, displayName: '隔离测试账号', role: 'super_admin' as const, status: 'active' as const, createdAt: '2026-10-21T00:00:00Z' }
const loginRequired = ref(false), notice = ref(''), writes = ref(0)
window.fetch = async (input, init) => {
const path = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url, location.origin).pathname
const json = (data: unknown) => new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
if (path === '/api/auth/account' && init?.method === 'PATCH') { writes.value++; return json({ user }) }
if (path === '/api/auth/verification') return json({ email: false, phone: false })
if (path.includes('/mfa')) return json({ enabled: false, recoveryRemaining: 0 })
return json({})
}
createApp({ setup: () => () => h('main', [
h('output', { 'aria-label': '隔离测试状态', style: 'display:block;padding:16px;background:#fffaf4;position:fixed;top:0;left:0;z-index:2000;font-size:14px' }, `模拟接口写入 ${writes.value} 次;需要重新登录:${loginRequired.value ? '是' : '否'}。${notice.value}`),
loginRequired.value ? h(AuthView, { onNotify: (message: string) => notice.value = message }) : h(AccountSettings, { user, onReauthenticate: () => loginRequired.value = true, onSaved: () => notice.value = '仅资料保存不退出登录', onNotify: (message: string) => notice.value = message }),
]) }).mount('#app')