39 lines
4.8 KiB
Python
39 lines
4.8 KiB
Python
"""Optional development-only Chromium UI test with mock API. Not a server runtime dependency."""
|
|
from pathlib import Path
|
|
import os
|
|
from playwright.sync_api import sync_playwright
|
|
root=Path(__file__).resolve().parents[1]/'websetup'
|
|
screens=Path(os.environ.get('MARS_SCREENSHOT_DIR',str(root.parent/'build')));screens.mkdir(parents=True,exist_ok=True)
|
|
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=[],backups=[],path='/etc/nwserv.conf',services=True)
|
|
state['groups']['1']=['SYS /var/mars/sys kt 711 600','DATA /var/mars/data kt 711 600']
|
|
scripts={('system',''):'REM existing\r\nMAP ROOT F:=DATA:\r\n',('user','DOSUSER'):'REM personal\r\n'}
|
|
requests=[]
|
|
rights=-1
|
|
def fixture(source,path,body):
|
|
global rights
|
|
requests.append((path,body))
|
|
if path=='/api/state':return state
|
|
if path=='/api/status':return {'mars-nwe-pcap.service':'ActiveState=active','mars-pcapd.service':'ActiveState=active'}
|
|
op=body['op']
|
|
if op=='objects':return {'objects':[{'name':'DOSUSER','type':1,'id':2},{'name':'STAFF','type':2,'id':3}]}
|
|
if op.startswith('script-'):
|
|
key=(body['scope'],body.get('name','') if body['scope']=='user' else '')
|
|
if op=='script-save':
|
|
assert body['previous']==scripts.get(key,'')
|
|
scripts[key]=body['text'].replace('\r\n','\n').replace('\n','\r\n')
|
|
if scripts[key] and not scripts[key].endswith('\r\n'):scripts[key]+='\r\n'
|
|
return dict(text=scripts.get(key,''),exists=key in scripts,path='SYS:PUBLIC/NET$LOG.DAT' if key[0]=='system' else 'SYS:MAIL/2/LOGIN')
|
|
if op.startswith('trustee-'):
|
|
if op=='trustee-set':assert body['previous']==rights;rights=body['mask']
|
|
if op=='trustee-remove':assert body['previous']==rights;rights=-1
|
|
return {'mask':rights}
|
|
raise AssertionError(body)
|
|
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':850});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('.launchpad [data-go="11"]').click();page.wait_for_function("document.getElementById('scriptStatus').textContent.includes('1 Gruppen')")
|
|
page.locator('#scriptScope').select_option('group');page.locator('#scriptTarget').select_option('STAFF');page.locator('#scriptOpen').click();page.locator('#scriptText').wait_for();page.locator('#scriptMap').click();page.locator('[name=drive]').select_option('P');page.locator('[name=volume]').select_option('DATA');page.locator('[name=path]').fill('PROJECTS');page.locator('#actionSubmit').click();page.wait_for_function("!document.getElementById('actionDialog').open");assert 'MAP ROOT P:=DATA:PROJECTS' in page.locator('#scriptText').input_value();page.locator('#scriptSave').click();page.wait_for_function("document.getElementById('scriptInfo').textContent.includes('Gespeichert')");assert 'IF MEMBER OF "STAFF" THEN\r\nMAP ROOT P:=DATA:PROJECTS\r\nEND' in scripts['system',''];assert 'REM existing' in scripts['system',''];
|
|
page.screenshot(path=str(screens/'MARS-NWE-PCAP-0.4-Scripteditor.png'));page.locator('#scriptClose').click();page.locator('#scriptScope').select_option('user');page.locator('#scriptTarget').select_option('DOSUSER');page.locator('#scriptOpen').click();page.locator('#scriptText').fill('MAP ROOT U:=DATA:USER');page.locator('#scriptSave').click();page.wait_for_function("document.getElementById('scriptInfo').textContent.includes('Gespeichert')");assert scripts['user','DOSUSER']=='MAP ROOT U:=DATA:USER\r\n';page.locator('#scriptClose').click();
|
|
page.locator('#aclOpen').click();page.locator('#aclTarget').select_option('2:STAFF');page.locator('#aclPath').fill('PROJECTS');page.locator('#aclLoad').click();page.locator('#aclRead').wait_for();page.locator('#aclRead').click();page.locator('#aclSave').click();page.wait_for_function("document.getElementById('aclError').textContent.includes('Gespeichert')");assert rights==65;page.screenshot(path=str(screens/'MARS-NWE-PCAP-0.4-Freigaben.png'));page.locator('#aclRemove').click();page.wait_for_function("document.getElementById('aclExisting').textContent==='Keine direkte Zuweisung'");assert rights==-1;page.locator('#aclClose').click();
|
|
assert not errors,errors;print('PASS: mock API Chromium group script, mapping helper, preserved global script, personal script, ACL read/set/remove');b.close()
|