40 lines
2.2 KiB
Python
40 lines
2.2 KiB
Python
"""Read-only deployed patient-auth smoke checks; never print credentials or patient data."""
|
|
from pathlib import Path
|
|
import json,sys,urllib.request,urllib.error
|
|
sys.path.insert(0,r'C:\wechat_rpa')
|
|
import backend_client
|
|
folder=Path(r'C:\kefu\deploy\patient-session-20260918')
|
|
settings=json.loads(Path(r'C:\Users\isard\AppData\Local\ZhenYangTangRPA\backend_connection.json').read_text(encoding='utf-8'))
|
|
base=str(settings['server_url']).rstrip('/')
|
|
credential=backend_client._unprotect_secret(settings.get('desktop_token_protected'))
|
|
results=[]
|
|
def check(label,path,method='GET',payload=None,authenticated=False):
|
|
headers={'Accept':'application/json'}
|
|
if authenticated:
|
|
assert credential,'No existing desktop credential available'
|
|
headers['Authorization']='Bearer '+credential
|
|
data=None
|
|
if payload is not None:
|
|
headers['Content-Type']='application/json';data=json.dumps(payload).encode()
|
|
request=urllib.request.Request(base+path,data=data,headers=headers,method=method)
|
|
try:
|
|
with urllib.request.urlopen(request,timeout=15) as response:status=response.status;body=json.load(response)
|
|
except urllib.error.HTTPError as exc:
|
|
status=exc.code
|
|
try:body=json.load(exc)
|
|
except Exception:body={}
|
|
detail=body.get('detail')
|
|
result={'check':label,'http':status,'errorCode':detail.get('code') if isinstance(detail,dict) else None}
|
|
if label=='patient_query':
|
|
if status==409:assert result['errorCode']=='zyt_session_expired'
|
|
elif status==200:assert body.get('items')==[];result['matchedPatients']=0
|
|
else:raise AssertionError('Unexpected patient response status '+str(status))
|
|
elif label=='anonymous_reauthentication':assert status in (401,403)
|
|
elif label in ('health','desktop_session'):assert status==200
|
|
results.append(result)
|
|
check('health','/api/v2/health')
|
|
check('anonymous_reauthentication','/api/v2/desktop/auth/zyt-session',method='POST',payload={'zyt_token':'synthetic_unauthenticated_verification_token'})
|
|
check('desktop_session','/api/v2/desktop/me',authenticated=True)
|
|
check('patient_query','/api/v2/archive/desktop/patients/search?keyword=__codex_no_patient_match_20260918__&page_size=1',authenticated=True)
|
|
(folder/'deployed-http-smoke.json').write_text(json.dumps(results,indent=2),encoding='utf-8')
|
|
print(json.dumps(results)) |