"""Read-only HTTP integration checks over an existing Windows ADB forward.""" import json, os, subprocess, time, xml.etree.ElementTree as ET ADB=os.environ.get('ADB','/mnt/c/Users/Andrei/AppData/Local/Android/Sdk/platform-tools/adb.exe') SERIAL=os.environ.get('ANDROID_SERIAL','192.168.0.186:5555') CURL='/mnt/c/Windows/System32/curl.exe' PACKAGE=os.environ.get('CONSOLE_PACKAGE','com.iomatex.console') raw=subprocess.check_output([ADB,'-s',SERIAL,'shell','run-as '+PACKAGE+' cat shared_prefs/console.xml']) password=ET.fromstring(raw).find("string[@name='password']").text def request(path, body=None, cookie=None): args=[CURL,'-sS','--max-time','8','-i','http://127.0.0.1:18080'+path] if body is not None: args += ['-H','Content-Type: application/json','--data-binary','@-'] if cookie: args += ['-H','Cookie: '+cookie] data=subprocess.check_output(args,input=json.dumps(body).encode() if body is not None else None).decode() headers,payload=data.replace('\r\n','\n').split('\n\n',1) return int(headers.split()[1]),headers,payload assert request('/api/status')[0]==401 assert request('/api/actions/reboot',{})[0]==401 code,headers,body=request('/api/auth/login',{'username':'iomatex','password':password}) assert code==200 and json.loads(body)['authenticated'] cookie=next(l.split(': ',1)[1].split(';')[0] for l in headers.splitlines() if l.startswith('Set-Cookie:')) for path in ['/api/status','/api/health/summary','/api/health/services','/api/display','/api/system/timezone','/api/network/summary','/api/itscreen/status','/api/itscreen/runtime','/api/itscreen/registration']: code,_,body=request(path,cookie=cookie) assert code==200 and json.loads(body).get('ok',path=='/api/display'), (path,code) if path=='/api/health/summary': health=json.loads(body) for attempt in range(15): if health.get('cpu_usage_percent') is not None: break time.sleep(1) health=json.loads(request(path,cookie=cookie)[2]) assert 0 <= health['cpu_usage_percent'] <= 100 assert len(health['load_average']) == 3 readings=health['temperatures'] assert {'soc-thermal','gpu-thermal'} <= {r['name'] for r in readings} assert all(r['value_c'] is None or -50 <= r['value_c'] <= 150 for r in readings) assert not any(r['name'].startswith('test') for r in readings) if path=='/api/display': display=json.loads(body) assert display['id']=='display' and display['connectors'] assert display['capabilities']=={'desktop_mode':False,'pulse_audio':False} if path=='/api/itscreen/registration': data=json.loads(body) assert 'password' not in data and data['capabilities']['can_reset'] is False if path=='/api/health/services': ids={item['id'] for item in json.loads(body)['services']} assert {'itscreen','display','environment'} <= ids assert not ids & {'modbus','cockpit','zigbee2mqtt'} assert request('/api/system/reboot',{},cookie)[0]==501 assert request('/api/auth/password/change',{'current_password':'invalid','new_password':'temporary123','confirm_password':'temporary123'},cookie)[0]==400 assert request('/api/system/timezone',{'timezone':'Invalid/Zone'},cookie)[0]==400 assert request('/api/network/profile/apply',{'ssid':''},cookie)[0]==400 assert request('/api/stages/check',{},cookie)[0]==200 assert request('/api/itscreen/registration/reset',{},cookie)[0]==501 assert request('/api/itscreen/register',{'host':'https://bad.example/path'},cookie)[0] in (400,409) assert request('/../AndroidManifest.xml')[0]==404 assert request('/api/auth/logout',{},cookie)[0]==200 assert request('/api/status',cookie=cookie)[0]==401 print('PASS: authorization, login, status, health, services, unsupported mutation, asset allowlist, logout/revocation')