116 lines
5.6 KiB
Bash
Executable File
116 lines
5.6 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 "========== D5.2 · 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 "========== D5.2 · 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.19.2"' <<<"$dhv2_internal" || fail "Health interno no informa v0.19.2"
|
|
grep -q '"phase":"D5.2"' <<<"$dhv2_internal" || fail "Health interno no informa D5.2"
|
|
grep -q '"version":"0.19.2"' <<<"$dhv2_external" || fail "Health externo no informa v0.19.2"
|
|
grep -q '"database":"ok"' <<<"$dhv2_external" || fail "La base no está saludable"
|
|
echo "$dhv2_external"
|
|
|
|
echo
|
|
echo "========== D5.2 · RUTA ADMINISTRATIVA PROTEGIDA =========="
|
|
dhv2_code="$(curl -sS --connect-timeout 10 --max-time 30 \
|
|
-o /tmp/dhv2-d5-2-response.json -w '%{http_code}' \
|
|
"$dhv2_base_url/api/v3/finding-catalog/admin")"
|
|
test "$dhv2_code" = "401" || fail "/api/v3/finding-catalog/admin devolvió HTTP $dhv2_code; se esperaba 401"
|
|
rm -f /tmp/dhv2-d5-2-response.json
|
|
echo "/api/v3/finding-catalog/admin sin sesión: 401 OK"
|
|
|
|
echo
|
|
echo "========== D5.2 · CATÁLOGO Y REVISIONES =========="
|
|
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 'categories_baseline', COUNT(*) >= 19 FROM finding_categories;
|
|
SELECT 'catalog_items_baseline', COUNT(*) >= 170 FROM finding_catalog_items;
|
|
SELECT 'versions_table', COUNT(*)
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public' AND table_name = 'finding_catalog_item_versions';
|
|
|
|
SELECT 'version_rows_match', NOT EXISTS (
|
|
SELECT 1
|
|
FROM finding_catalog_items item
|
|
WHERE NOT EXISTS (
|
|
SELECT 1 FROM finding_catalog_item_versions version
|
|
WHERE version.item_id = item.id AND version.revision = item.revision
|
|
)
|
|
);
|
|
|
|
SELECT 'revision_constraints', COUNT(*)
|
|
FROM information_schema.table_constraints
|
|
WHERE table_schema = 'public'
|
|
AND table_name = 'finding_catalog_item_versions'
|
|
AND constraint_name IN (
|
|
'uq_finding_catalog_item_versions_revision',
|
|
'chk_finding_catalog_item_versions_revision',
|
|
'chk_finding_catalog_item_versions_snapshot',
|
|
'fk_finding_catalog_item_versions_item',
|
|
'fk_finding_catalog_item_versions_actor'
|
|
);
|
|
|
|
SELECT 'catalog_manage_roles', 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', 'supervisor')
|
|
AND permission.code = 'finding_catalog.manage';
|
|
|
|
SELECT 'version_select', has_table_privilege(:'app_user', 'finding_catalog_item_versions', 'SELECT');
|
|
SELECT 'version_insert', has_table_privilege(:'app_user', 'finding_catalog_item_versions', 'INSERT');
|
|
SELECT 'version_update', has_table_privilege(:'app_user', 'finding_catalog_item_versions', 'UPDATE');
|
|
SELECT 'version_delete', has_table_privilege(:'app_user', 'finding_catalog_item_versions', 'DELETE');
|
|
|
|
SELECT 'migration_applied', COUNT(*)
|
|
FROM typeorm_migrations
|
|
WHERE name = 'PhaseD52FindingCatalogAdministration1787335200000';
|
|
SQL
|
|
)"
|
|
grep -q 'categories_baseline|t' <<<"$dhv2_db_check" || fail "Faltan categorías de la línea base"
|
|
grep -q 'catalog_items_baseline|t' <<<"$dhv2_db_check" || fail "Faltan tipos de hallazgo de la línea base"
|
|
grep -q 'versions_table|1' <<<"$dhv2_db_check" || fail "No se creó la tabla de revisiones"
|
|
grep -q 'version_rows_match|t' <<<"$dhv2_db_check" || fail "Hay tipos sin snapshot de su revisión vigente"
|
|
grep -q 'revision_constraints|5' <<<"$dhv2_db_check" || fail "Faltan restricciones de integridad del historial"
|
|
grep -q 'catalog_manage_roles|2' <<<"$dhv2_db_check" || fail "Admin y supervisor no conservan gestión del catálogo"
|
|
grep -q 'version_select|t' <<<"$dhv2_db_check" || fail "La API no puede leer revisiones"
|
|
grep -q 'version_insert|t' <<<"$dhv2_db_check" || fail "La API no puede crear revisiones"
|
|
grep -q 'version_update|f' <<<"$dhv2_db_check" || fail "La API no debe modificar revisiones"
|
|
grep -q 'version_delete|f' <<<"$dhv2_db_check" || fail "La API no debe borrar revisiones"
|
|
grep -q 'migration_applied|1' <<<"$dhv2_db_check" || fail "La migración D5.2 no figura aplicada"
|
|
echo "$dhv2_db_check"
|
|
|
|
echo
|
|
echo "========== D5.2 · API COMPILADA =========="
|
|
docker compose exec -T api sh -lc \
|
|
'grep -R "FindingCatalogController" /app/dist >/dev/null && grep -R "FINDING_CATALOG_ITEM_UPDATED" /app/dist >/dev/null'
|
|
echo "Administración, auditoría y versionado cargados: OK"
|
|
|
|
echo
|
|
echo "========== D5.2 · DASHBOARD =========="
|
|
docker compose exec -T web sh -lc \
|
|
'grep -R "0.19.2" /usr/share/nginx/html/assets >/dev/null && grep -R "Catálogo administrable" /usr/share/nginx/html/assets >/dev/null && grep -R "Catálogo de hallazgos" /usr/share/nginx/html/assets >/dev/null && grep -R "Nueva categoría" /usr/share/nginx/html/assets >/dev/null && grep -R "Nuevo tipo de hallazgo" /usr/share/nginx/html/assets >/dev/null && grep -R "Los cambios crean una nueva revisión" /usr/share/nginx/html/assets >/dev/null'
|
|
echo "Catálogo administrativo y footer v0.19.2: OK"
|
|
|
|
echo
|
|
echo "========== D5.2 · CONTENEDORES =========="
|
|
docker compose ps
|
|
|
|
echo
|
|
echo "ACEPTACIÓN DE FASE D5.2: OK"
|