Files
inbraille/scripts/smoke-imagem.sh
T
Lucas RayanandClaude Sonnet 5.5 a9aec5abe4
Release / Plano (reaproveitar a imagem?) (push) Successful in 8s
CI / Trivy (dependências, segredos e configuração) (push) Failing after 8s
Release / ci (push) Failing after 9s
CI / Testes e imagem Docker (linux/arm64) (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Skipped
Release / Cria a release no Gitea (push) Skipped
Recover InBraille from the production image (1.3.1) and move it to Gitea
The GitHub account was suspended and the repository had no backup. The deployed code
(src/, public/, index.html, main.py, requirements.txt) was extracted from the production
image 1.3.1. The tests, Dockerfile, compose files, SECURITY.md, CHANGELOG.md and README were
rebuilt from the records of the work sessions that created them; LICENSE, .gitignore,
robots.txt and sitemap.xml were recreated. CI now runs on Gitea Actions.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 00:15:01 -03:00

77 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Teste de fumaça da imagem do InBraille, do jeito que ela roda em produção
# (--read-only, sem capabilities, usuário sem privilégios): as páginas e os arquivos de
# SEO respondem, a API codifica, decodifica e GERA um STL de verdade (VTK e as bibliotecas
# gráficas da imagem), os cabeçalhos de segurança estão lá e nada interno vaza.
#
# scripts/smoke-imagem.sh <imagem>
#
# Cada falha é impressa e o script sai com 1 no fim, para mostrar tudo de uma vez.
set -uo pipefail
imagem=${1:?uso: smoke-imagem.sh <imagem>}
app=inbraille-smoke-${GITHUB_RUN_ID:-$$}
falhas=0
falhou() { echo "FALHOU $1"; falhas=$((falhas + 1)); }
# Os daemons dos runners persistem entre jobs: limpa sempre, inclusive se falhar.
trap 'docker rm -f "$app" >/dev/null 2>&1' EXIT
docker run -d --name "$app" --read-only --tmpfs /tmp --cap-drop ALL \
--security-opt no-new-privileges:true "$imagem" >/dev/null || exit 1
ip=""
for _ in $(seq 1 40); do
ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$app" 2>/dev/null)
[ -n "$ip" ] && curl -fsS -o /dev/null "http://$ip:3000/" 2>/dev/null && break
sleep 1
done
base=http://$ip:3000
curl -fsS -o /dev/null "$base/" || { echo "FALHOU /: sem resposta"; docker logs "$app" | tail -20; exit 1; }
status() { [ "$(curl -s -o /dev/null -w '%{http_code}' "$base$2")" = "$1" ] || falhou "$2: esperado $1"; }
# Páginas (a mesma index.html atende os três idiomas) e arquivos de SEO.
status 200 /
status 200 /en
status 200 /zh
status 200 /robots.txt
status 200 /sitemap.xml
status 200 /google21a790a2c23c0ec5.html
status 200 /public/index.js
curl -s "$base/sitemap.xml" | python3 -c 'import sys,xml.dom.minidom as m; m.parseString(sys.stdin.read())' 2>/dev/null || falhou "/sitemap.xml: XML inválido"
curl -s "$base/robots.txt" | grep -qi '^sitemap:' || falhou "/robots.txt: sem a linha Sitemap"
# Nada interno vaza, e a documentação interativa da API fica desligada.
for p in /docs /openapi.json /main.py /src/config.py /public/../main.py /Dockerfile; do status 404 "$p"; done
# API: ida e volta do texto, e um STL pequeno de verdade.
enc=$(curl -s -X POST "$base/api/encode" -H 'Content-Type: application/json' -d '{"text":"ola","alphabet":"Brazilian"}')
printf %s "$enc" | grep -q '⠕' || falhou "/api/encode: resposta sem Braille ($enc)"
stl=$(mktemp); trap 'rm -f "$stl"; docker rm -f "$app" >/dev/null 2>&1' EXIT
code=$(curl -s -o "$stl" -w '%{http_code}' -X POST "$base/api/to-stl" -H 'Content-Type: application/json' -d '{"braille":"⠓⠑⠇⠇⠕","resolution":15}')
[ "$code" = 200 ] || falhou "/api/to-stl: esperado 200, veio $code"
# STL binário: 80 bytes de cabeçalho + 4 de contagem de triângulos + 50 bytes por triângulo.
python3 - "$stl" <<'PY' || falhou "/api/to-stl: o STL gerado é inválido"
import struct,sys,os
b=open(sys.argv[1],'rb').read()
n=struct.unpack('<I',b[80:84])[0]
sys.exit(0 if n>0 and len(b)==84+50*n else 1)
PY
# Limites: corpo grande demais é recusado.
[ "$(head -c 70000 /dev/zero | curl -s -o /dev/null -w '%{http_code}' -X POST "$base/api/encode" --data-binary @-)" = 413 ] || falhou "/api/encode: corpo de 70 KB deveria dar 413"
# Cabeçalhos de segurança.
head=$(curl -sI "$base/")
grep -qi "^content-security-policy:.*frame-ancestors 'none'" <<< "$head" || falhou "/: CSP sem frame-ancestors"
grep -qi '^x-content-type-options: nosniff' <<< "$head" || falhou "/: sem X-Content-Type-Options"
grep -qi '^x-frame-options: DENY' <<< "$head" || falhou "/: sem X-Frame-Options"
grep -qi '^cache-control: .*no-cache' <<< "$head" || falhou "/: sem Cache-Control no-cache (as páginas precisam revalidar)"
# Roda sem privilégios.
[ "$(docker exec "$app" id -u)" = 10001 ] || falhou "o processo não roda como o usuário 10001"
[ "$falhas" = 0 ] && echo "ok: páginas, SEO, API (incl. STL), cabeçalhos e isolamento conferidos"
[ "$falhas" = 0 ]