Port the Fuc 0.12.0 frontend and default-off VIP plugin. Include the previously approved password-reset token revocation. Deploy only to an independent FUC-XB test instance; no production cutover.
49 lines
9.0 KiB
JavaScript
49 lines
9.0 KiB
JavaScript
// Real HTTP -> Laravel -> isolated SQLite acceptance. No external providers.
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import {createApi} from '../../theme/Fuc/assets/core.mjs';
|
|
const origin='http://xb.loc';let token='';const email='qa-'+Date.now()+'@example.test';const evidence=[];
|
|
const api=createApi({getToken:()=>token,fetcher:(url,options)=>fetch(origin+url,options)});
|
|
async function check(name,fn){await fn();evidence.push(name);console.log('PASS '+name);}
|
|
await check('guest plans and login config',async()=>{assert.equal((await api('guest/plan/fetch')).length,2);assert.equal((await api('guest/comm/config')).app_name,'Fuc 验收站');});
|
|
await check('invalid credentials rejected',async()=>{await assert.rejects(api('passport/auth/login',{email:'[email protected]',password:'wrong-password'}));});
|
|
await check('real auth token and account endpoints',async()=>{const auth=await api('passport/auth/register',{email,password:'Fuc-QA-Only-2026!'});token=auth.auth_data;assert.ok(token.startsWith('Bearer '));assert.equal((await api('user/info')).email,email);assert.ok((await api('user/comm/config')).withdraw_methods.includes('支付宝'));});
|
|
await check('templates render and protected theme files are absent',async()=>{const page=await fetch(origin);assert.match(await page.text(),/fucSettings/);assert.equal((await fetch(origin+'/theme/Fuc/dashboard.blade.php')).status,404);});
|
|
await check('order create detail cancellation and persistent readback',async()=>{const no=await api('user/order/save',{plan_id:1,period:'month_price'});const detail=await api('user/order/detail?trade_no='+no);assert.equal(detail.total_amount,1200);assert.equal(detail.period,'month_price');await api('user/order/cancel',{trade_no:no});assert.equal(await api('user/order/check?trade_no='+no),2);});
|
|
await check('free checkout opens real subscription',async()=>{const no=await api('user/order/save',{plan_id:2,period:'month_price'});assert.deepEqual(await api('user/order/checkout',{trade_no:no,method:0}),{type:-1,data:true});assert.equal(await api('user/order/check?trade_no='+no),3);const sub=await api('user/getSubscribe');assert.equal(sub.plan_id,2);assert.equal(sub.transfer_enable,10*1024**3);});
|
|
await check('subscription reset changes old token',async()=>{const before=(await api('user/getSubscribe')).subscribe_url;await api('user/resetSecurity');const after=(await api('user/getSubscribe')).subscribe_url;assert.notEqual(after,before);});
|
|
await check('subscription URL serves local Clash Meta and Sing-box output',async()=>{const sub=await api('user/getSubscribe');for(const flag of ['meta','sing-box']){const url=new URL(sub.subscribe_url);assert.equal(url.origin,origin);url.searchParams.set('flag',flag);const response=await fetch(url);assert.equal(response.status,200);const body=await response.text();assert.ok(body.length);assert.doesNotMatch(body,/<html/i);}});
|
|
const {execFileSync}=await import('node:child_process');execFileSync('/usr/local/bin/php',['scripts/theme-fuc/integration-credit.php',email]);
|
|
await check('coupon changes authoritative order amount and ownership is enforced',async()=>{const code=email.split('@')[0];await api('user/coupon/check',{code,plan_id:1,period:'month_price'});const no=await api('user/order/save',{plan_id:1,period:'month_price',coupon_code:code});const detail=await api('user/order/detail?trade_no='+no);assert.equal(detail.discount_amount,100);const other=await api('passport/auth/register',{email:'foreign-'+Date.now()+'@example.test',password:'Fuc-QA-Only-2026!'});const foreign=createApi({getToken:()=>other.auth_data,fetcher:(u,o)=>fetch(origin+u,o)});await assert.rejects(foreign('user/order/detail?trade_no='+no));await api('user/order/cancel',{trade_no:no});const sessions=await foreign('user/getActiveSession');assert.equal(sessions.length,1);await foreign('user/removeActiveSession',{session_id:String(sessions[0].id)});});
|
|
await check('gift redemption credits wallet once and persists history',async()=>{const code=email.split('@')[0],before=await api('user/info');assert.equal((await api('user/gift-card/check',{code})).can_redeem,true);await api('user/gift-card/redeem',{code});assert.equal((await api('user/info')).balance,before.balance+500);assert.ok((await api('user/gift-card/history')).length);await assert.rejects(api('user/gift-card/redeem',{code}));});
|
|
await check('invite creation and commission transfer are persisted',async()=>{await api('user/invite/save');assert.ok((await api('user/invite/fetch')).codes.length);const before=await api('user/info');await api('user/transfer',{transfer_amount:100});const after=await api('user/info');assert.equal(after.balance,before.balance+100);assert.equal(after.commission_balance,before.commission_balance-100);});
|
|
await check('ticket create reply close',async()=>{await api('user/ticket/save',{subject:'Fuc接口验收 '+Date.now(),level:1,message:'测试工单'});const t=(await api('user/ticket/fetch'))[0];await api('user/ticket/reply',{id:t.id,message:'测试回复'});const detail=await api('user/ticket/fetch?id='+t.id);assert.equal(detail.message.length,2);await api('user/ticket/close',{id:t.id});assert.equal((await api('user/ticket/fetch?id='+t.id)).status,1);await assert.rejects(api('user/ticket/reply',{id:t.id,message:'关闭后不可回复'}));});
|
|
await check('withdraw uses configured methods and creates finance ticket',async()=>{await assert.rejects(api('user/ticket/withdraw',{withdraw_method:'invalid',withdraw_account:'QA'}));await api('user/ticket/withdraw',{withdraw_method:'支付宝',withdraw_account:'QA-local-only'});const t=(await api('user/ticket/fetch'))[0];assert.ok(t.subject);await api('user/ticket/close',{id:t.id});});
|
|
await check('reminders save and readback',async()=>{await api('user/update',{remind_expire:1,remind_traffic:0});assert.equal((await api('user/info')).remind_expire,true);});
|
|
await check('knowledge notices nodes traffic and gifts contracts',async()=>{assert.ok((await api('user/notice/fetch')).length);const groups=await api('user/knowledge/fetch?language=zh-CN');const doc=Object.values(groups).flat()[0];assert.match((await api('user/knowledge/fetch?id='+doc.id)).body,/订阅导入/);assert.ok(Array.isArray(await api('user/server/fetch')));assert.ok(Array.isArray(await api('user/stat/getTrafficLog')));assert.ok(Array.isArray(await api('user/gift-card/history')));await assert.rejects(api('user/gift-card/check',{code:'invalid-qa-code'}));await assert.rejects(api('user/coupon/check',{code:'invalid-qa-code',plan_id:1,period:'month_price'}));});
|
|
await check('password change retains current session and rejects old password',async()=>{await api('user/changePassword',{old_password:'Fuc-QA-Only-2026!',new_password:'Fuc-QA-Changed-2026!'});assert.equal((await api('user/info')).email,email);await assert.rejects(api('passport/auth/login',{email,password:'Fuc-QA-Only-2026!'}));});
|
|
await check('email code reset revokes every old login and permits only new credentials',async()=>{
|
|
const firstToken=token;
|
|
const secondToken=(await api('passport/auth/login',{email,password:'Fuc-QA-Changed-2026!'})).auth_data;
|
|
assert.equal((await api('user/getActiveSession')).length,2);
|
|
await api('passport/comm/sendEmailVerify',{email});
|
|
await assert.rejects(api('passport/auth/forget',{email,email_code:'wrong',password:'Fuc-QA-Reset-2026!'}));
|
|
assert.equal((await api('user/info')).email,email);
|
|
assert.equal((await api('user/getActiveSession')).length,2);
|
|
const code=execFileSync('/usr/local/bin/php',['scripts/theme-fuc/integration-email-code.php',email],{encoding:'utf8'}).trim();
|
|
assert.match(code,/^\d{6}$/);
|
|
await api('passport/auth/forget',{email,email_code:code,password:'Fuc-QA-Reset-2026!'});
|
|
for(const oldToken of [firstToken,secondToken]){
|
|
let expired=false;
|
|
const oldApi=createApi({getToken:()=>oldToken,onUnauthorized:()=>expired=true,fetcher:(u,o)=>fetch(origin+u,o)});
|
|
await assert.rejects(oldApi('user/info'));assert.equal(expired,true);
|
|
}
|
|
await assert.rejects(api('passport/auth/login',{email,password:'Fuc-QA-Changed-2026!'}));
|
|
token=(await api('passport/auth/login',{email,password:'Fuc-QA-Reset-2026!'})).auth_data;
|
|
assert.equal((await api('user/getActiveSession')).length,1);
|
|
await assert.rejects(api('passport/auth/forget',{email,email_code:code,password:'Another-QA-Reset-2026!'}));
|
|
assert.equal((await api('user/info')).email,email);
|
|
});
|
|
await check('revoked session returns 403 and clears theme authentication',async()=>{const sessions=await api('user/getActiveSession');assert.ok(sessions.length);for(const session of sessions.sort((a,b)=>a.id-b.id))await api('user/removeActiveSession',{session_id:String(session.id)});let expired=false;const dead=createApi({getToken:()=>token,onUnauthorized:()=>expired=true,fetcher:(url,opt)=>fetch(origin+url,opt)});await assert.rejects(dead('user/info'));assert.equal(expired,true);});
|
|
fs.mkdirSync('codex/output/fuc-theme',{recursive:true});fs.writeFileSync('codex/output/fuc-theme/integration-20261101.json',JSON.stringify({checks:evidence,passed:evidence.length,environment:'isolated XB kernel and SQLite; provider HTTP blocked, mail and other jobs faked; real OrderHandleJob allowed'},null,2));
|