aerotun-health-smoke.cjs 3.5 KB

123456789101112131415161718192021
  1. const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright');
  2. const assert=require('node:assert/strict');
  3. (async()=>{const browser=await chromium.launch({headless:true,args:['--no-sandbox'],env:process.env});const page=await browser.newPage();const errors=[],starts=[];let session=0;
  4. page.on('pageerror',e=>errors.push(e.message));
  5. await page.route('**/api/vpn/aerotun/health',route=>route.fulfill({json:{states:[{tunnel_id:'health-id',status:'connected',since:'2026-01-01T00:00:00Z'}],events:[{tunnel_id:'health-id',time:'2026-01-01T00:00:00Z',type:'state',status:'connected',previous:'waiting'}]}}));
  6. await page.route('**/api/vpn/aerotun/tunnels/*/health-check',route=>route.fulfill({json:{reachability:'reachable',rtt_ms:4.2,mtu:1300,mtu_probe:'reachable',explanation:'Overlay result'}}));
  7. await page.route('**/api/tools/bwtest/start',route=>{starts.push(route.request().postDataJSON());session++;return route.fulfill({json:{session_id:'test-'+session,running:true}})});
  8. await page.route('**/api/tools/bwtest/status',route=>route.fulfill({json:{session_id:'test-'+session,running:false,summary:{avg_tx_mbps:42,avg_rx_mbps:43}}}));
  9. try{
  10. await page.goto(process.env.DEBTIK_TEST_URL||'http://127.0.0.1:8080/',{waitUntil:'domcontentloaded'});await page.locator('#login-username').fill(process.env.DEBTIK_TEST_USER||'admin');await page.locator('#login-password').fill(process.env.DEBTIK_TEST_PASSWORD||'admin');await page.locator('#login-submit-btn').click();await page.waitForFunction(()=>state.currentUser!==null);
  11. await page.evaluate(()=>{document.getElementById('section-aerotun').classList.remove('hidden');state.aerotunTunnels=[{id:'health-id',name:'aero-health',mode:'client',running:true,connected:true,backend:'veth',protocol_version:3,mtu:1300,configured_mtu:1420,local_address:'192.0.2.1/30',peer_address:'192.0.2.2/30',remote_endpoint:'198.51.100.1:51830',allowed_ips:['192.0.2.2/32'],rx_bytes:10,tx_bytes:20,packets_rx:1,packets_tx:2}];renderAeroTUN()});
  12. await page.evaluate(()=>openEditAeroTUNModal('health-id'));assert.equal(await page.locator('#aerotun-modal-mtu').inputValue(),'1420');await page.evaluate(()=>closeAeroTUNModal());
  13. await page.evaluate(()=>openAeroTUNHealth('health-id'));await page.waitForFunction(()=>document.getElementById('aerotun-health-history').textContent.includes('waiting'));
  14. assert.match(await page.locator('#aerotun-health-status').innerText(),/MTU: 1300 \/ configured 1420/);
  15. await page.locator('#aerotun-health-check-btn').click();assert.match(await page.locator('#aerotun-health-result').innerText(),/RTT 4.2 ms/);
  16. assert.equal(await page.locator('#aerotun-compare-host').inputValue(),'198.51.100.1');await page.locator('#aerotun-compare-btn').click();await page.waitForFunction(()=>document.getElementById('aerotun-compare-result').textContent.includes('different routes'),null,{timeout:12000});
  17. assert.deepEqual(starts.map(x=>[x.target,x.direction]),[['192.0.2.2','tx'],['192.0.2.2','rx'],['198.51.100.1','tx'],['198.51.100.1','rx']]);assert.deepEqual(errors,[]);
  18. await page.route('**/api/tools/bwtest/status',route=>route.fulfill({json:{session_id:'external',running:true}}));await page.locator('#aerotun-compare-btn').click();await page.waitForFunction(()=>document.getElementById('aerotun-compare-result').textContent.includes('Another bandwidth test is running'));assert.equal(starts.length,4);
  19. await page.evaluate(()=>handleLogoutClick());console.log('AeroTUN health, configured MTU, probe and four-step comparison passed.');
  20. }finally{await browser.close()}
  21. })().catch(e=>{console.error(e);process.exitCode=1});