formatted project by python-black

This commit is contained in:
2026-11-10 09:52:42 +03:00
parent 7cd02da51d
commit 9899ee4676
66 changed files with 2517 additions and 944 deletions
+61 -30
View File
@@ -7,7 +7,7 @@ import time
from scripts.deployment import ComposeProject
from tests.client import Client, arguments, check, run
PROBE = r'''
PROBE = r"""
import asyncio, json, sys
from pathlib import Path
from uuid import UUID
@@ -62,60 +62,91 @@ async def main():
await storage.aclose()
await engine.dispose()
asyncio.run(main())
'''
"""
def main():
def configure(parser):
parser.add_argument('--with-outage', action='store_true', help='временно остановить MinIO выбранного проекта')
args = arguments('MinIO private bucket and failure checks', configure)
parser.add_argument(
"--with-outage",
action="store_true",
help="временно остановить MinIO выбранного проекта",
)
args = arguments("MinIO private bucket and failure checks", configure)
project = ComposeProject()
client = Client(args.base_url, args.ca_file, timeout=40)
alice, _, _, chat = client.bootstrap()
aliases = {replica.instance_id for replica in project.replicas() if replica.running}
live = client.call('GET', '/health/live', schema='Health')
check(live['headers'].get('X-Instance-Id') in aliases, 'BASE_URL does not belong to the selected Compose project')
live = client.call("GET", "/health/live", schema="Health")
check(
live["headers"].get("X-Instance-Id") in aliases,
"BASE_URL does not belong to the selected Compose project",
)
attachment, original = client.attachment(alice, chat)
attachment = client.wait_ready(alice, attachment)
# Повторный bootstrap не должен очистить bucket или сменить используемые credentials.
for _ in range(2):
project.run('run', '--rm', '--no-deps', 'minio-bootstrap', timeout=100)
project.run("run", "--rm", "--no-deps", "minio-bootstrap", timeout=100)
replicas = project.replicas()
check(bool(replicas), 'API not running')
result = subprocess.run(['docker', 'exec', '-i', replicas[0].id, 'python', '-c', PROBE],
input=json.dumps({'attachment_id': attachment['id']}),
text=True, capture_output=True, timeout=20)
check(result.returncode == 0, 'private bucket probe failed (details hidden)')
check(bool(replicas), "API not running")
result = subprocess.run(
["docker", "exec", "-i", replicas[0].id, "python", "-c", PROBE],
input=json.dumps({"attachment_id": attachment["id"]}),
text=True,
capture_output=True,
timeout=20,
)
check(result.returncode == 0, "private bucket probe failed (details hidden)")
statuses = json.loads(result.stdout)
check(statuses['GET'] == statuses['PUT'] == 403, 'anonymous S3 access allowed')
check(statuses['admin_denied'] and statuses['other_buckets_denied'] and statuses['root_files_absent'], 'API has excessive access')
check(statuses['console_unreachable'], 'console reachable from API network')
check(statuses['temp_originals_absent'], 'API retained temporary originals')
check(not project.config['services']['minio'].get('ports'), 'MinIO publishes host ports')
env = project.config['services']['minio']['environment']
check(env['MINIO_BROWSER'] == 'off', 'browser enabled')
check('127.0.0.1:9001' in project.config['services']['minio']['command'], 'console is not bound to loopback')
path = '/api/v1/attachments/' + attachment['id'] + '/content'
check(client.call('GET', path, actor=alice)['bytes'] == original, 'bootstrap changed original')
check(statuses["GET"] == statuses["PUT"] == 403, "anonymous S3 access allowed")
check(
statuses["admin_denied"]
and statuses["other_buckets_denied"]
and statuses["root_files_absent"],
"API has excessive access",
)
check(statuses["console_unreachable"], "console reachable from API network")
check(statuses["temp_originals_absent"], "API retained temporary originals")
check(
not project.config["services"]["minio"].get("ports"),
"MinIO publishes host ports",
)
env = project.config["services"]["minio"]["environment"]
check(env["MINIO_BROWSER"] == "off", "browser enabled")
check(
"127.0.0.1:9001" in project.config["services"]["minio"]["command"],
"console is not bound to loopback",
)
path = "/api/v1/attachments/" + attachment["id"] + "/content"
check(
client.call("GET", path, actor=alice)["bytes"] == original,
"bootstrap changed original",
)
if args.with_outage:
try:
project.run('stop', 'minio')
client.call('GET', path, expected=503, actor=alice)
project.run("stop", "minio")
client.call("GET", path, expected=503, actor=alice)
finally:
project.run('start', 'minio')
project.run("start", "minio")
deadline = time.monotonic() + 60
while True:
try:
client.call('GET', '/health/ready', schema='Health')
client.call("GET", "/health/ready", schema="Health")
break
except Exception:
if time.monotonic() >= deadline:
raise
time.sleep(0.5)
check(client.call('GET', path, actor=alice)['bytes'] == original, 'original lost after MinIO restart')
print('PASS: idempotent bootstrap, anonymous GET/PUT denied, restricted API credentials, private console'
+ (', MinIO outage/recovery' if args.with_outage else ''))
check(
client.call("GET", path, actor=alice)["bytes"] == original,
"original lost after MinIO restart",
)
print(
"PASS: idempotent bootstrap, anonymous GET/PUT denied, restricted API credentials, private console"
+ (", MinIO outage/recovery" if args.with_outage else "")
)
if __name__ == '__main__':
if __name__ == "__main__":
run(main)