#!/usr/bin/env bash # Build this plugin, drop it into a throwaway Runway deployment, boot the PACKAGED host in ACTIVE mode, and prove # this release's contract end to end: # - it loads with ZERO host-linkage and bean-name/surface warnings, and its app-level settings bind; # - the JSON API serves results anonymously; there is no plugin-owned /search page until one is installed; # - the three operator actions are CSRF-protected POSTs: a GET (a cross-site link or ) changes nothing even # for a signed-in owner, a POST without the console's CSRF token is refused 403, and an anonymous caller holding # a token is still refused by the permission check (404); # - signed in as the site owner: the rebuild-index and install-page buttons are POST forms carrying the token; # the starter page installs through SitePages on an Advisory, an Enforced and a Reviewed site (each outcome # reported), renders results inline, and a second install changes nothing; # - the `exclude` setting reaches the index on the save (through the kernel's change event), without a reindex; # - searches with no results: off by default, recorded once turned on (email-like terms never), written to the # plugin's own per-site file; a FULL backup carries no-results.tsv and a TRANSFER copy leaves it out and lists it # in its manifest; the clear POST is CSRF-checked; # - the API's rate limit keys on the kernel-gated client IP: made-up X-Forwarded-For headers do not evade it; # - the result highlighter: result links (page and API) carry #rw-hl=, every page carries the loader # script stamped with the nonce its CSP allows, and the loader, highlight.js and highlight.css are served; # - the installed results page is never among its own results (2.1.1). # The deployment holds three sites copied from the wizard's default one before the ACTIVE boot: default (Advisory), # enforced, reviewed — addressed by Host name through curl --resolve. Verify ONLY against the packaged jar — never # spring-boot:run (its restart classloader loads ZERO plugins). # # Usage: scripts/verify-against-host.sh [--keep] [--port N] # JAVA_HOME=/path/to/jdk-25 required: the JDK that builds the plugin and runs the host # MVN=/path/to/mvn Maven (default: mvn on the PATH) # HOST_TARGET=/path/to/runway/runway-app/target the host build (default: the kernel this plugin sits in, else ../runway) # HOST_JAR=/path/to/runway-app--exec.jar the kernel to verify against (default: the host checkout's # runway-app/target jar MATCHING its pom version) # VERIFY_TMPDIR=/dir where the throwaway deployment goes (default: $TMPDIR or /tmp) # VERIFY_LOG_DIR=/dir keep copies of the host logs, the install answers and the two # backup manifests there (evidence) # The script never runs `mvn install` (nothing is written to ~/.m2): it packages this plugin offline against # whatever runway-spi is already in the local repository. set -uo pipefail HERE="$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)" # JAVA_HOME must name a JDK 25. MVN (default: `mvn` on the PATH) and HOST_TARGET (default: see above) can be set in the environment. if [ -z "${JAVA_HOME:-}" ] || [ ! -x "$JAVA_HOME/bin/java" ]; then echo "set JAVA_HOME to a JDK 25"; exit 2; fi export JAVA_HOME JAVA="$JAVA_HOME/bin/java" MVN="${MVN:-mvn}" # Default host: the kernel at the root of the repository this plugin sits in (plugins//), else a kernel # checkout named `runway` beside the plugins checkout. if [ -z "${HOST_TARGET:-}" ]; then if [ -f "$HERE/../../runway-app/pom.xml" ]; then HOST_TARGET="$HERE/../../runway-app/target" else HOST_TARGET="$HERE/../../runway/runway-app/target"; fi fi KEEP="no"; PORT="" while [ $# -gt 0 ]; do case "$1" in --keep) KEEP="yes"; shift ;; --port) PORT="${2:?}"; shift 2 ;; *) echo "unknown arg: $1"; exit 2 ;; esac; done APP_USER=root; APP_PW=Search-Admin-2026; SITE_USER=owner; SITE_PW=Search-Site-2026 PER_MINUTE=25 free_port() { python3 -I -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1]);s.close()'; } [ -n "$PORT" ] || PORT="$(free_port)" BASE="http://localhost:$PORT" echo "[verify] building the plugin ..." ( cd "$HERE" && "$MVN" -o -q -DskipTests package ) || { echo "plugin build failed"; exit 1; } # The host jar MATCHING the host pom's version — never "the newest file": every reproducible jar carries the same # fixed timestamp, so `ls -t` cannot tell a leftover release jar from the SNAPSHOT under test. if [ -n "${HOST_JAR:-}" ]; then JAR="$HOST_JAR" else HOST_VERSION="$(sed -n 's:.*\(.*\).*:\1:p' "$HOST_TARGET/../pom.xml" | head -1)" JAR="$HOST_TARGET/runway-app-$HOST_VERSION-exec.jar" fi [ -f "$JAR" ] || { echo "no host exec jar $JAR — build the host (mvn -pl runway-app package) or set HOST_JAR"; exit 1; } echo "[verify] host jar: $JAR" SCRATCH="$(mktemp -d "${VERIFY_TMPDIR:-${TMPDIR:-/tmp}}/search-verify.XXXXXX")" cleanup() { [ -z "${VERIFY_LOG_DIR:-}" ] || { mkdir -p "$VERIFY_LOG_DIR" \ && cp "$SCRATCH"/*.log "$SCRATCH"/*-manifest.yml "$SCRATCH"/install-*.txt "$VERIFY_LOG_DIR"/ 2>/dev/null; } # Wait for the host to exit before deleting: a JVM still shutting down rewrites files under external/ (the # no-result list is flushed on shutdown) and makes `rm -rf` leave the scratch folder behind. [ "$KEEP" = "yes" ] || { kill "${PID:-0}" 2>/dev/null; wait "${PID:-0}" 2>/dev/null; rm -rf "$SCRATCH"; } } trap cleanup EXIT EXT="$SCRATCH/external" mkdir -p "$EXT/plugins" cp -r "$HERE/target/search" "$EXT/plugins/search" wait_for() { for _ in $(seq 1 "$3"); do grep -q "$2" "$1" 2>/dev/null && return 0; sleep 1; done; return 1; } PASS=0; FAIL=0 ck() { if eval "$2" >/dev/null 2>&1; then echo " PASS $1"; PASS=$((PASS+1)); else echo " FAIL $1"; FAIL=$((FAIL+1)); fi; } # The shipped application.yml trusts loopback as a same-host reverse proxy. This deployment trusts only a TEST-NET # address instead, so curl on loopback is an untrusted peer: a forwarded header it sends must be ignored. boot() { ( cd "$SCRATCH" && exec "$JAVA" -jar "$JAR" --server.port="$PORT" --runway.storage.external="$EXT" \ --runway.proxy.trusted-cidrs=192.0.2.1/32 ) >"$1" 2>&1 & PID=$!; } echo "[verify] booting host (wizard) on :$PORT ..." boot "$SCRATCH/wizard.log" wait_for "$SCRATCH/wizard.log" "Started RunwayApplication" 90 || { echo "wizard did not start"; tail -20 "$SCRATCH/wizard.log"; exit 1; } curl -s -o /dev/null -X POST "$BASE/setup" --data-urlencode "username=$APP_USER" --data-urlencode "password=$APP_PW" \ --data-urlencode "displayName=Root" --data-urlencode "siteAdminUsername=$SITE_USER" --data-urlencode "siteAdminPassword=$SITE_PW" for _ in $(seq 1 30); do kill -0 "$PID" 2>/dev/null || break; sleep 1; done # --- Two more sites, copied from the seeded default one (same owner), before the ACTIVE boot reads them ---------- SITES="$EXT/sites" [ -f "$SITES/default/site.yml" ] || { echo "the wizard did not seed $SITES/default"; exit 1; } make_site() { # id editorial-level cp -r "$SITES/default" "$SITES/$1" sed -i -e "s/^id: .*/id: \"$1\"/" -e "s/^- \"localhost\"/- \"$1.test\"/" -e "s/^editorial: .*/editorial: \"$2\"/" \ "$SITES/$1/site.yml" } make_site enforced enforced make_site reviewed reviewed sed -i 's/^ - "default"$/ - "default"\n - "enforced"\n - "reviewed"/' "$EXT/site-users.yml" # A bilingual page whose visible copy comes ONLY from the site's bundles (decoupled th:text): the template holds an # empty element. The kernel indexes the page as rendered in each language, and search searches each language's # own documents. French is a site language too, for the visitor strings the plugin ships in French. sed -i '/^locales:/a - "es"' "$SITES/default/site.yml" sed -i '/^locales:/a - "fr"' "$SITES/default/site.yml" T="$SITES/default/templates" cat > "$T/faculty.html" <<'HTML' Faculty

