Skip to content

Commit cb8d298

Browse files
test(e2e): run registered HTTP middleware hooks in testkit
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent f22f90e commit cb8d298

17 files changed

Lines changed: 341 additions & 280 deletions

File tree

‎.github/workflows/e2e-suites.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ jobs:
116116
{"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
117117
{"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
118118
{"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"connect-ssh-supervision","gateway":"openshell","runner":"ubuntu-24.04"},
119+
{"environment":"ubuntu-docker-rootful-middleware-http-hooks","installer":"deb","family":"features","package":"middleware-http-hooks","gateway":"openshell","runner":"ubuntu-24.04"},
119120
{"environment":"fedora-podman-rootful-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"},
120121
{"environment":"fedora-podman-rootless-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"},
121122
{"environment":"fedora-podman-rootful-userns-default","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"},

‎e2e/rust/Cargo.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎e2e/rust/Cargo.toml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ name = "host_gateway_alias"
213213
path = "tests/host_gateway_alias.rs"
214214
required-features = ["e2e-host-gateway"]
215215

216-
[[test]]
217-
name = "supervisor_middleware_http_hooks"
218-
path = "tests/supervisor_middleware_http_hooks.rs"
219-
required-features = ["e2e-docker"]
220-
221216
[[test]]
222217
name = "workspace_namespace_managed"
223218
path = "tests/workspace_namespace_managed.rs"
@@ -270,7 +265,6 @@ tower = "0.5"
270265
url = "2"
271266

272267
[dev-dependencies]
273-
flate2 = "1"
274268
openshell-ocsf-validate = { path = "../../crates/openshell-ocsf-validate" }
275269
serial_test = "3"
276270

‎e2e/with-docker-gateway.sh‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,20 @@ ADDITIONAL_CA_SERVER_PID=""
126126
ADDITIONAL_CA_SERVER_LOG="${WORKDIR}/additional-ca-server.log"
127127
ADDITIONAL_CA_DIR="${WORKDIR}/additional-ca"
128128
ADDITIONAL_CA_PORT=""
129+
CONTENT_GUARD_PID=""
130+
CONTENT_GUARD_PORT=""
129131
IMAGE_UPDATES_MODE="${OPENSHELL_E2E_DOCKER_IMAGE_UPDATES:-0}"
130132
SUPERVISOR_NETWORK_MODE="${OPENSHELL_E2E_DOCKER_SUPERVISOR_NETWORK_MODE:-}"
131133
case "${SUPERVISOR_NETWORK_MODE}" in
132134
""|host|bridge|auto) ;;
133135
*) echo "ERROR: invalid Docker supervisor network mode for e2e." >&2; exit 2 ;;
134136
esac
135137

138+
if [ -n "${OPENSHELL_E2E_CONTENT_GUARD_BIN:-}" ] && [ -n "${OPENSHELL_GATEWAY_ENDPOINT:-}" ]; then
139+
echo "ERROR: The content guard fixture requires a gateway started by this wrapper." >&2
140+
exit 2
141+
fi
142+
136143
if [ "${IMAGE_UPDATES_MODE}" = "1" ] && [ -n "${OPENSHELL_GATEWAY_ENDPOINT:-}" ]; then
137144
echo "ERROR: Docker image-update qualification requires a new gateway owned by this wrapper." >&2
138145
exit 2
@@ -156,6 +163,7 @@ cleanup() {
156163

157164
e2e_stop_gateway "${GATEWAY_PID}" "${GATEWAY_PID_FILE}"
158165
e2e_stop_process "${ADDITIONAL_CA_SERVER_PID}" "additional CA HTTPS fixture"
166+
e2e_stop_process "${CONTENT_GUARD_PID}" "content guard middleware"
159167

160168
if [ "${exit_code}" -ne 0 ] \
161169
&& [ -n "${E2E_NAMESPACE}" ] \
@@ -608,6 +616,27 @@ fi
608616
export OPENSHELL_E2E_GATEWAY_CA_CERT="${PKI_DIR}/ca.crt"
609617
GATEWAY_ENDPOINT="https://${SUPERVISOR_GATEWAY_HOST}:${HOST_PORT}"
610618

619+
if [ -n "${OPENSHELL_E2E_CONTENT_GUARD_BIN:-}" ]; then
620+
CONTENT_GUARD_PORT="$(e2e_pick_port)"
621+
"${OPENSHELL_E2E_CONTENT_GUARD_BIN}" --bind "0.0.0.0:${CONTENT_GUARD_PORT}" &
622+
CONTENT_GUARD_PID=$!
623+
for ((attempt = 0; attempt < 30; attempt++)); do
624+
if ! kill -0 "${CONTENT_GUARD_PID}" 2>/dev/null; then
625+
echo "ERROR: Content guard exited before it started listening." >&2
626+
exit 1
627+
fi
628+
if (exec 3<>"/dev/tcp/127.0.0.1/${CONTENT_GUARD_PORT}") 2>/dev/null; then
629+
break
630+
fi
631+
sleep 1
632+
done
633+
if [ "${attempt}" -eq 30 ]; then
634+
echo "ERROR: Content guard did not start listening." >&2
635+
exit 1
636+
fi
637+
export OPENSHELL_TEST_CONTENT_GUARD_REGISTRATION=content-guard-example
638+
fi
639+
611640
echo "Starting openshell-gateway on port ${HOST_PORT} (namespace: ${E2E_NAMESPACE})..."
612641
echo "Using sandbox image: ${SANDBOX_IMAGE} (pull policy: ${SANDBOX_IMAGE_PULL_POLICY})"
613642
e2e_generate_gateway_jwt "${JWT_DIR}"
@@ -677,6 +706,12 @@ GATEWAY_CONFIG="${STATE_DIR}/gateway.toml"
677706
printf 'supervisor_image = %s\n' "$(toml_string "${SUPERVISOR_IMAGE}")"
678707
printf '\n[openshell.drivers.docker.resource_admission]\n'
679708
printf 'enabled = false\n'
709+
if [ -n "${CONTENT_GUARD_PORT}" ]; then
710+
printf '\n[[openshell.supervisor.middleware]]\n'
711+
printf 'name = %s\n' "$(toml_string "${OPENSHELL_TEST_CONTENT_GUARD_REGISTRATION}")"
712+
printf 'grpc_endpoint = %s\n' "$(toml_string "http://${SUPERVISOR_GATEWAY_HOST}:${CONTENT_GUARD_PORT}")"
713+
printf 'allow_insecure_transport = true\nmax_payload_bytes = 262144\ntimeout = "2s"\n'
714+
fi
680715
} > "${GATEWAY_CONFIG}"
681716

682717
GATEWAY_ARGS=(

‎tasks/test.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ TARGET_DIR="${CARGO_TARGET_DIR:-$PWD/target}/content-guard"
240240
cargo build --locked --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml \
241241
--target-dir "${TARGET_DIR}"
242242
export OPENSHELL_E2E_CONTENT_GUARD_BIN="${TARGET_DIR}/debug/supervisor-middleware-content-guard"
243-
export OPENSHELL_E2E_REQUIRE_MIDDLEWARE=1
244-
exec e2e/with-docker-gateway.sh cargo test --manifest-path e2e/rust/Cargo.toml \
245-
--features e2e-docker --test supervisor_middleware_http_hooks -- --nocapture
243+
exec e2e/with-docker-gateway.sh cargo test --locked \
244+
--manifest-path tests/suites/features/Cargo.toml -p middleware-http-hooks -- --nocapture
246245
"""
247246

248247
["e2e:mcp"]

‎tests/suites/features/Cargo.lock‎

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/suites/features/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
[workspace]
55
resolver = "2"
6-
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "routable-host-ip"]
6+
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "middleware-http-hooks", "oci-image", "routable-host-ip"]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
name = "middleware-http-hooks"
6+
description = "Features suite: HTTP hooks against a registered middleware service"
7+
version = "0.0.0"
8+
edition = "2024"
9+
rust-version = "1.94"
10+
license = "Apache-2.0"
11+
repository = "https://github.com/ai-openshell/openshell"
12+
publish = false
13+
14+
[[test]]
15+
name = "middleware-http-hooks"
16+
path = "tests/http_hooks.rs"
17+
harness = false
18+
19+
[dependencies]
20+
flate2 = "1"
21+
host-server-support = { path = "../../../support/host-server" }
22+
middleware-support = { path = "../../../support/middleware" }
23+
openshell-testkit = { path = "../../../testkit/testkit" }
24+
serde_json = "1"
25+
tokio = { version = "1", features = ["io-util", "net", "rt", "sync", "time"] }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Registered middleware HTTP hooks
2+
3+
Run `mise run e2e:middleware-http-hooks` to start a Docker gateway and the
4+
content-guard example and run the suite. The tmachine row
5+
`ubuntu-docker-rootful-middleware-http-hooks/deb` starts and registers the same
6+
example during environment setup. Build its binary with
7+
`nix run .#build-artifacts-test-archives` when preparing inputs locally.
8+
9+
Both environments set `OPENSHELL_TEST_CONTENT_GUARD_REGISTRATION` to the name
10+
registered in the gateway (typically `content-guard-example`). The suite fails
11+
if it is missing. The gateway and supervisor must be able to reach the guard,
12+
and the sandbox must be able to reach an upstream hosted by the test process
13+
at `host.openshell.internal`.

0 commit comments

Comments
 (0)