const assert=require('node:assert/strict');global.window={};require('../../static/js/link-targets.js');const {href,sshTarget}=window.LinkTargets; assert.equal(href({type:'ssh',host:'server.local',username:'admin',port:2222}),'ssh://admin@server.local:2222'); assert.equal(href({type:'ssh',url:'ssh://admin@server.local:2222'}),'ssh://admin@server.local:2222'); assert.equal(sshTarget({host:'server.local:2222',username:'admin'}).command,'ssh -p 2222 admin@server.local'); assert.equal(href({type:'ssh',host:'2001:db8::1'}),'ssh://[2001:db8::1]'); assert.equal(href({type:'ssh',url:'ssh://admin@[2001:db8::1]:2222'}),'ssh://admin@[2001:db8::1]:2222'); for(const host of ['-oProxyCommand=bad','server;bad','server$(bad)','server/path','server bad'])assert.equal(sshTarget({host}),null); assert.equal(href({type:'ssh',url:'ssh://user:password@host'}),''); assert.equal(href({type:'ssh',host:'server',port:99999}),''); assert.equal(href({type:'http',host:'server.local'}),'http://server.local'); assert.equal(href({type:'http',url:'https://server.local/path'}),'https://server.local/path'); assert.equal(href({type:'http',url:'javascript:alert(1)'}),''); assert.equal(href({type:'command',url:'ssh host'}),''); console.log('SSH/web target regression checks passed'); const {rdpTarget}=window.LinkTargets; assert.equal(rdpTarget({host:'172.16.20.31',port:3390}),'rdp://full%20address=s%3A172.16.20.31%3A3390'); assert.equal(rdpTarget({host:'server',username:'DOMAIN\\user'}),'rdp://full%20address=s%3Aserver%3A3389&username=s%3ADOMAIN%5Cuser'); assert.equal(rdpTarget({host:'server:3391'}),'rdp://full%20address=s%3Aserver%3A3391'); assert.equal(rdpTarget({host:'2001:db8::1'}),'rdp://full%20address=s%3A%5B2001%3Adb8%3A%3A1%5D%3A3389'); assert.equal(rdpTarget({host:'server',port:70000}),''); assert.equal(rdpTarget({url:'javascript:alert(1)'}),''); console.log('RDP direct-app target regression checks passed');