Faculty

HTML cat > "$T/faculty.th.xml" <<'XML' XML printf 'path: /faculty\nlocalizedPaths:\n es: /facultad\nlocales: [en, es]\ntitle:\n en: Faculty\n es: Profesores\n' > "$T/faculty.meta.yml" # A page carrying the search box in French as well (a French site's results page), to prove the plugin's French # visitor strings are used there rather than English. cat > "$T/recherche.html" <<'HTML' Recherche
HTML printf 'path: /find\nlocalizedPaths:\n fr: /recherche\nlocales: [en, fr]\ntitle:\n en: Find\n fr: Recherche\n' > "$T/recherche.meta.yml" mkdir -p "$SITES/default/i18n" printf '\nverify.faculty=Our students learn from a faculty of researchers.\n' >> "$SITES/default/i18n/messages.properties" printf '\nverify.faculty=Nuestros alumnos aprenden con una facultad de excelencia.\n' >> "$SITES/default/i18n/messages_es.properties" # The app-level settings, in the file the plugins screen writes: a low per-minute ceiling the last section floods. mkdir -p "$EXT/plugin-settings" cat > "$EXT/plugin-settings/search.yml" <" / the surface reason — a grep for the # 0.6.0 wording alone can never fail on a 1.0 kernel. ck "ZERO host-linkage findings" "! grep -qE \"uses host internals|plugin 'search' linkage scan\" '$LOG'" ck "ZERO bean-name/surface findings" "! grep -qE \"plugin 'search'.*(allowed until Runway 1.0|bean name|may not contribute)\" '$LOG'" ck "no WARN/ERROR names the plugin" "! grep -E ' (WARN|ERROR) ' '$LOG' | grep -qiE \"plugin 'search'|mx\\.quest\\.search\"" ck "no key collision / degraded" "! grep -qiE 'collision|duplicate key|degraded' '$LOG'" echo "== static assets ==" ck "search.css served" "curl -s -o /dev/null -w '%{http_code}' '$BASE/__plugin/search/static/search.css' | grep -q 200" ck "help page served" "curl -s -o /dev/null -w '%{http_code}' '$BASE/__plugin/search/static/search-help.html' | grep -q 200" ck "highlight.js served as JavaScript" \ "curl -s -D - -o /dev/null '$BASE/__plugin/search/static/highlight.js' | grep -qiE '^content-type: (text|application)/javascript'" ck "highlight.css served" "curl -s -o /dev/null -w '%{http_code}' '$BASE/__plugin/search/static/highlight.css' | grep -q 200" PLUGIN_VERSION="$(sed -n 's/^version: //p' "$HERE/plugin.yml")" echo "== the result highlighter (since 2.1.0) ==" if command -v node >/dev/null 2>&1; then ck "the page scripts parse (node --check)" "node --check '$HERE/static/highlight.js' && node --check '$HERE/static/highlight-loader.js'" ck "the word pattern folds as the server lowercases (Turkish İ, accents, symbols)" \ "node '$HERE/src/test/js/highlight-pattern.js' '$HERE/static/highlight.js'" else echo " SKIP node not found: the page scripts were not parsed" fi curl -s -D "$SCRATCH/home.headers" "$BASE/" > "$SCRATCH/home.html" ck "every page carries the loader script, stamped with the nonce the kernel's CSP allows" \ "n=\$(grep -oE '