Enable long filename configuration and provide read-only DOS compatibility export
This commit is contained in:
23
tests/test_dos_export.py
Normal file
23
tests/test_dos_export.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pathlib import Path
|
||||
import tempfile,subprocess,os,re
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
base=Path(d);src=base/'src';src.mkdir()
|
||||
for name in ['Langer Dateiname mit Umlaut ä.txt','readme.txt','README.TXT','CON','LFNAMES.TXT']:(src/name).write_text(name)
|
||||
(src/'Langer Unterordner').mkdir();(src/'Langer Unterordner'/'Bericht November 2026.pdf').write_bytes(b'pdf')
|
||||
dst=base/'dos';subprocess.run(['python3',str(root/'dos-compat-export.py'),str(src),str(dst)],check=True)
|
||||
originals={f.read_bytes() for f in src.rglob('*') if f.is_file()}
|
||||
copied={f.read_bytes() for f in dst.rglob('*') if f.is_file() and f.name!='LFNAMES.TXT'}
|
||||
assert originals==copied
|
||||
for folder in [dst,*[p for p in dst.rglob('*') if p.is_dir()]]:
|
||||
names=[p.name for p in folder.iterdir()];assert len(names)==len(set(names))
|
||||
assert all(re.fullmatch(r'[A-Z0-9_]{1,8}(\.[A-Z0-9_]{1,3})?',n) for n in names)
|
||||
assert 'CON' not in names
|
||||
assert (folder/'LFNAMES.TXT').exists()
|
||||
assert 'Langer Dateiname mit Umlaut ä.txt' in (dst/'LFNAMES.TXT').read_bytes().decode('cp850')
|
||||
# source links must fail rather than exporting data outside the selected tree
|
||||
(src/'link').symlink_to('/etc/passwd')
|
||||
assert subprocess.run(['python3',str(root/'dos-compat-export.py'),str(src),str(base/'bad')],capture_output=True).returncode!=0
|
||||
for f in dst.rglob('*'):f.chmod(0o755 if f.is_dir() else 0o644)
|
||||
dst.chmod(0o755)
|
||||
print('PASS: DOS aliases, collisions, reserved names, bytes, CP850 catalog, link rejection')
|
||||
@@ -15,6 +15,14 @@ const fs=require('fs'),path=require('path'),assert=require('assert');
|
||||
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.waitForFunction(()=>document.querySelector('#configPath').textContent==='/test');
|
||||
await page.evaluate(()=>show(2));
|
||||
await page.locator('#g1').fill('SYS /srv/sys kt 711 600 # keep rights');
|
||||
await page.locator('#g6').fill('0 0x1');
|
||||
await page.locator('#enableLFN').click();
|
||||
assert.equal(await page.locator('#g1').inputValue(),'SYS /srv/sys tiO 711 600 # keep rights');
|
||||
assert.equal(await page.locator('#g6').inputValue(),'2 0x1');
|
||||
await page.evaluate(()=>{mark(false);show(0)});
|
||||
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);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
int main(void){char tmp[]="/tmp/mars-native-test-XXXXXX";assert(mkdtemp(tmp));snprintf(config_path,sizeof config_path,"%s/nwserv.conf",tmp);snprintf(auth_path,sizeof auth_path,"%s/.mars-web-auth.json",tmp);snprintf(backup_dir,sizeof backup_dir,"%s/.mars-web-backups",tmp);
|
||||
const char*orig="# preserve\r\n2 OLD\r\n99 keep exactly\r\n12 SUPERVISOR root SecretPass\r\n200 0\r\n";assert(!atomic_write(config_path,orig,strlen(orig),0600));json_object*g=groups(orig);assert(!strcmp(json_object_get_string(json_object_array_get_idx(get(g,"2"),0)),"OLD"));char*unchanged=merge(orig,g);assert(unchanged&&!strcmp(unchanged,orig));free(unchanged);json_object_put(g);
|
||||
g=json_tokener_parse("{\"2\":[\"NEW\"],\"13\":[\"TEST nobody TestPass123\"]}");char*next=merge(orig,g);assert(next&&strstr(next,"2 NEW\r\n")&&strstr(next,"99 keep exactly\r\n")&&strstr(next,"13 TEST nobody TestPass123\r\n"));json_object_put(g);g=json_tokener_parse("{\"2\":[\"BAD\\n4 invalid\"]}");assert(!merge(orig,g));json_object_put(g);puts("PASS merge, CRLF, unknown lines, injection rejection");
|
||||
g=json_tokener_parse("{\"6\":[\"2 0x1\"]}");char *lfn=merge("6 0 0x1\n99 keep\n",g);assert(lfn&&strstr(lfn,"6 2 0x1\n")&&strstr(lfn,"99 keep\n"));free(lfn);json_object_put(g);puts("PASS managed LFN server version merge");
|
||||
char h[65],name[64];sha(orig,h);assert(!save_conf(orig,h,next,name));assert(*name);char*b=backup_read(name);assert(b&&!strcmp(b,orig));free(b);g=backups();assert(json_object_array_length(g)==1);json_object_put(g);assert(save_conf(orig,h,"stale",name)==-2);assert(!backup_read("../../etc/shadow"));char*cur=read_file(config_path,MAX_CONF,1);assert(cur&&!strcmp(cur,next));free(cur);free(next);puts("PASS backup, revision conflict, private file, traversal rejection");
|
||||
assert(!auth_init());assert(auth_default());assert(auth_verify("admin"));assert(!auth_verify("wrong"));assert(auth_set("short",0));assert(!auth_set("ChangedPassword123",0));assert(!auth_default());assert(auth_verify("ChangedPassword123"));assert(!auth_verify("admin"));assert(!auth_init());assert(auth_verify("ChangedPassword123"));puts("PASS PBKDF2, default, persistent password, wrong password");
|
||||
g=validate("2 SERVER\n3 0x1 1\n4 0x1 no-such-device 802.3 1\n5 1\n200 1\n1 SYS /\n12 SUPERVISOR not-a-real-user\n");assert(json_object_array_length(get(g,"errors"))>=5);json_object_put(g);g=devices();if(json_object_array_length(g)){const char*dev=js(json_object_array_get_idx(g,0),"name");char*conf=NULL;assert(asprintf(&conf,"2 SERVER\n3 0x1 1\n4 0x2 %s 802.3 1\n5 0\n200 0\n1 SYS /tmp\n12 SUPERVISOR root SecretPass\n",dev)>0);json_object*v=validate(conf);assert(json_object_array_length(get(v,"errors"))==0);json_object_put(v);free(conf);}json_object_put(g);puts("PASS validation invalid configuration and detected Ethernet interface");
|
||||
|
||||
Reference in New Issue
Block a user