Добавить панель системы и временный внешний доступ

This commit is contained in:
Никита
2026-11-10 11:25:50 +03:00
parent 0e0efe5614
commit a81c0bad34
19 changed files with 383 additions and 8 deletions
+14
View File
@@ -0,0 +1,14 @@
import sys,base64,http.client,json
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'tests'))
from client import Client,check
c=Client('http://localhost:18085');actor=c.user('chunked')
registration=actor['registration']
auth='Basic '+base64.b64encode((registration['username']+':'+registration['password']).encode()).decode()
for body,expected in (([],201),([b'x'],400)):
conn=http.client.HTTPConnection('localhost',18085,timeout=10)
conn.request('POST','/api/v1/auth/sessions',body=iter(body),headers={'Authorization':auth,'Transfer-Encoding':'chunked'},encode_chunked=True)
response=conn.getresponse();data=json.loads(response.read());conn.close()
check(response.status==expected,'chunked login status mismatch')
check(('token' in data) if expected==201 else data['error']['code']=='invalid_request','unexpected result')
print('PASS: empty chunked login accepted; nonempty chunked login rejected')
+38
View File
@@ -0,0 +1,38 @@
import base64
from support import *
# The operator session is supplied locally, never stored in evidence.
import os
password=os.environ.get('OPS_TEST_PASSWORD')
if not password:raise SystemExit('Set OPS_TEST_PASSWORD for the configured local operator')
c=Client('http://localhost:18085')
credential=base64.b64encode((os.environ.get('OPS_TEST_USERNAME','n1k0der')+':'+password).encode()).decode()
session=parsed(c,'POST','/api/v1/auth/sessions',201,headers={'Authorization':'Basic '+credential})
owner={'id':session['user']['id'],'token':session['token']}
a,b,e,chat=c.bootstrap()
check(parsed(c,'GET','/api/ui/operator',actor=owner)['enabled'],'operator not enabled')
check(not parsed(c,'GET','/api/ui/operator',actor=a)['enabled'],'regular user promoted')
c.call('GET','/api/ui/operations',401)
c.call('GET','/api/ui/operations',404,actor=a)
snapshot=parsed(c,'GET','/api/ui/operations',actor=owner)
check(all(name in snapshot['counts'] for name in ('queued','processing','ready','failed')),'counts missing')
check(snapshot['services']['postgres'] and snapshot['services']['s3'] and snapshot['services']['broker'],'probes failed')
user=parsed(c,'GET','/api/ui/users/n1k0der',actor=a)
check(user['id']==owner['id'] and 'password_hash' not in user,'lookup unsafe')
c.call('GET','/api/ui/users/n1k0der',401)
attachment=upload(c,a,chat)['json'];ready(c,a,attachment)
path='/api/ui/operations/attachments/'+attachment['id']+'/replay'
c.call('POST',path,404,actor=a);c.call('POST',path,401);c.call('POST',path,409,actor=owner)
# A controlled failed-state fixture retains the original staging bytes for replay.
compose('stop','worker')
try:
attachment=upload(c,a,chat)['json'];id=job_id(attachment)
sql("UPDATE attachment_jobs SET state='failed',error_code='test_fixture' WHERE id='"+id+"'; UPDATE attachments SET status='failed',error_code='test_fixture' WHERE id='"+attachment['id']+"'")
path='/api/ui/operations/attachments/'+attachment['id']+'/replay'
c.call('POST',path,202,actor=owner);c.call('POST',path,409,actor=owner)
check(sql("SELECT replay_count FROM attachment_jobs WHERE id='"+id+"'")=='1','replay duplicated')
finally:compose('up','-d','--no-deps','worker')
def completed():
result=c.call('GET','/api/v1/attachments/'+attachment['id'],[200,503],actor=a,schema='Attachment')
return result['json']['status']=='ready' if result['status']==200 else False
wait(completed)
print('PASS: operator-only metrics and replay; anonymous 401; regular user 404; exact login lookup; one replay completes with real worker')