Repository navigation
server: wrap outer mux, clean up wrapper, add E2E validation test - #204
Conversation
#203 kept the adapter's own ServeMux from redirecting unclean /broker/ paths. But cmd/main.go mounts the adapter on a second ServeMux, which cleans the path and sends the relative 301 first, so the adapter never saw these requests and the dispatcher still failed on them. Add HttpAdapter.Wrap, which sends unclean /broker/ paths directly to the adapter, and use it in front of the outer mux. The test now goes through an outer mux, the same as production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a shared relay scenario that requests //file and /./file through the real tunnel server image, agent and origin. On main the outer ServeMux in cmd/main.go sends a relative 301 and the scenario fails. With HttpAdapter.Wrap the origin serves the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ve them Both agents' accept filters reject a path that is not normalized: the grpc-tunnel agent with 400 "path is not normalized", snyk-broker with 401 "blocked". The scenario now checks that such a path reaches the agent and gets that 4xx, and that the ingress does not answer with a redirect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HttpAdapter.ServeHTTP had its own copy of the unclean-path check from #203. It now uses Wrap in front of its own ServeMux, the same as cmd/main.go does for the outer one, so the check is in one place. Wrap calls handleBrokerDispatch directly, so ServeHTTP and Wrap do not call each other. The test now sends each path through both entry points: the adapter directly, and an outer ServeMux as in cmd/main.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wrap had to find paths that are not clean and send them past each ServeMux that routed to the adapter. Now no ServeMux routes the adapter's paths. Wrap matches connection-status and /broker/ dispatch on the path as it was sent, and sends all other requests to next. ServeHTTP is Wrap in front of a 404, and cmd/main.go no longer registers the adapter's paths on its mux. isCleanPath is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| if r.Method != http.MethodGet && r.Method != http.MethodHead { | ||
| return "", false | ||
| } | ||
| for _, prefix := range []string{"/connection-status/", "/broker/connection-status/"} { |
There was a problem hiding this comment.
i don't like that we are hand-extracting this when the prior code did r.PathValue("token"), which i understood came from the Mux. Can we reuse a more generic approach can we use a mux under the covers just for path extraction rather than trying to parse the strings?
There was a problem hiding this comment.
Changed in de5455b. A ServeMux cannot do the extraction here: it cleans the path and sends the 301 before any handler runs, and it has no setting to turn that off. So connectionStatusToken now uses one regex, ^(?:/broker)?/connection-status/([^/]+)$. TestConnectionStatusToken checks both forms, hashed and raw tokens, and the paths that must not match (no token, extra segments, //, other prefixes, and dispatch paths).
connectionStatusToken now uses a regex for /connection-status/{token}
and /broker/connection-status/{token}, instead of hand-written prefix
cuts. Wrap checks the method. TestConnectionStatusToken covers both
forms and the paths that must not match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
#203 did not stop the failures. The relay dispatcher still logs
IllegalArgumentException: Expected URL scheme 'http' or 'https' but no scheme was found for /broke...for paths such as/broker/<token>/repos/o/r/contents//Jenkinsfile.#203 made
HttpAdapter.ServeHTTPbypass the adapter's ownServeMuxfor paths that are not clean. Butcmd/main.gomounts the adapter on a second, outerServeMux:The outer mux cleans the path and sends the relative 301 first, so the adapter never sees these requests. The test in #203 called the adapter directly, so it did not catch this.
Fix
No
ServeMuxroutes the adapter's paths now, so nothing cleans them.HttpAdapter.Wrap(next)serves all of the adapter's routes, and sends all other requests tonext. It matches the path as it was sent:GET /connection-status/{token}andGET /broker/connection-status/{token}: connection status/broker/{token}/{path...}: tunnel dispatchHttpAdapter.ServeHTTPisWrapin front of a 404. The adapter has no internalServeMux.main.gono longer registers/broker/and/connection-status/on its mux. It useshttpAdapter.Wrap(httpMux)as the server handler.connectionStatusTokenextracts the token with one regex,^(?:/broker)?/connection-status/([^/]+)$, andgetConnectionStatusgets the token as an argument. AServeMuxcannot do this extraction, because it cleans the path first.TestConnectionStatusTokencovers the paths that must and must not match.TestBrokerDispatch_ForwardsPathAsSentsends each path through both entry points: the adapter directly, andWrapin front of aServeMux, as inmain.go.One small behavior change: a non-GET request to the root
/connection-status/{token}now gets 404 instead of 405. The dispatcher sends only GET there.End-to-end test
agent/test/relay/relay_scenarios.shhas a new shared scenario,scenario_unclean_path_reaches_agent. It sends.../contents//Jenkinsfileand.../contents/./Jenkinsfilethrough the real tunnel server image (the realmain.gowiring), agent, and origin. It runs against both transports.Both agents' accept filters reject a path that is not normalized: the grpc-tunnel agent with 400
path is not normalized, snyk-broker with 401blocked. So the scenario checks that the request reaches the agent and gets that 4xx, and that the ingress does not answer with a redirect.main+ scenario only (run)CI on this branch runs
make -C server test.🤖 Generated with Claude Code