Add ALNODE BPQ web console with BBS, Winlink, chat and modem dashboard
This commit is contained in:
commit
5a50f0cfdf
213 files changed
+1027
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import {test} from 'node:test';import assert from 'node:assert/strict';import {parseMessages,parseMessage,parseRoutes,parseRadio} from './bpq.mjs';
|
||||
import {Chat,parseUser} from './chat.mjs';
|
||||
import {incoming} from './public/notifications.js';
|
||||
import {mailDirection,mailFolder,cmsStatus} from './model.mjs';
|
||||
import {parseAttachments,mimeOf,safeName,b2Body} from './attachments.mjs';
|
||||
test('B2 body excludes attachment bytes and preserves UTF8',()=>{const body=Buffer.from('Caffè');const b=Buffer.concat([Buffer.from(`Mid: example\r\nBody: ${body.length}\r\nFile: 3 a.bin\r\n\r\n`),body,Buffer.from('\r\nxxx')]);assert.equal(b2Body(b),'Caffè')});
|
||||
test('B2 attachments preserve binary bytes, byte lengths and multiple files',()=>{const body=Buffer.from('Caffè'),one=Buffer.from([0,255,13,10]),two=Buffer.from('hello');const header=Buffer.from(`Mid: test\r\nBody: ${body.length}\r\nFile: ${one.length} a.bin\r\nFile: ${two.length} notes.txt\r\n\r\n`);const message=Buffer.concat([header,body,Buffer.from('\r\n'),one,Buffer.from('\r\n'),two,Buffer.from('\r\n')]);const files=parseAttachments(message);assert.equal(files.length,2);assert.deepEqual(files[0].data,one);assert.deepEqual(files[1].data,two);assert.equal(files[1].mime,'text/plain');});
|
||||
test('untrusted HTML/SVG is text and filename paths are removed',()=>{assert.equal(mimeOf(Buffer.from('<svg onload=alert(1)>'),'x.svg'),'text/plain');assert.equal(mimeOf(Buffer.from('<html>'),'x.jpg'),'application/octet-stream');assert.equal(safeName('../../secret.png'),'secret.png');});
|
||||
test('truncated B2 attachment is rejected, ordinary bulletin has no binary attachments',()=>{assert.throws(()=>parseAttachments(Buffer.from('Body: 1\r\nFile: 999 foo.png\r\n\r\na\r\nxx')));assert.deepEqual(parseAttachments(Buffer.from('R:261013\r\n\r\nBulletin')),[]);});
|
||||
test('long RMS email route does not drop or shift the message row',()=>{const row='<a href=/WebMail/WM?W123&2482> 2482</a> 13-Oct PN 150 RMS IU2EUG@WINLINKIU2EUG Queue regression\r\n';const m=parseMessages(row)[0];assert.equal(m.id,2482);assert.equal(m.to,'RMS');assert.equal(m.from,'IU2EUG');assert.equal(m.subject,'Queue regression');});
|
||||
test('own outgoing emails stay in queue even with an SSID or full email sender',()=>{for(const from of ['IU2EUG','IU2EUG-11','[email protected]']){const m={from,fromAddress:from,to:'RMS',status:'N'};assert.equal(mailDirection(m),'outgoing');assert.equal(mailFolder(m),'queue')}assert.equal(mailFolder({from:'IU2EUG',status:'F'}),'sent');assert.equal(mailFolder({from:'K1AJD',status:'N'}),'inbox');});
|
||||
test('CMS clean close is recognized for both directions of FQ',()=>{for(const direction of ['<','>'])assert.equal(cmsStatus(`261013 20:52:23 |RMS Connecting to BBS RMS\n261013 20:52:26 ${direction}RMS FQ\n261013 20:52:28 |RMS RMS Disconnected`).state,'complete');});
|
||||
test('CMS disconnect alone is neutral, explicit protocol error is an error',()=>{const start='261013 20:52:23 |RMS Connecting to BBS RMS\n';assert.equal(cmsStatus(start+'261013 20:52:28 |RMS RMS Disconnected').state,'ended');assert.equal(cmsStatus(start+'261013 20:52:28 <RMS *** Protocol Error').state,'error');});
|
||||
test('arrival alerts ignore first load and previously seen IDs',()=>{const messages=[{id:1,type:'B',from:'IW2OHX'},{id:2,type:'P',from:'K1AJD'}];assert.deepEqual(incoming(messages,null),{bulletins:[],mail:[]});assert.deepEqual(incoming(messages,new Set([1,2])),{bulletins:[],mail:[]});});
|
||||
test('arrival alerts distinguish downloaded bulletins and incoming mail, exclude own writes',()=>{const got=incoming([{id:1,type:'B',from:'IW2OHX'},{id:2,type:'P',from:'K1AJD'},{id:3,type:'P',from:'IU2EUG'}],new Set());assert.equal(got.bulletins.length,1);assert.equal(got.mail.length,1);assert.equal(got.mail[0].id,2);});
|
||||
test('chat roster extracts callsign, name, node, room and idle time',()=>{assert.deepEqual(parseUser('K1AJD at AGCHAT Tony, Augusta, GA [General] Idle for 1279 seconds'),{call:'K1AJD',node:'AGCHAT',name:'Tony',qth:'Augusta, GA',topic:'General',idle:1279});});
|
||||
test('chat rejects command injection before writing to socket',()=>{const c=new Chat(async()=>({}));c.state='online';assert.throws(()=>c.send('hello\r/QUIT'));assert.throws(()=>c.send('/F'));assert.throws(()=>c.changeTopic('General\r/QUIT'));assert.throws(()=>c.send('hello','K1AJD\rB'));clearInterval(c.timer)});
|
||||
test('polling roster lines do not become conversation messages',()=>{const c=new Chat(async()=>({}));c.line('1 Station(s) connected:');c.line('IU2EUG at ALBCHT IU2EUG, Senago Italy [General] Idle for 0 seconds');assert.equal(c.events.length,0);assert.equal(c.users.length,1);clearInterval(c.timer)});
|
||||
test('fixed-width BPQ list retains empty routing field and decodes subject',()=>{const row='<a href=/WebMail/WM?W123&2444> 2444</a> 13-Oct PF 157 IW2OHX IU2EUG Test & hello\r\n';assert.deepEqual(parseMessages(row),[{id:2444,date:'13-Oct',type:'P',status:'F',size:157,to:'IW2OHX',via:'',from:'IU2EUG',subject:'Test & hello'}]);});
|
||||
test('bulletin columns and routing',()=>{const row='<a href=/WebMail/WM?W123&2466> 2466</a> 13-Oct BN 1784 DX WW HP2DFA DX bulletin\r\n';const m=parseMessages(row)[0];assert.equal(m.to,'DX');assert.equal(m.from,'HP2DFA');assert.equal(m.subject,'DX bulletin');});
|
||||
test('message content is extracted without executing HTML, CRs normalized',()=>{const m=parseMessage('<textarea id=txt>From: IU2EUG\nTo: TEST\nTitle: <script>\n\nhello\rworld & radio</textarea>');assert.equal(m.subject,'<script>');assert.equal(m.text,'hello\nworld & radio');});
|
||||
test('route status is distinct from last-heard value',()=>{const html='<tr>'+['>4','IW2OHX-15','192','6','100','2','0','4','5000','18:10','0','161'].map(c=>'<td>'+c+'</td>').join('')+'</tr>';assert.equal(parseRoutes(html)[0].active,true);assert.equal(parseRoutes(html)[0].nodes,6);});
|
||||
test('radio online/free/busy are separate states',()=>{const r=parseRadio('Comms State Connected to VARA TNC TNC State Free Mode 2300 Channel State Busy S/N 15,6 Traffic Sent 59 RXed 5480 FT991A 7.050 USB S');assert.equal(r.state,'Free');assert.equal(r.busy,true);assert.equal(r.frequency,'7.050');assert.equal(r.scanning,true)});
|
||||
|
||||
|
||||
test('BPQ monitor decodes fragmented and joined frames, ports and direction', async()=>{
|
||||
const {MonitorDecoder}=await import('./monitor.mjs');const frames=[],ports=[];const d=new MonitorDecoder(f=>frames.push(f),p=>ports.push(...p));
|
||||
const definition=Buffer.concat([Buffer.from([255,255]),Buffer.from('3|1 VARA HF|2 Telnet|4 AXIP|')]);
|
||||
const rx=Buffer.concat([Buffer.from([255,27,17]),Buffer.from('12:00:00R IW2OHX-15>NODES Port=4 <UI>\rhello\r'),Buffer.from([254])]);
|
||||
const tx=Buffer.concat([Buffer.from([255,27,91]),Buffer.from('12:00:01T IU2EUG>IW2OHX Port=1\rtest\r'),Buffer.from([254])]);
|
||||
const data=Buffer.concat([Buffer.from('node greeting'),definition,rx,tx]);for(const byte of data)d.push(Buffer.from([byte]));
|
||||
assert.deepEqual(ports.map(p=>p.id),[1,2,4]);assert.equal(frames.length,2);assert.equal(frames[0].direction,'RX');assert.equal(frames[0].port,4);assert.match(frames[0].text,/hello/);assert.equal(frames[1].direction,'TX');assert.equal(frames[1].port,1);assert.equal(d.buffer.length,0);
|
||||
});
|
||||
|
||||
|
||||
test('native VARA bitrate keeps TX/RX separate and excludes speed-level number', async()=>{
|
||||
const {parseVaraRate}=await import('./vara-rate.mjs');assert.deepEqual(parseVaraRate('<134>VARA BITRATE (14) 7050 BPS TX'),{bps:7050,direction:'TX',level:14});assert.deepEqual(parseVaraRate('BITRATE (9) 2682 BPS RX'),{bps:2682,direction:'RX',level:9});assert.deepEqual(parseVaraRate('BITRATE 270 RX'),{bps:270,direction:'RX',level:null});assert.equal(parseVaraRate('BUFFER 7050'),null);assert.equal(parseVaraRate('BITRATE ??? RX'),null);assert.equal(parseVaraRate('BITRATE 999999 BPS TX'),null);
|
||||
});
|
||||
|
||||
|
||||
test('BPQ message dates preserve UTC hours and infer previous year across January',async()=>{const {bpqTimestamp}=await import('./bpq.mjs');assert.equal(bpqTimestamp('14-Oct 12:11Z',new Date('2026-10-14T12:12:00Z')),'2026-10-14T12:11:00.000Z');assert.equal(bpqTimestamp('31-Dec 23:58Z',new Date('2026-01-01T01:00:00Z')),'2025-12-31T23:58:00.000Z');assert.equal(bpqTimestamp('31-Feb 12:00Z'),null);assert.equal(bpqTimestamp('14-Oct'),null);});
|
||||
Reference in new issue
Block a user