Skip to content

Return 404 for requests to paths the Flask mock does not serve - #3384

Merged
adamtheturtle merged 5 commits into
mainfrom
adamtheturtle/issue-3368
Aug 10, 2026
Merged

Return 404 for requests to paths the Flask mock does not serve#3384
adamtheturtle merged 5 commits into
mainfrom
adamtheturtle/issue-3368

Conversation

@adamtheturtle

Copy link
Copy Markdown
Member

validate_request is a before_request hook, and Flask runs those before it raises a routing error, so requests matching no route reached validate_keys, which unpacked an empty generator and raised ValueError — crashing the Flask and Docker backends for any authenticated request to an unknown path or to a known path with an unserved method.

This skips validation when Flask has matched no route (request.url_rule is None), leaving Flask to raise its own routing error: 404 for an unknown path, as real Vuforia returns, and 405 for an unserved method.

Tests use the Flask test client, since responses intercepts only the paths the app routes; a further test covers the unauthenticated probe the Docker health check makes, which now sees 404 instead of 401 (both are in its accepted set). The new behaviour and the unverified response bodies are documented in the differences doc.

Closes #3368

🤖 Generated with Claude Code

adamtheturtle and others added 5 commits August 10, 2026 10:25
The Flask app's ``validate_request`` before_request hook ran for requests
which match no route, because Flask runs before_request handlers before it
raises the routing error. ``validate_keys`` then unpacked an empty generator
and raised a ``ValueError``, so any authenticated request to an unknown path,
or to a known path with a method it does not serve, crashed the Flask and
Docker backends.

Skip validation when Flask has matched no route, so Flask raises its own
routing error: 404 for an unknown path, as real Vuforia returns, and 405 for
an unserved method.

Closes #3368

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Real Vuforia returns a 404 response both for a request to a path which it
does not serve and for a request to a served path with a method which that
path does not serve; it does not return a 405. Make the Flask app return a
404 with no body in both cases, rather than Flask's 404 page or a 405.

Add verified fake tests which run against real Vuforia and the mocks, and
record in the differences documentation which bodies real Vuforia gives.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Every entry in the CI test matrix uses one of the credentials files in
secrets.tar.gpg, and there are exactly as many of those files as there are
entries, so a new entry has no database to use and its job fails while
copying the file. Move the tests into tests/mock_vws/test_invalid_given_id.py,
which already covers requests which name something the API does not serve,
rather than adding an entry.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Flask backend crashes on requests to unrouted paths and methods

1 participant