Add scanner API integration, workflow components, execution-bound live images and 3D model viewing. Harden task control, parameters, resource protection and reports, with automated regressions and detailed verification records.
90 lines
4.4 KiB
Python
90 lines
4.4 KiB
Python
"""Verify the running local backend with EMPTY scanner settings; never contact hardware.
|
|
|
|
Requires AM_FREESCAN_VERIFY_USER and AM_FREESCAN_VERIFY_PASSWORD. Credentials and
|
|
tokens are never printed. Does not create business tasks, devices or commands.
|
|
"""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import urllib.error
|
|
import urllib.request
|
|
import uuid
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
BASE = 'http://localhost:48090'
|
|
|
|
|
|
def request(path, body=None, token=None, extra=None):
|
|
headers = {'tenant-id': '1', 'Content-Type': 'application/json'}
|
|
if token:
|
|
headers['Authorization'] = 'Bearer ' + token
|
|
headers.update(extra or {})
|
|
data = None if body is None else json.dumps(body, ensure_ascii=False).encode('utf-8')
|
|
req = urllib.request.Request(BASE + path, data=data, headers=headers)
|
|
try:
|
|
response = urllib.request.urlopen(req, timeout=20)
|
|
except urllib.error.HTTPError as error:
|
|
response = error
|
|
with response:
|
|
return json.load(response)
|
|
|
|
|
|
def main():
|
|
auth = request('/admin-api/system/auth/login', {
|
|
'username': os.environ['AM_FREESCAN_VERIFY_USER'],
|
|
'password': os.environ['AM_FREESCAN_VERIFY_PASSWORD'],
|
|
})
|
|
assert auth['code'] == 0, 'Local login failed'
|
|
token = auth['data']['accessToken']
|
|
prefix = '/admin-api/cmvr/scanner'
|
|
settings = request(prefix + '/configuration', token=token)['data']
|
|
# Stop before ANY operation if an actual scanner might be configured.
|
|
assert settings['configured'] is False and not settings['host'] and settings['port'] is None
|
|
assert settings['credentialConfigured'] is False and not settings['robotId'] and not settings['deviceId']
|
|
assert 'apiKey' not in settings
|
|
assert request(prefix + '/configuration')['code'] == 401
|
|
|
|
source = (ROOT / 'am-backend/yudao-module-cmvr/src/main/java/com/cmvr/scanner/ScannerOperation.java').read_text(encoding='utf-8')
|
|
operations = re.findall(r'^ (\w+)\("(GET|POST)", "([^"]+)"', source, re.M)
|
|
assert len(operations) == 37
|
|
for name, method, path in operations:
|
|
suffix = '/metadata' if path == '/' else path.removeprefix('/api/v1')
|
|
suffix = suffix.replace('{taskId}', 'a' * 32).replace('{fileId}', 'a' * 32)
|
|
result = request(prefix + suffix, {} if method == 'POST' else None, token,
|
|
{'X-Scanner-Command-Key': 'VERIFY-OFFLINE-' + uuid.uuid4().hex})
|
|
assert result.get('scannerCode') == 'not_configured', (name, result.get('code'))
|
|
|
|
checks = [('CONNECT', '{"deviceType":3}', 200),
|
|
('CONNECT', '{"deviceType":3.0}', 400),
|
|
('SCAN_START', '{"planCode":"legacy"}', 400),
|
|
('EXPORT', '{"formats":[]}', 400),
|
|
('EDIT', '{"projectUuid":"p","cloudUuid":"c","pointIds":[9007199254740993],"confirm":true}', 200)]
|
|
for operation, source, code in checks:
|
|
result = request(prefix + '/validate', {'operation': operation, 'requestJson': source}, token)
|
|
assert result['code'] == code, (operation, code, result.get('code'))
|
|
assert request(prefix + '/commands/VERIFY-OFFLINE-NONEXISTENT', token=token).get('data') is None
|
|
page = request('/admin-api/lab/execution/page?pageNo=1&pageSize=1', token=token)
|
|
task_view_checks = 0
|
|
if page.get('data', {}).get('list'):
|
|
execution_id = str(page['data']['list'][0]['id'])
|
|
view = '/admin-api/lab/execution/scanner-view'
|
|
query = '?executionId=' + execution_id
|
|
assert request(view + query)['code'] == 401
|
|
state = request(view + query, token=token)
|
|
assert state['code'] == 0 and state['data']['available'] is False
|
|
assert request(view + '/assets' + query, token=token)['code'] == 0
|
|
assert request(view + '/image' + query, token=token)['code'] != 0
|
|
assert request(view + '/asset/' + 'a' * 32 + query, token=token)['code'] != 0
|
|
assert request(view + '/snapshot-command' + query + '&commandKey=VERIFY-OFFLINE-NONEXISTENT', token=token)['code'] != 0
|
|
assert request(view + '/snapshot' + query, {}, token, {'X-Scanner-Command-Key': 'VERIFY-OFFLINE-NOSNAPSHOT'})['code'] != 0
|
|
task_view_checks = 7
|
|
print(json.dumps({'supplierRoutesChecked': len(operations), 'parameterChecks': len(checks),
|
|
'executionViewChecks': task_view_checks,
|
|
'anonymousDenied': True, 'scannerConfigurationEmpty': True,
|
|
'hardwareRequests': 0, 'businessTasksCreated': 0}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|