feat: complete lab 7 for grade 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
sashadugina06
2026-12-04 13:55:32 +03:00
parent 20afc2c790
commit 11390b65fd
91 changed files with 10163 additions and 50 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/bin/sh
# Use an isolated loopback network and tmpfs storage. No Compose services or volumes.
set -eu
cd "$(dirname "$0")/.."
root=$PWD
app_image=${RECOVERY_TEST_APP_IMAGE:-mtusi2026lab7-app:local}
pg_image=${RECOVERY_TEST_PG_IMAGE:-postgres:16.16-bookworm@sha256:cd0e9518bda5f2ea667ff84d22795d089720c883f288e215d97ce57437e8ef37}
s3_image=bitnamilegacy/minio:2025.7.23-debian-12-r5@sha256:6dabb4a2088c9a79908de3bc05f4586c23ad2182c8908e7e3acbf61c1467fb20
work=$(mktemp -d)
work=$(cd "$work" && pwd -P)
pg=
s3=
cleanup() {
if [ -n "$s3" ]; then docker stop "$s3" >/dev/null 2>&1 || :; fi
if [ -n "$pg" ]; then docker stop "$pg" >/dev/null 2>&1 || :; fi
rm -f "$work"/ca.key "$work"/ca.crt "$work"/ca.srl "$work"/server.csr \
"$work"/server.ext "$work"/certs/private.key "$work"/certs/public.crt
rmdir "$work"/certs "$work"
}
trap cleanup EXIT
mkdir "$work/certs"
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj '/CN=Recovery test CA' \
-addext 'keyUsage=critical,keyCertSign,cRLSign' -keyout "$work/ca.key" -out "$work/ca.crt" >/dev/null 2>&1
openssl req -new -newkey rsa:2048 -nodes -subj '/CN=localhost' \
-keyout "$work/certs/private.key" -out "$work/server.csr" >/dev/null 2>&1
printf '%s\n' 'subjectAltName=IP:127.0.0.1' 'extendedKeyUsage=serverAuth' > "$work/server.ext"
openssl x509 -req -in "$work/server.csr" -CA "$work/ca.crt" -CAkey "$work/ca.key" \
-CAcreateserial -days 1 -extfile "$work/server.ext" -out "$work/certs/public.crt" >/dev/null 2>&1
pg=$(docker run --rm -d --network none --tmpfs /var/lib/postgresql/data \
-e POSTGRES_DB=recovery_test -e POSTGRES_HOST_AUTH_METHOD=trust "$pg_image")
for attempt in $(seq 1 30); do
if docker exec "$pg" pg_isready -h 127.0.0.1 -U postgres -d recovery_test >/dev/null 2>&1; then break; fi
test "$attempt" -lt 30
sleep 1
done
# Scratch MinIO runs as root solely to read the host-owned disposable TLS key.
s3=$(docker run --rm -d --network "container:$pg" --user 0:0 \
--tmpfs /data --tmpfs /certs --tmpfs /bitnami/minio/data \
--mount "type=bind,src=$work,dst=/fixture,readonly" \
--mount "type=bind,src=$root/infra/minio,dst=/policy,readonly" \
-e MINIO_ROOT_USER=fixture-admin -e MINIO_ROOT_PASSWORD=fixture-admin-password \
--entrypoint /opt/bitnami/minio/bin/minio "$s3_image" server /data --certs-dir /fixture/certs)
for attempt in $(seq 1 30); do
if docker exec "$s3" curl -fsS --cacert /fixture/ca.crt https://127.0.0.1:9000/minio/health/ready >/dev/null 2>&1; then break; fi
test "$attempt" -lt 30
sleep 1
done
docker exec "$s3" sh -ec '
export MC_CONFIG_DIR=/tmp/recovery-test-mc
mkdir -p "$MC_CONFIG_DIR/certs/CAs"
cp /fixture/ca.crt "$MC_CONFIG_DIR/certs/CAs/fixture.crt"
mc alias set fixture https://127.0.0.1:9000 fixture-admin fixture-admin-password >/dev/null
mc mb fixture/messenger-attachments >/dev/null
mc admin user add fixture lab-recovery fixture-recovery-password >/dev/null
mc admin policy create fixture lab-recovery /policy/recovery.json >/dev/null
mc admin policy attach fixture lab-recovery --user lab-recovery >/dev/null
'
docker run --rm --network "container:$pg" \
--mount "type=bind,src=$root,dst=/workspace,readonly" \
--mount "type=bind,src=$work/ca.crt,dst=/fixture-ca.crt,readonly" \
-w /workspace -e PYTHONDONTWRITEBYTECODE=1 \
-e 'RECOVERY_TEST_DSN=host=127.0.0.1 dbname=recovery_test user=postgres' \
-e RECOVERY_TEST_S3=https://127.0.0.1:9000 -e RECOVERY_TEST_CA=/fixture-ca.crt \
-e RECOVERY_TEST_ADMIN_USER=fixture-admin -e RECOVERY_TEST_ADMIN_PASSWORD=fixture-admin-password \
-e RECOVERY_TEST_SCOPED_USER=lab-recovery -e RECOVERY_TEST_SCOPED_PASSWORD=fixture-recovery-password \
--entrypoint python "$app_image" -m unittest discover -s student-tests -p 'test_recovery_*.py' -v