Open
Conversation
* Preflight for POST and PUT * Origin header for all non-namespaced requests
…ED_ORIGIN`. If empty, only the defaults (localhost on all ports and *.boptest.net) are allowed
- Add OPTIONS preflight handlers for all GET endpoints that may carry an Authorization header (testcases, status, name, measurements, inputs, kpi, forecast_points) - Add OPTIONS + addCorsOriginHdr to all three POST .../select routes so browser clients can start a test session - Fix /scenario/:testid and /step/:testid OPTIONS responses to advertise "GET, PUT" instead of only "PUT" - Add addCorsOriginHdr to GET /version - Add trailing newline to middleware.js Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Layer 1 — Node.js unit tests (mocha + supertest, no Docker needed): - test/cors.test.js covers addCorsOriginHdr, handleCorsPreflight, and the full origin allowlist (allowed and disallowed origins) - @babel/register added to package.json so mocha can transpile ES modules - npm test wired to run the suite; new cors-unit-tests job in build_test_containers.yml runs it in parallel with simulation-tests Layer 2 — pytest integration test against the deployed stack: - test_cors_headers() in test_testcase_api.py verifies CORS headers on GET /version, GET /testcases, OPTIONS /testcases preflight, OPTIONS /testcases/:id/select preflight, and that disallowed origins are blocked Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses issue #760 to allow calling BOPTEST from a web browser.
It adds CORS support to the web service.
CORS is configured conservatively: only origins matching
localhost:<port>or*.boptest.netare allowed by default. Additional origins can be whitelisted atdeploy time via the
BOPTEST_ALLOWED_ORIGINSenvironment variable (comma-separated),which is threaded through
docker-compose.yml.What's included
addCorsOriginHdrmiddleware that appendsAccess-Control-Allow-OriginandVary: Originto responses for allowed origins.handleCorsPreflightmiddleware that responds to OPTIONS preflight requests,advertising the correct allowed methods,
Content-TypeandAuthorizationheaders,and a 24-hour
Max-Agecache.GET /versionGET /testcasesPOST /testcases/*/select(all three variants)GET /status/:testid,GET /name/:testidPUT /stop/:testid,PUT /initialize/:testidGET|PUT /scenario/:testid,GET|PUT /step/:testidGET /measurements/:testid,GET /inputs/:testidPOST /advance/:testid,POST /submit/:testidGET /kpi/:testidPUT /results/:testid,PUT /forecast/:testidGET /forecast_points/:testidthat may carry an
Authorizationheader)./scenario,/step) advertise both methods in their OPTIONSresponse so either verb works from a browser.
Tests
Unit tests (
service/web/server/test/cors.test.js, mocha + supertest, no Docker needed):addCorsOriginHdr: header presence/absence,Varyheader, env-var origin,next()always calledhandleCorsPreflight: 204 + full headers for allowed origins, 405 for disallowed/absent origin,correct
Allow-Methodsfor GET / PUT / mixed routes, pass-through for non-OPTIONS verbsRun locally with:
Integration tests (
service/test/test_testcase_api.py, runs against the deployed stack):GET /versionandGET /testcasesreturnAccess-Control-Allow-Originfor an allowed originOPTIONS /testcasesreturns 204 with all preflight headers includingMax-Age: 86400OPTIONS /testcases/:id/selectreturns 204 and advertisesPOST