SPB Git

Repository Public

e2e.sh 5.4 KB 118 lines shellscript

1#!/usr/bin/env bash2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr Identity8# File             : integrations/e2e.sh9# Module           : integrations10# Repository       : https://git.spboucher.ai/maclustr-identity11# Project Website  : https://identity.spboucher.ai12# Created          : 2026-12-0113# Last Modified    : 2026-12-0114#15# Author           : Simon-Pierre Boucher16# Position         : Professor of Finance17# Institution      : Université du Québec en Outaouais (UQO)18# Organization     : SP Boucher19# Website          : https://spboucher.ai20# Git              : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin   : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License          : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# End-to-end proof that two independent applications integrate MacLustr Identity and stay isolated.42#43#   1. makes sure a LOCAL backend answers (starts one, with its webhook dispatcher, when none does);44#   2. provisions one application + sandbox key + webhook per demo (setup.sh);45#   3. boots demo-marketplace (Node, TypeScript SDK) and demo-wallet (FastAPI, Python SDK);46#   4. runs e2e.mjs, which drives full verifications over HTTP (the person is simulated with the sandbox47#      flow endpoints) and asserts gates, webhooks, isolation and fail-closed behaviour.48#49# Everything started here is stopped by PID on exit. Never run against production.50set -euo pipefail51HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"52REPO="$(cd "$HERE/.." && pwd)"53export MLID_BASE_URL="${MLID_BASE_URL:-http://localhost:8870}"54export DATABASE_URL="${DATABASE_URL:-postgres://127.0.0.1/maclustr_identity_sdk}"55export MLID_DATA_DIR="${MLID_DATA_DIR:-/tmp/mlid-sdk/data}"56export MLID_MASTER_KEY_FILE="${MLID_MASTER_KEY_FILE:-/tmp/mlid-sdk/master.key}"57case "$MLID_BASE_URL" in http://localhost:*|http://127.0.0.1:*) ;; *) echo "e2e.sh only targets a local backend" >&2; exit 2 ;; esac5859WORK="$(mktemp -d "${TMPDIR:-/tmp}/mlid-e2e.XXXXXX")"60PIDS=()61cleanup() {62  for pid in "${PIDS[@]:-}"; do [ -n "$pid" ] && kill "$pid" 2>/dev/null || true; done63  if [ "${KEEP_LOGS:-0}" = "1" ]; then echo "logs kept in $WORK"; else rm -rf "$WORK"; fi64}65trap cleanup EXIT6667busy() { lsof -nP -iTCP:"$1" -sTCP:LISTEN -t >/dev/null 2>&1; }68TAKEN=""69pick_port() { # pick_port <variable> <preferred> : first free port at or after the preferred one, not already handed out70  local p="$2"71  while busy "$p" || [[ " $TAKEN " == *" $p "* ]]; do p=$((p + 1)); done72  if [ "$p" != "$2" ]; then echo "note: port $2 is in use, using $p instead"; fi73  TAKEN="$TAKEN $p"; printf -v "$1" '%s' "$p"74}75wait_http() { # wait_http <url> <what>76  for _ in $(seq 1 60); do curl -fsS "$1" >/dev/null 2>&1 && return 0; sleep 0.25; done77  echo "timed out waiting for $2 ($1)" >&2; return 178}7980# 1. Backend81if ! curl -fsS "$MLID_BASE_URL/health" >/dev/null 2>&1; then82  echo "no backend at $MLID_BASE_URL: starting one (API + dispatcher)"83  BPORT="${MLID_BASE_URL##*:}"84  createdb "${DATABASE_URL##*/}" 2>/dev/null || true85  mkdir -p "$MLID_DATA_DIR"86  (cd "$REPO" && MLID_ALLOW_PRIVATE_WEBHOOKS=1 MLID_ORIGIN="$MLID_BASE_URL" exec .venv/bin/python -m uvicorn services.mlid.app:app --port "$BPORT" >"$WORK/backend.log" 2>&1) &87  PIDS+=($!)88  wait_http "$MLID_BASE_URL/health" "the backend"89  (cd "$REPO" && MLID_ALLOW_PRIVATE_WEBHOOKS=1 MLID_ORIGIN="$MLID_BASE_URL" exec .venv/bin/python -m services.mlid.dispatcher >"$WORK/dispatcher.log" 2>&1) &90  PIDS+=($!)91fi9293# 2. Ports and provisioning94pick_port MK_PORT "${MARKETPLACE_PORT:-8881}"; pick_port WL_PORT "${WALLET_PORT:-8882}"95pick_port MK_DOWN_PORT 8891; pick_port WL_DOWN_PORT 889296PORT="$MK_PORT" "$HERE/demo-marketplace/setup.sh"97PORT="$WL_PORT" "$HERE/demo-wallet/setup.sh"9899# 3. The two demo applications, each with a fresh state file100(cd "$HERE/demo-marketplace" && PORT="$MK_PORT" DEMO_STATE_FILE="$WORK/marketplace.json" exec node server.mjs >"$WORK/marketplace.log" 2>&1) &101PIDS+=($!)102(cd "$HERE/demo-wallet" && PORT="$WL_PORT" DEMO_STATE_FILE="$WORK/wallet.json" exec .venv/bin/python app.py >"$WORK/wallet.log" 2>&1) &103PIDS+=($!)104wait_http "http://localhost:$MK_PORT/health" "demo-marketplace"105wait_http "http://127.0.0.1:$WL_PORT/health" "demo-wallet"106107# 4. Assertions108set +e109MK_URL="http://localhost:$MK_PORT" WL_URL="http://localhost:$WL_PORT" MK_DOWN_PORT="$MK_DOWN_PORT" WL_DOWN_PORT="$WL_DOWN_PORT" \110  MK_STATE="$WORK/marketplace.json" WL_STATE="$WORK/wallet.json" WORK="$WORK" node "$HERE/e2e.mjs"111CODE=$?112set -e113if [ "$CODE" != "0" ]; then114  echo "--- demo-marketplace log"; tail -n 20 "$WORK/marketplace.log" || true115  echo "--- demo-wallet log"; tail -n 20 "$WORK/wallet.log" || true116fi117exit "$CODE"118
Files main
Menu

Theme