Guide Wi-Fi purchase in four simple steps and configure LGPD notice with environment variables
build-image / build-push (push) Successful in 3m1s

This commit is contained in:
jfeng committed 2026-10-22 22:17:12 +00:00
1 parent ce6e5980ec
commit 024adcb1cb
7 files changed
+114 -67

No files matched your search

+33 -15
View File
@@ -5,14 +5,13 @@ import vm from 'node:vm';
const html=fs.readFileSync(new URL('../public/index.html',import.meta.url),'utf8');
const code=html.match(/<script>([\s\S]*?)<\/script>/)[1];
async function portal({search,storage={},access={ok:true,authenticated:true,seconds:120},externalAvailable=true,clipboardAvailable=true,legacyCopy=false,consent=true,siteConfig={},paymentStatus={status:'pending'}}) {
async function portal({search,storage={},access={ok:true,authenticated:true,seconds:120},externalAvailable=true,clipboardAvailable=true,legacyCopy=false,siteConfig={},paymentStatus={status:'pending'}}) {
const ids=[...html.matchAll(/\bid="([^"]+)"/g)].map(m=>m[1]);
const listeners=new Map(),clipboard=[];
const elements=new Map(ids.map(id=>[id,{textContent:'',hidden:false,disabled:false,value:'',innerHTML:'',classList:{toggle(){},add(){},remove(){}},addEventListener:(event,fn)=>listeners.set(id+':'+event,fn),appendChild(){}}]));
const elements=new Map(ids.map(id=>[id,{textContent:'',hidden:false,disabled:false,value:'',innerHTML:'',style:{},attributes:{},setAttribute(k,v){this.attributes[k]=v;},removeAttribute(k){delete this.attributes[k];},classList:{toggle(){},add(){},remove(){}},addEventListener:(event,fn)=>listeners.set(id+':'+event,fn),appendChild(){}}]));
const requests=[],forms=[],intervals=[],navigations=[];
const sandbox={URL,URLSearchParams,Date,AbortController,console,location:{search},navigator:{},sessionStorage:{getItem:k=>storage[k]??null,setItem:(k,v)=>storage[k]=v,removeItem:k=>delete storage[k]},document:{getElementById:id=>{assert.ok(elements.has(id),'Missing element '+id);return elements.get(id);},body:{append(){}},createElement:tag=>({append(){},submit(){forms.push(tag);}})},setTimeout(){},clearTimeout(){},setInterval:fn=>{intervals.push(fn);return intervals.length;},clearInterval(){},window:{addEventListener(){},scrollTo(){}}};
sandbox.location.href='https://hotspot.example.test/'+(search || '');
elements.get('accessConsent').checked=consent;
sandbox.window.location={replace:url=>navigations.push(url)};
sandbox.navigator.clipboard={writeText:async text=>{if(!clipboardAvailable)throw new Error('Clipboard denied');clipboard.push(text);}};
sandbox.document.body.appendChild=()=>{};
@@ -60,12 +59,12 @@ test('direct portal URL without MAC cannot silently claim temporary access',asyn
test('portal reports cooldown failures and offers retry',async()=>{
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11&free=1',access:{ok:false,error:'Janela encerrada.',retryAfterSeconds:180}});
assert.match(p.elements.get('freeAccessMessage').textContent,/3 minutos/);
assert.equal(p.elements.get('retryFreeAccess').hidden,false);
assert.ok(p.elements.has('copyBtn'));
});
test('browsing plans does not consume the payment internet window',async()=>{
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11'});
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,0);
assert.match(p.elements.get('freeAccessMessage').textContent,/Gere o PIX e copie/);
assert.match(p.elements.get('freeAccessMessage').textContent,/Escolha um plano/);
});
test('generating or restoring a PIX leaves it visible without granting internet or navigating',async()=>{
const storage={};
@@ -75,7 +74,7 @@ test('generating or restoring a PIX leaves it visible without granting internet
assert.ok(paths.includes('/api/checkout'));
assert.ok(!paths.includes('/api/access/start'));
assert.equal(p.navigations.length,0);
assert.match(p.elements.get('freeAccessMessage').textContent,/Copiar PIX/);
assert.match(p.elements.get('freeAccessMessage').textContent,/Copiar código PIX/);
assert.equal(JSON.parse(storage.pendingPix).paymentId,'Ptest');
assert.equal(p.elements.get('copiaCola').textContent,'test-pix');
const reloaded=await portal({search:'?mac=AA:BB:CC:DD:EE:11',storage});
@@ -142,9 +141,9 @@ test('failed clipboard copy keeps the PIX open without consuming the internet wi
assert.equal(p.navigations.length,0);
assert.equal(p.elements.get('copyBtn').disabled,false);
assert.match(p.elements.get('toast').textContent,/copie o código manualmente/);
// The explicit button remains available after the guest has copied manually.
await p.click('retryFreeAccess');
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,1);
assert.equal(p.elements.has('retryFreeAccess'),false);
await p.click('copyBtn');
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,0);
});
test('legacy clipboard success permits access only after the copy attempt succeeds',async()=>{
@@ -166,18 +165,37 @@ test('an expired or denied window cannot navigate, and a new window can revalida
assert.equal(next.navigations.length,1);
});
test('rules use the configured payment duration and require acknowledgement before access',async()=>{
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11',consent:false,siteConfig:{freeSeconds:180,freeCooldownSeconds:2700}});
test('guided payment has clear rules and one copy action without a separate release button',async()=>{
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11',siteConfig:{freeSeconds:180,freeCooldownSeconds:2700}});
assert.match(p.elements.get('accessRules').textContent,/3 minutos/);
assert.match(p.elements.get('accessRules').textContent,/45 minutos após o fim/);
await p.checkout();await p.click('copyBtn');
assert.equal(p.elements.has('retryFreeAccess'),false);
assert.equal(p.elements.has('accessConsent'),false);
await p.checkout();
assert.equal(p.elements.get('step-pay').attributes['aria-current'],'step');
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,0);
assert.match(p.elements.get('freeAccessMessage').textContent,/confirme acima/);
p.elements.get('accessConsent').checked=true;
await p.click('retryFreeAccess');
await p.click('copyBtn');
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,1);
});
test('privacy information is available outside the steps and never requests a bank password',()=>{
assert.match(html,/<details[^>]*id="privacyNotice"/);
assert.match(html,/Seus dados e sua privacidade \(LGPD\)/);
assert.match(html,/não pede sua senha do banco/);
assert.match(html,/acesso, correção e exclusão quando cabível/);
assert.ok(!html.includes('id="retryFreeAccess"'));
});
test('privacy environment fields render as text, including markup, without replacing HTML',async()=>{
const privacy={controller:'Empresa Exemplo',contact:'[email protected]',retention:'Registros de compra: <b>prazo definido pelo responsável</b>'};
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11',siteConfig:{privacy}});
assert.equal(p.elements.get('privacyController').textContent,privacy.controller);
assert.equal(p.elements.get('privacyContact').textContent,privacy.contact);
assert.equal(p.elements.get('privacyRetention').textContent,privacy.retention);
assert.equal(p.elements.get('privacyRetention').innerHTML,'');
assert.equal(p.requests.filter(r=>r.path==='/api/access/start').length,0);
});
test('confirmed payment distinguishes activation pending from an active paid connection',async()=>{
for(const state of ['pending','active']){
const p=await portal({search:'?mac=AA:BB:CC:DD:EE:11',storage:{paymentId:'Ptest'},paymentStatus:{status:'paid',voucher:{user:'paid-user',pass:'paid-pass'},connection:{state}}});