107 lines
4.5 KiB
Bash
Executable File
107 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
dhv2_base_url="${DHV2_BASE_URL:-https://dhv2.korexlabs.com}"
|
|
dhv2_base_url="${dhv2_base_url%/}"
|
|
|
|
fail() {
|
|
echo "ERROR: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "========== B3 · MIGRACIONES =========="
|
|
dhv2_migration_status="$(docker compose --profile tools run --rm migrate npm run migration:show 2>&1)"
|
|
grep -q 'Pending migrations: no' <<<"$dhv2_migration_status" \
|
|
|| fail "Quedaron migraciones pendientes"
|
|
echo "Migraciones pendientes: no"
|
|
|
|
echo
|
|
echo "========== B3 · HEALTH =========="
|
|
dhv2_internal="$(curl -fsS --connect-timeout 10 --max-time 30 http://127.0.0.1:3101/api/v3/health)"
|
|
dhv2_external="$(curl -fsS --connect-timeout 10 --max-time 30 "$dhv2_base_url/api/v3/health")"
|
|
grep -q '"version":"0.10.0"' <<<"$dhv2_internal" || fail "Health interno no informa v0.10.0"
|
|
grep -q '"phase":"B3"' <<<"$dhv2_internal" || fail "Health interno no informa B3"
|
|
grep -q '"version":"0.10.0"' <<<"$dhv2_external" || fail "Health externo no informa v0.10.0"
|
|
grep -q '"database":"ok"' <<<"$dhv2_external" || fail "La base no está saludable"
|
|
echo "$dhv2_external"
|
|
|
|
echo
|
|
echo "========== B3 · RUTAS PROTEGIDAS =========="
|
|
for dhv2_path in asset-versions assets; do
|
|
dhv2_code="$(curl -sS --connect-timeout 10 --max-time 30 \
|
|
-o /tmp/dhv2-b3-response.json -w '%{http_code}' \
|
|
"$dhv2_base_url/api/v3/$dhv2_path")"
|
|
test "$dhv2_code" = "401" || fail "/api/v3/$dhv2_path devolvió HTTP $dhv2_code; se esperaba 401"
|
|
echo "/api/v3/$dhv2_path sin sesión: 401 OK"
|
|
done
|
|
rm -f /tmp/dhv2-b3-response.json
|
|
|
|
echo
|
|
echo "========== B3 · VERSIONADO Y PERMISOS =========="
|
|
dhv2_db_check="$(docker compose exec -T db sh -lc \
|
|
'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v ON_ERROR_STOP=1 -v app_user="$APP_DB_USER" -At' <<'SQL'
|
|
SELECT 'versions_table', COUNT(*)
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public'
|
|
AND table_name = 'asset_versions';
|
|
|
|
SELECT 'current_version_column', COUNT(*)
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'public'
|
|
AND table_name = 'assets'
|
|
AND column_name = 'current_version';
|
|
|
|
SELECT 'history_index', COUNT(*)
|
|
FROM pg_indexes
|
|
WHERE schemaname = 'public'
|
|
AND tablename = 'asset_versions'
|
|
AND indexname = 'idx_asset_versions_asset_number';
|
|
|
|
SELECT 'backfill_mismatches', COUNT(*)
|
|
FROM assets asset
|
|
WHERE asset.current_version < 1
|
|
OR NOT EXISTS (
|
|
SELECT 1 FROM asset_versions version
|
|
WHERE version.asset_id = asset.id
|
|
AND version.version_number = asset.current_version
|
|
);
|
|
|
|
SELECT 'permission', COUNT(*)
|
|
FROM permissions
|
|
WHERE code = 'assets.read_history';
|
|
|
|
SELECT 'role_permissions', COUNT(*)
|
|
FROM role_permissions role_permission
|
|
INNER JOIN roles role ON role.id = role_permission.role_id
|
|
INNER JOIN permissions permission ON permission.id = role_permission.permission_id
|
|
WHERE role.code IN ('admin', 'director', 'supervisor', 'inspector', 'auditor')
|
|
AND permission.code = 'assets.read_history';
|
|
|
|
SELECT 'app_select', has_table_privilege(:'app_user', 'asset_versions', 'SELECT');
|
|
SELECT 'app_insert', has_table_privilege(:'app_user', 'asset_versions', 'INSERT');
|
|
SELECT 'app_update', has_table_privilege(:'app_user', 'asset_versions', 'UPDATE');
|
|
SELECT 'app_delete', has_table_privilege(:'app_user', 'asset_versions', 'DELETE');
|
|
SQL
|
|
)"
|
|
grep -q 'versions_table|1' <<<"$dhv2_db_check" || fail "No se creó asset_versions"
|
|
grep -q 'current_version_column|1' <<<"$dhv2_db_check" || fail "assets no tiene current_version"
|
|
grep -q 'history_index|1' <<<"$dhv2_db_check" || fail "No se encontró el índice temporal"
|
|
grep -q 'backfill_mismatches|0' <<<"$dhv2_db_check" || fail "Hay activos sin versión vigente"
|
|
grep -q 'permission|1' <<<"$dhv2_db_check" || fail "No se creó assets.read_history"
|
|
grep -q 'role_permissions|5' <<<"$dhv2_db_check" || fail "Los cinco roles base no recibieron lectura histórica"
|
|
grep -q 'app_select|t' <<<"$dhv2_db_check" || fail "La API no puede consultar versiones"
|
|
grep -q 'app_insert|t' <<<"$dhv2_db_check" || fail "La API no puede crear versiones"
|
|
grep -q 'app_update|f' <<<"$dhv2_db_check" || fail "La API no debe poder modificar versiones"
|
|
grep -q 'app_delete|f' <<<"$dhv2_db_check" || fail "La API no debe poder borrar versiones"
|
|
echo "$dhv2_db_check"
|
|
|
|
echo
|
|
echo "========== B3 · FRONTEND =========="
|
|
docker compose exec -T web sh -lc \
|
|
'grep -R "0.10.0" /usr/share/nginx/html/assets >/dev/null && grep -R "Historial y versiones de activos" /usr/share/nginx/html/assets >/dev/null && grep -R "Historial de activos" /usr/share/nginx/html/assets >/dev/null && grep -R "Snapshot técnico exacto" /usr/share/nginx/html/assets >/dev/null'
|
|
echo "Historial y footer v0.10.0: OK"
|
|
|
|
echo
|
|
echo "ACEPTACIÓN DE FASE B3: OK"
|