Build legacy drivers and publish per-OS packages with web activation and DEB
This commit is contained in:
25
tests/test_driver_ui.cjs
Normal file
25
tests/test_driver_ui.cjs
Normal file
@@ -0,0 +1,25 @@
|
||||
// Optional UI test: npm install --prefix build/ui playwright; playwright install chromium
|
||||
const {chromium}=require('../build/ui/node_modules/playwright');
|
||||
const fs=require('fs'),path=require('path'),assert=require('assert');
|
||||
(async()=>{
|
||||
const browser=await chromium.launch({args:['--no-sandbox']});
|
||||
const page=await browser.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
||||
let platforms=[],activated=false;
|
||||
const state={defaultPassword:false,groups:Object.fromEntries(['1','2','3','4','5','12','13','17','21','45','200'].map(x=>[x,[]])),text:'',revision:'test',csrf:'test',validation:{errors:[]},devices:[],backups:[],path:'/test',services:true};
|
||||
await page.route('**/*',async route=>{const u=new URL(route.request().url()).pathname;let body;
|
||||
if(u==='/api/state')body=state;
|
||||
else if(u==='/api/status')body={'mars-nwe-pcap.service':'ActiveState=inactive','mars-pcapd.service':'ActiveState=inactive'};
|
||||
else if(u==='/api/drivers')body={platforms,map:activated?'MAP ROOT T:=SYS:PUBLIC/DRIVERS/TEST':''};
|
||||
else if(u==='/api/drivers/activate'){const data=route.request().postDataJSON();assert.equal(data.confirm,true);assert.deepEqual(data.platforms,['WIN95','WINXP']);platforms=data.platforms;activated=true;body={ok:true};}
|
||||
else if(u==='/api/gateway')body={config:{enabled:false,network:'0x101',gateway:'10.250.0.1',dns:'1.1.1.1',uplink:'',clients:[]},revision:'r',status:'Disabled'};
|
||||
else {const file=path.join(__dirname,'../websetup',u==='/'?'index.html':u.slice(1));return route.fulfill({body:fs.readFileSync(file),contentType:u.endsWith('.js')?'text/javascript':u.endsWith('.css')?'text/css':'text/html'});}
|
||||
return route.fulfill({json:body});});
|
||||
await page.goto('http://127.0.0.1:18889/');
|
||||
await page.locator('#gatewayOpen').click();await page.locator('#gwWinClients').click();
|
||||
await page.waitForFunction(()=>document.querySelector('#driverStatus').textContent.includes('Noch keine'));
|
||||
assert.equal(await page.locator('a[href^="/drivers/"]:visible').count(),0);
|
||||
await page.locator('[name=driverOS][value=WIN95]').check();await page.locator('[name=driverOS][value=WINXP]').check();
|
||||
await page.locator('#activateDrivers').click();await page.waitForFunction(()=>document.querySelector('#driverStatus').textContent.startsWith('MAP ROOT'));
|
||||
assert.equal(await page.locator('a[href^="/drivers/"]:visible').count(),2);assert(activated);assert.deepEqual(errors,[]);
|
||||
await page.screenshot({path:path.join(__dirname,'../build/driver-modal.png'),fullPage:true});await browser.close();console.log('PASS Chromium: OS selection, activation, filtered downloads, MAP instruction, modal');
|
||||
})().catch(e=>{console.error(e);process.exit(1)});
|
||||
11
tests/test_gateway.c
Normal file
11
tests/test_gateway.c
Normal file
@@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include "gateway.h"
|
||||
#include "ipxpkt.h"
|
||||
#include <assert.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
struct packets {size_t len[3];uint8_t data[3][546];int count;};
|
||||
static int store(void*ctx,const uint8_t*p,size_t n){struct packets*a=ctx;assert(a->count<3&&n<=546);a->len[a->count]=n;memcpy(a->data[a->count++],p,n);return 0;}
|
||||
static void protocol(void){uint8_t frame[1514],out[1514],node[6]={2,1,2,3,4,5};for(size_t i=0;i<sizeof frame;i++)frame[i]=(uint8_t)(i*17);for(unsigned port=PKT_PLAIN;port<=PKT_TRAIL;port++){struct packets a={0};struct pkt_rx r={0};assert(!pkt_send(port,0x1234,frame,sizeof frame,store,&a)&&a.count==3);int off=port==PKT_TRAIL?32:0;assert(a.data[0][off]==1&&a.data[0][off+1]==3&&a.data[0][off+2]==0x34&&a.data[0][off+3]==0x12);assert(a.len[0]==546);assert(pkt_receive(&r,1,node,port,a.data[2],a.len[2],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[2],a.len[2],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[1],a.len[1],1,out)==1514);assert(!memcmp(frame,out,sizeof frame));/* Timeouts and distinct source keys */assert(!pkt_receive(&r,1,node,port,a.data[0],a.len[0],10,out));assert(!pkt_receive(&r,2,node,port,a.data[1],a.len[1],10,out));assert(!pkt_receive(&r,1,node,port,a.data[1],a.len[1],14,out));assert(!pkt_receive(&r,1,node,port,a.data[2],a.len[2],14,out));assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],14,out)==1514);a.data[0][off]=0;assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],15,out)<0);a.data[0][off]=1;a.data[0][off+1]=4;assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],15,out)<0);assert(pkt_receive(&r,1,node,port,a.data[0],3,15,out)<0);assert(pkt_receive(&r,1,node,port,a.data[0],547,15,out)<0);for(unsigned j=0;j<500;j++){struct packets b={0};assert(!pkt_send(port,j,frame,60,store,&b));assert(pkt_receive(&r,1,node,port,b.data[0],b.len[0],20,out)==60);assert(!memcmp(frame,out,60));}}}
|
||||
static void policy(void){char e[256];struct gw_config c;json_object*o=gw_default();assert(!gw_parse(o,&c,e,sizeof e)&&!c.enabled);json_object_put(o);o=json_tokener_parse("{\"enabled\":true,\"network\":\"0x101\",\"gateway\":\"10.250.0.1\",\"dns\":\"1.1.1.1\",\"uplink\":\"eth0\",\"web\":true,\"ping\":true,\"clients\":[{\"mac\":\"020102030405\",\"ip\":\"10.250.0.10\"}]}");assert(!gw_parse(o,&c,e,sizeof e)&&c.count==1&&ntohl(c.net)==0x101);uint8_t mac[]={2,9,8,7,6,5},f[60]={0};memcpy(f,mac,6);memcpy(f+6,c.peers[0].mac,6);put16(f+12,0x0800);f[14]=0x45;put16(f+16,20);memcpy(f+26,&c.peers[0].ip,4);assert(gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[26]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[26]^=1;f[6]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[6]^=1;put16(f+12,0x86dd);assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));memset(f,255,6);put16(f+12,0x0806);put16(f+14,1);put16(f+16,0x0800);f[18]=6;f[19]=4;put16(f+20,1);memcpy(f+22,c.peers[0].mac,6);memcpy(f+28,&c.peers[0].ip,4);memcpy(f+38,&c.ip,4);assert(gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[41]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));json_object_object_add(o,"uplink",json_object_new_string("eth0;evil"));assert(gw_parse(o,&c,e,sizeof e));json_object_object_add(o,"uplink",json_object_new_string("eth0"));json_object_object_add(o,"dns",json_object_new_string("192.168.1.1"));assert(gw_parse(o,&c,e,sizeof e));json_object_object_add(o,"dns",json_object_new_string("1.1.1.1"));json_object *a=NULL;json_object_object_get_ex(o,"clients",&a);json_object_array_add(a,json_object_get(json_object_array_get_idx(a,0)));assert(gw_parse(o,&c,e,sizeof e));json_object_put(o);}
|
||||
int main(void){protocol();policy();puts("PASS: IPXPKT both sockets, little-endian IDs, fragmentation, out-of-order, duplicates, expiry, throughput, malformed data, config validation, static MAC/IP and ARP policy");}
|
||||
9
tests/test_gateway_auto.c
Normal file
9
tests/test_gateway_auto.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "../native/gateway_auto.h"
|
||||
#include "gateway.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
static void subnets(void){json_object*r=json_tokener_parse("[{\"dst\":\"default\"},{\"dst\":\"10.250.0.0/23\",\"dev\":\"cni0\"},{\"dst\":\"10.250.2.10\",\"dev\":\"vpn0\"},{\"dst\":\"192.168.1.0/24\"}]");assert(!ga_free(r,inet_addr("10.250.0.1")));assert(!ga_free(r,inet_addr("10.250.1.1")));assert(!ga_free(r,inet_addr("10.250.2.1")));assert(ga_choose(r)==inet_addr("10.250.3.1"));json_object_put(r);r=json_tokener_parse("[{\"dst\":\"10.250.0.0/24\",\"dev\":\"marsipx0\"},{\"dst\":\"10.250.0.1\",\"dev\":\"marsipx0\"}]");assert(ga_free(r,inet_addr("10.250.0.1")));json_object_put(r);assert(!ga_free(NULL,inet_addr("10.250.0.1")));}
|
||||
static unsigned request(uint8_t*f,struct gw_peer*q,struct gw_config*c,int type,int wrong){memset(f,0,600);memset(f,255,6);memcpy(f+6,q->mac,6);put16(f+12,0x800);f[14]=0x45;f[23]=17;memset(f+30,255,4);put16(f+34,68);put16(f+36,67);uint8_t*b=f+42;b[0]=1;b[1]=1;b[2]=6;put32(b+4,123456);memcpy(b+28,q->mac,6);put32(b+236,0x63825363);uint8_t*p=b+240;*p++=53;*p++=1;*p++=type;if(type==3){*p++=50;*p++=4;uint32_t ip=wrong?inet_addr("10.250.0.19"):q->ip;memcpy(p,&ip,4);p+=4;*p++=54;*p++=4;memcpy(p,&c->ip,4);p+=4;}*p++=255;unsigned len=p-b;put16(f+16,len+28);put16(f+38,len+8);return len+42;}
|
||||
static void dhcp(void){struct gw_config c={.ip=0,.dns=0};c.ip=inet_addr("10.250.0.1");c.dns=inet_addr("1.1.1.1");struct gw_peer q={.mac={2,1,2,3,4,5},.ip=0};q.ip=inet_addr("10.250.0.10");uint8_t mac[]={2,9,8,7,6,5},f[600],out[600];unsigned n=request(f,&q,&c,1,0);assert(gw_dhcp(&c,&q,mac,f,n,out)==342);assert(out[284]==2&&get32(out+46)==123456&&!memcmp(out+58,&q.ip,4));n=request(f,&q,&c,3,0);assert(gw_dhcp(&c,&q,mac,f,n,out)>0&&out[284]==5);n=request(f,&q,&c,3,1);assert(gw_dhcp(&c,&q,mac,f,n,out)>0&&out[284]==6&&get32(out+58)==0);f[70]^=1;assert(gw_dhcp(&c,&q,mac,f,n,out)==-1);n=request(f,&q,&c,1,0);f[n-1]=50;assert(gw_dhcp(&c,&q,mac,f,n,out)==-1);n=request(f,&q,&c,1,0);assert(gw_dhcp(&c,&q,mac,f,n-1,out)==-1);}
|
||||
int main(void){subnets();dhcp();puts("PASS: overlapping routes, DHCP OFFER/ACK/NAK, malformed and spoofed packets");}
|
||||
26
tests/test_gateway_browser.py
Normal file
26
tests/test_gateway_browser.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Optional dev-only Chromium test with mock API; not a server dependency."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
from playwright.sync_api import sync_playwright
|
||||
root=Path(__file__).resolve().parents[1]/'websetup'
|
||||
screen=Path(os.environ.get('MARS_GATEWAY_SCREENSHOT',str(root.parent/'build/gateway.png')))
|
||||
state=dict(defaultPassword=False,groups={k:[] for k in ['1','2','3','4','5','12','13','17','21','45','200']},text='',revision='a',csrf='b',validation={'errors':[]},devices=[{'name':'enp3s0','mac':'02:01:02:03:04:05','state':'up'},{'name':'enp4s0','mac':'02:01:02:03:04:06','state':'up'}],backups=[],path='/usr/local/etc/mars_nwe/nwserv.conf',services=True)
|
||||
state['groups']['4']=['0x101 enp3s0 802.3 1','0x102 enp3s0 802.2 1']
|
||||
gw=dict(enabled=False,network='0x101',gateway='10.250.0.1',dns='1.1.1.1',uplink='',web=True,ping=True,clients=[])
|
||||
rev='r1'; actions=[]
|
||||
def fixture(source,path,body):
|
||||
global gw,rev
|
||||
if path=='/api/state':return state
|
||||
if path=='/api/status':return {'mars-nwe-pcap.service':'ActiveState=active','mars-pcapd.service':'ActiveState=active'}
|
||||
if path=='/api/gateway':
|
||||
if body:
|
||||
assert body['revision']==rev and body['confirm'];gw=body['config'];rev='r2';actions.append('save');return {'ok':True}
|
||||
return {'config':gw,'revision':rev,'status':'Disabled (simulierte API)'}
|
||||
if path=='/api/service':assert body['action']=='restart' and body['revision']=='a';actions.append('restart');return {'ok':True}
|
||||
raise AssertionError(path)
|
||||
with sync_playwright() as p:
|
||||
b=p.chromium.launch(executable_path='/usr/bin/chromium',args=['--no-sandbox']);page=b.new_page(viewport={'width':1280,'height':1050});errors=[];page.on('pageerror',lambda e:errors.append(str(e)));page.on('dialog',lambda d:d.accept());page.expose_binding('fixture',fixture);page.evaluate("window.fetch=async(path,opts)=>({ok:true,status:200,json:()=>window.fixture(path,opts?.body?JSON.parse(opts.body):null)})")
|
||||
html=(root/'index.html').read_text().replace('<link rel="stylesheet" href="/style.css">','<style>'+(root/'style.css').read_text()+'</style>').replace('<script src="/app.js" defer></script>','');page.set_content(html);page.add_script_tag(content=(root/'app.js').read_text());page.wait_for_function("document.getElementById('serverStatus').textContent==='active'")
|
||||
page.locator('#gatewayOpen').click();page.locator('#gwEnabled').check();page.locator('#gwNetwork').select_option('0x102');page.locator('#gwUplink').select_option('enp4s0');page.locator('#gwClients').fill('02:01:02:03:04:07 10.250.0.10');page.locator('#gwRestart').click();page.wait_for_function("document.getElementById('gwMessage').textContent.includes('zuerst speichern')");assert not actions
|
||||
page.locator('#gatewayForm button[type=submit]').click();page.wait_for_function("document.getElementById('gwMessage').textContent.includes('Gespeichert')");assert gw['enabled'] and gw['network']=='0x102' and gw['clients']==[{'mac':'020102030407','ip':'10.250.0.10'}] and gw['uplink']=='enp4s0'
|
||||
page.locator('#gwRestart').click();page.wait_for_function("document.getElementById('gwMessage').textContent.includes('Neustart angefordert')");assert actions==['save','restart'];page.locator('#gwRefresh').click();page.wait_for_function("!document.getElementById('gwRefresh').disabled");page.locator('#gatewayDialog').evaluate('(el)=>el.scrollTop=0');page.screenshot(path=str(screen));page.locator('#gatewayClose').click();assert not errors,errors;print('PASS: mock API Chromium Gateway modal, discovered interface selection, MAC/IP entries, save, dirty guard, restart, status');b.close()
|
||||
13
tests/test_legacy.c
Normal file
13
tests/test_legacy.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "legacy_core.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
static struct legacy_core c;
|
||||
int main(void){unsigned char mac[6]={2,1,2,3,4,5},f[MARS_FRAME_MAX]={0},out[MARS_FRAME_MAX];unsigned i;
|
||||
assert(lc_valid_mac(mac));lc_init(&c,mac);memcpy(f+6,mac,6);f[12]=8;f[13]=6;
|
||||
assert(lc_send(&c,f,60)<0);lc_link(&c,1);assert(!lc_send(&c,f,60));assert(lc_pop(&c,out,60)==60&&!memcmp(f,out,60));assert(lc_pop(&c,out,sizeof out)==0);
|
||||
for(i=0;i<MARS_RING_SIZE;i++){assert(!lc_send(&c,f,60));}assert(lc_send(&c,f,60)<0);assert(lc_pop(&c,out,59)<0);for(i=0;i<MARS_RING_SIZE;i++)assert(lc_pop(&c,out,sizeof out)==60);
|
||||
memset(f,255,6);assert(!lc_push(&c,f,60)&&lc_rx(&c,out,sizeof out)==0);c.filter=MF_BROADCAST;assert(!lc_push(&c,f,60)&&lc_rx(&c,out,sizeof out)==60);assert(!memcmp(f,out,60));
|
||||
memcpy(f,mac,6);assert(!lc_push(&c,f,60)&&lc_rx(&c,out,sizeof out)==0);c.filter=MF_DIRECTED;assert(!lc_push(&c,f,60)&&lc_rx(&c,out,sizeof out)==60);assert(lc_push(&c,f,1515)<0);assert(lc_push(&c,f,13)<0);f[12]=0x86;assert(lc_push(&c,f,60)<0);f[12]=8;
|
||||
assert(!lc_send(&c,f,60));assert(!lc_push(&c,f,60));for(i=0;i<MARS_LEASE_TICKS;i++)lc_tick(&c);assert(!c.lease&&!c.tx.count&&!c.rx.count);assert(lc_pop(&c,out,sizeof out)<0);lc_link(&c,1);assert(lc_pop(&c,out,sizeof out)==0);
|
||||
puts("legacy core: queue, MAC, packet filter, invalid frames, lease expiry passed");return 0;}
|
||||
34
tests/test_publish_winclient.sh
Executable file
34
tests/test_publish_winclient.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
[[ $EUID == 0 ]] || { echo 'SKIP: publisher requires root'; exit 0; }
|
||||
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
|
||||
export MARS_CONF=$t/nwserv.conf MARS_GATEWAY_CONFIG=$t/ipxpkt.json MARS_IPX_INTERFACES=$t/interfaces
|
||||
mkdir -p "$t/sys/public"
|
||||
printf '1 SYS %s/sys\n' "$t" > "$MARS_CONF"
|
||||
printf '%s\n' '{"enabled":true,"network":"0x101","gateway":"10.250.0.1"}' > "$MARS_GATEWAY_CONFIG"
|
||||
printf '%s\n' 'Network Node_Address Primary Device Frame_Type' '00000101 020908070605 No eth0 802.2' > "$MARS_IPX_INTERFACES"
|
||||
./publish-winclient.sh --config-only
|
||||
for os in win95 win98 winme winnt40 win2000 winxp; do
|
||||
f=$t/sys/public/clients/$os/gateway.ini
|
||||
test -f "$f"; tr -d '\r' < "$f" | grep -qx 'network=00000101'; tr -d '\r' < "$f" | grep -qx 'server=020908070605'; tr -d '\r' < "$f" | grep -qx 'ip=10.250.0.1'
|
||||
done
|
||||
if ./publish-winclient.sh --config-only; then echo 'FAIL overwrite'; exit 1; fi
|
||||
rm -r "$t/sys/public/clients"
|
||||
mkdir "$t/binaries"; echo NOT-EXE > "$t/binaries/MARSNET.EXE"
|
||||
if ./publish-winclient.sh "$t/binaries"; then echo 'FAIL invalid EXE'; exit 1; fi
|
||||
[[ ! -e $t/sys/public/clients ]]
|
||||
# Test fixture only; the MZ check is a format sanity check, NOT code authentication.
|
||||
printf MZfixture > "$t/binaries/MARSNET.EXE"
|
||||
printf MZfixture > "$t/binaries/MARSIPX.EXE"
|
||||
if ./publish-winclient.sh "$t/binaries"; then echo 'FAIL incomplete native package'; exit 1; fi
|
||||
printf MZfixture > "$t/binaries/MARSNDIS.SYS"; printf 'fixture\n' > "$t/binaries/MARSNDIS.INF"
|
||||
./publish-winclient.sh "$t/binaries"
|
||||
[[ -f $t/sys/public/clients/winxp/marsndis.sys && -f $t/sys/public/clients/win95/marsnet.exe && ! -e $t/sys/public/clients/win95/marsndis.sys ]]
|
||||
echo 'PASS: publisher network config, six folders, no overwrite, reject invalid/incomplete input, target selection (fixtures only)'
|
||||
rm -r "$t/sys/public/clients"
|
||||
mkdir "$t/legacy"; printf MZfixture > "$t/legacy/MARSNET.EXE"; printf MZfixture > "$t/legacy/MARSNET3.SYS"; printf 'fixture\n' > "$t/legacy/MARSNET.INF"
|
||||
if ./publish-winclient.sh "$t/legacy"; then echo 'FAIL preview gate'; exit 1; fi
|
||||
MARS_ALLOW_PREVIEW=1 ./publish-winclient.sh "$t/legacy"
|
||||
[[ -f $t/sys/public/clients/win95/marsnet3.sys && -f $t/sys/public/clients/winme/marsnet.inf && ! -e $t/sys/public/clients/winnt40/marsnet3.sys && ! -e $t/sys/public/clients/winxp/marsnet.exe ]]
|
||||
echo 'PASS: legacy preview gate and Win9x target routing'
|
||||
@@ -18,12 +18,17 @@ cat > "$cfg" <<'CONF'
|
||||
99 PRESERVE
|
||||
CONF
|
||||
chmod 600 "$cfg"
|
||||
start(){ ./build/mars_vme --config "$cfg" --www "$PWD/websetup" --bind 127.0.0.1 --port "$port" --no-services >"$d/log" 2>&1 & pid=$!; for i in $(seq 1 70); do if curl -fsS "$base/login" >/dev/null 2>&1 && kill -0 "$pid"; then return; fi; sleep .1; done; cat "$d/log" >&2; return 1; }
|
||||
mkdir -p "$d/www/drivers"
|
||||
cp websetup/* "$d/www/"
|
||||
printf 'ZIP fixture bytes' > "$d/www/drivers/WIN95.zip"
|
||||
printf '{"platforms":["WIN95"],"map":"test"}' > "$d/www/drivers/enabled.json"
|
||||
start(){ ./build/mars_vme --config "$cfg" --www "$d/www" --bind 127.0.0.1 --port "$port" --no-services >"$d/log" 2>&1 & pid=$!; for i in $(seq 1 70); do if curl -fsS "$base/login" >/dev/null 2>&1 && kill -0 "$pid"; then return; fi; sleep .1; done; cat "$d/log" >&2; return 1; }
|
||||
get(){ curl -fsS -b "$d/cookie" "$base/$1"; }
|
||||
post(){ curl -fsS -b "$d/cookie" -c "$d/cookie" -H "Origin: $base" -H 'Content-Type: application/json' -H "X-Mars-CSRF: ${csrf:-}" -d "$2" "$base/$1"; }
|
||||
status(){ curl -sS -o "$d/response" -w '%{http_code}' "$@"; }
|
||||
start
|
||||
[[ $(status "$base/api/state") == 401 ]]
|
||||
[[ $(status "$base/drivers/WIN95.zip") == 401 ]]
|
||||
[[ $(status -H 'Host: evil.example' "$base/login") == 403 ]]
|
||||
[[ $(status -H 'Content-Type: application/json' -d '{"user":"admin","password":"admin"}' "$base/api/login") == 403 ]]
|
||||
post api/login '{"user":"admin","password":"admin"}' | jq -e .ok >/dev/null
|
||||
@@ -34,6 +39,10 @@ post api/password '{"current":"admin","new":"NativeTestPassword123","repeat":"Na
|
||||
[[ $(status -b "$d/old-cookie" "$base/api/state") == 401 ]]
|
||||
post api/login '{"user":"admin","password":"NativeTestPassword123"}' | jq -e .ok >/dev/null
|
||||
s=$(get api/state); jq -e '(.defaultPassword|not) and (.text|contains("99 PRESERVE"))' <<<"$s" >/dev/null
|
||||
get drivers/WIN95.zip > "$d/download.zip"
|
||||
cmp "$d/download.zip" "$d/www/drivers/WIN95.zip"
|
||||
[[ $(status -b "$d/cookie" "$base/drivers/WINXP.zip") == 404 ]]
|
||||
get api/drivers | jq -e '.platforms==["WIN95"]' >/dev/null
|
||||
csrf=$(jq -r .csrf <<<"$s"); rev=$(jq -r .revision <<<"$s"); dev=$(jq -r '.devices[0].name // empty' <<<"$s")
|
||||
if [[ -n $dev ]]; then
|
||||
request=$(jq -nc --arg rev "$rev" --arg dev "$dev" '{revision:$rev,mode:"guided",groups:{"2":["NEW"],"4":[("0x101 "+$dev+" 802.3 1")]}}')
|
||||
|
||||
16
tests/test_winclient.c
Normal file
16
tests/test_winclient.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "client_core.h"
|
||||
#include "frame_queue.h"
|
||||
#include "gateway.h"
|
||||
#include <assert.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
struct pieces {uint8_t p[3][546];size_t len[3];int count;};
|
||||
static int emit(void*v,const uint8_t*p,size_t n){struct pieces*q=v;assert(q->count<3&&n<=546);memcpy(q->p[q->count],p,n);q->len[q->count++]=n;return 0;}
|
||||
static const uint8_t node[]={2,1,2,3,4,5},server[]={2,9,8,7,6,5};
|
||||
static void test(uint16_t port){struct client_core c;struct pkt_rx r={0};struct pieces p={0};uint8_t f[1514]={0},out[1514],gw[]={10,250,0,1};int rc=0;assert(!client_init(&c,0x101,node,server,port));client_probe(&c,gw,f);assert(!client_tx(&c,f,60,emit,&p));assert(pkt_receive(&r,0x101,node,port,p.p[0],p.len[0],1,out)==60&&!memcmp(f,out,60));
|
||||
memcpy(f,server,6);memcpy(f+6,node,6);f[12]=8;f[13]=0;f[14]=0x45;put16(f+16,1500);p.count=0;assert(!client_tx(&c,f,1514,emit,&p)&&p.count==3);for(int i=2;i>=0;i--)rc=pkt_receive(&r,0x101,node,port,p.p[i],p.len[i],2,out);assert(rc==1514&&!memcmp(f,out,1514));f[6]^=1;assert(client_tx(&c,f,1514,emit,&p)<0);f[6]^=1;f[12]=0x86;assert(client_tx(&c,f,1514,emit,&p)<0);
|
||||
f[12]=8;memcpy(f,node,6);memcpy(f+6,server,6);p.count=0;assert(!pkt_send(port,77,f,1514,emit,&p));assert(client_rx(&c,0x102,server,port,p.p[0],p.len[0],3,out)<0);assert(client_rx(&c,0x101,node,port,p.p[0],p.len[0],3,out)<0);assert(client_rx(&c,0x101,server,port==PKT_PLAIN?PKT_TRAIL:PKT_PLAIN,p.p[0],p.len[0],3,out)<0);for(int i=2;i>=0;i--)rc=client_rx(&c,0x101,server,port,p.p[i],p.len[i],4,out);assert(rc==1514&&!memcmp(f,out,1514));assert(client_rx(&c,0x101,server,port,p.p[0],p.len[0],5,out)==0);assert(client_rx(&c,0x101,server,port,p.p[1],p.len[1],9,out)==0);assert(client_rx(&c,0x101,server,port,p.p[2],p.len[2],9,out)==0);
|
||||
struct gw_config cfg={0};struct gw_peer peer={0};cfg.ip=inet_addr("10.250.0.1");cfg.dns=inet_addr("1.1.1.1");peer.ip=inet_addr("10.250.0.10");memcpy(peer.mac,node,6);
|
||||
for(int type=1;type<=3;type+=2){memset(f,0,sizeof f);memset(f,255,6);memcpy(f+6,node,6);put16(f+12,0x800);f[14]=0x45;f[23]=17;memset(f+30,255,4);put16(f+34,68);put16(f+36,67);uint8_t*b=f+42,*o=b+240;b[0]=1;b[1]=1;b[2]=6;put32(b+4,123456);memcpy(b+28,node,6);put32(b+236,0x63825363);*o++=53;*o++=1;*o++=type;if(type==3){*o++=50;*o++=4;memcpy(o,&peer.ip,4);o+=4;*o++=54;*o++=4;memcpy(o,&cfg.ip,4);o+=4;}*o++=255;unsigned n=o-b;put16(f+16,n+28);put16(f+38,n+8);p.count=0;assert(!client_tx(&c,f,n+42,emit,&p));rc=pkt_receive(&r,0x101,node,port,p.p[0],p.len[0],10,out);assert(rc==(int)n+42);rc=gw_dhcp(&cfg,&peer,server,out,rc,f);assert(rc==342);p.count=0;assert(!pkt_send(port,90+type,f,rc,emit,&p));assert(client_rx(&c,0x101,server,port,p.p[0],p.len[0],11,out)==342);assert(out[284]==(type==1?2:5)&&!memcmp(out+58,&peer.ip,4));}}
|
||||
static void queue(void){static struct mars_ring r;uint8_t f[1514]={0},out[1514];assert(!mars_ring_pop(&r,out,sizeof out));for(int i=0;i<64;i++){f[0]=i;assert(!mars_ring_push(&r,f,sizeof f));}assert(mars_ring_push(&r,f,60)<0&&mars_ring_pop(&r,out,20)<0);for(int i=0;i<32;i++)assert(mars_ring_pop(&r,out,sizeof out)==1514&&out[0]==i);for(int i=0;i<32;i++){f[0]=i+64;assert(!mars_ring_push(&r,f,60));}for(int i=32;i<96;i++)assert(mars_ring_pop(&r,out,sizeof out)==(i<64?1514:60)&&out[0]==i);mars_ring_clear(&r);assert(!r.count&&!r.head);}
|
||||
int main(void){test(PKT_PLAIN);test(PKT_TRAIL);queue();puts("PASS: Windows client core + actual server codec/DHCP; peer validation, fragments, queue");}
|
||||
Reference in New Issue
Block a user