Skip to content

Add an API test suite and fix six bugs it turned up - #198

Open
babourine wants to merge 39 commits into
patterninc:mainfrom
babourine:stan_test_e2e
Open

babourine wants to merge 39 commits into
patterninc:mainfrom
babourine:stan_test_e2e

Conversation

@babourine

Copy link
Copy Markdown
Contributor

Hey all. I've been building a test safety net for heimdall, and it turned up a few bugs along the way. This PR adds the tests and fixes six of them.

Builds on #197 (Makefile). The tests run through its make targets, so please merge that one first. Until then, this diff includes it.

How to review

  • One commit per fix, tests included. Review them one at a time, in order.
  • Run everything locally:
    • make docker-up && make test-e2e runs the black-box API suite against the compose stack;
    • make go-test runs the unit tests with -race; no database needed.
  • Each fix's test fails without it. I checked by reverting each one. Re-run any of them that way if you want to see the bug for yourself.

Fixes

  1. Filter.Render race (internal/pkg/database/filter.go).
    • The bug: every list endpoint parsed its SQL template into one shared *template.Template, so GET /jobs and GET /commands running at the same moment could execute each other's query.
    • What users saw: under load, list pages occasionally showed wrong results or failed with SQL errors.
    • Fix: templates are parsed per call.
    • Proof: before the fix, TestFilterRenderConcurrent produced wrong SQL 26 times out of 50.
  2. Unbounded request bodies (handler.go, server.go).
    • The bug: io.ReadAll had no limit, so one client could make the server buffer as much as it could send.
    • Fix: API bodies are capped by a new server.max_request_bytes setting (default 1 MiB, about 10× the largest real body), and anything over gets 413.
  3. Prefix route matching (heimdall.go).
    • The bug: API routes used PathPrefix, so POST /api/v1/jobs (note the s) submitted a job, and PUT /api/v1/command/x/anything reached submitCommand. That second one matters if a proxy in front guards catalog writes by exact path.
    • Fix: routes match exact paths, and unknown API paths get a JSON 404 instead of a 500.
  4. Query parameters overriding the path (applyQuery in handler.go).
    • The bug: PUT /api/v1/command/a?id=b wrote command b, and POST /job?canceled_by=x stored x.
    • Fix: the path always names the object, and only GET reads the query (filters and paging).
  5. Auth plugin errors ignored (auth.go).
    • The bug: the middleware dropped GetUser's error and carried on as anonymous.
    • Fix: a rejected credential now gets 401 on every route, without echoing the plugin's error.
    • No credentials is still anonymous: GetUser now documents returning ("", nil). So paths a proxy deliberately passes unauthenticated, like /metrics, keep working.
  6. heimdall print showing secrets (pkg/context, database, ranger).
    • The bug: context passwords, custom sensitive_context_keys, the database password and the Ranger client password all printed in plain text, and print output tends to end up in terminals and CI logs.
    • Fix: they print as REDACTED. The DSN keeps its host and database.

What to watch after deploying

  • Exact routes: a client that relied on trailing slashes or extra path segments gets a 404. Worth checking any scripts or scheduler operators that call the API.
    • gauravwarale: every path the UI calls is pinned in TestRouteTable and still matches. A quick click-through after deploy would confirm it.
  • Wrong method: gets 404, not 405. gorilla/mux 1.8.1 subrouters lose the method mismatch. A skipped test records that we'd like 405, possibly by moving to the standard library's ServeMux.
  • Query on writes: query parameters on POST and PUT are now ignored.
  • Body size: a request over 1 MiB gets 413. Raise server.max_request_bytes if anything legitimate trips it.

The tests, and how to use them

  • test/e2e/: tests the running server over HTTP. They cover the catalog, the async and sync job lifecycle, cancel, listing and paging, admin writes, health, and error shapes. If you change behaviour a client can see, this is where it shows.
  • Unit tests: context redaction, filter rendering, caller patterns, statuses and duration. The handler and middleware tests use httptest on the router, which is now built in its own router() method, so they need no database.
  • Known bugs as skipped tests (TestWant…):
    • Each one is the real assertion, skipped, with a WHAT comment (what should change, often with a code sketch) and a WHY comment (who it hurts).
    • Fixing one means deleting its t.Skip, renaming it to Test…, and making it pass. They make good first tasks in this codebase.
    • Open ones include:
      • unknown ids return 500 instead of 404;
      • a malformed body or bad cursor returns 500 instead of 400;
      • a sync job isn't in the database yet when submit returns;
      • payload_handler latency is recorded at startup, not per request;
      • any user can cancel any job. That one is left on purpose: it needs an admin or group rule first, which deserves its own discussion.

make go-fmt-check go-tidy-check go-vet go-lint go-build go-test (or make go-all) passes, and the e2e suite passes against the compose stack.

babourine and others added 30 commits November 29, 2026 19:46
…all so forks dont havbe this workflow failing
…eave stale binaries and plugins'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…tion so Init() call remains just a read call and does not change anything (support of validate and print commands)
…le different modes of operation -- running different containers on demand
* Add fork CI (stan-ci)

* make step blocking

---------

Co-authored-by: Stan Babourine <2166030+babourine@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 23:14
@wiz-55ccc8b716

wiz-55ccc8b716 Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities 1 Medium
Data Finding Sensitive Data -
Secret Finding Secrets 4 Low 1 Info
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Software Management Finding Software Management Findings -
Total 1 Medium 4 Low 1 Info

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed database DSNs can expose credentials unchanged because URL and query parsing errors are not safely handled.

4 open issues
1 file not reviewed
  • web/pnpm-lock.yaml: Generated file
What changed in this PR

Adds an API regression suite and fixes six issues in request handling, authentication, SQL rendering, and secret redaction. It also includes the Makefile foundation from #197, which should merge first.

Changes:

  • Adds unit, router, end-to-end, smoke, and coverage checks.
  • Hardens routing, request bodies, query precedence, authentication, and configuration printing.
  • Updates build workflows, local development tooling, dependencies, and UI snapshots.
File Description
web/​src/​components/​ListPage/​__snapshots__/​ListPage.test.tsx.snap Refreshes list-page snapshots.
web/​src/​components/​DetailPage/​__snapshots__/​DetailPage.test.tsx.snap Refreshes detail-page snapshots.
web/​pnpm-lock.yaml Updates UI dependencies.
web/​Makefile Adds web development targets.
test/​e2e/​want_test.go Records skipped assertions for known issues.
test/​e2e/​sync_test.go Tests synchronous jobs.
test/​e2e/​routing_test.go Tests routing and JSON errors.
test/​e2e/​jobs_list_test.go Tests filtering and pagination.
test/​e2e/​job_test.go Tests asynchronous job lifecycle.
test/​e2e/​health_test.go Tests cluster health endpoints.
test/​e2e/​client_test.go Adds shared HTTP test helpers.
test/​e2e/​catalog_test.go Tests catalog reads and statuses.
test/​e2e/​cancel_test.go Tests job cancellation.
test/​e2e/​admin_test.go Tests catalog writes.
scripts/​ci/​smoke.sh Adds stack smoke checks.
scripts/​ci/​coverage.sh Adds coverage reporting and checks.
scripts/​ci/​coverage-baseline.txt Records the coverage baseline.
README.md Documents Makefile and CLI usage.
pkg/​plugin/​auth.go Documents authentication error semantics.
pkg/​object/​status/​status_test.go Tests object status serialization.
pkg/​object/​object_test.go Tests object initialization.
pkg/​object/​job/​status/​status_test.go Tests job status serialization.
pkg/​object/​job/​job_test.go Tests job defaults and IDs.
pkg/​object/​command/​command_test.go Tests caller allowlists.
pkg/​duration/​duration_test.go Tests duration parsing and serialization.
pkg/​context/​context.go Redacts YAML context output.
pkg/​context/​context_test.go Tests redaction and internal secret retention.
Makefile Adds build, test, coverage, and development targets.
internal/​pkg/​server/​server.go Adds request-body limit configuration.
internal/​pkg/​rbac/​ranger/​print_test.go Tests Ranger password redaction.
internal/​pkg/​rbac/​ranger/​client.go Redacts Ranger passwords in YAML.
internal/​pkg/​object/​command/​starrocks/​job_context.go Removes an extra blank line.
internal/​pkg/​object/​command/​starrocks/​backend_client_pool.go Adds a deprecation lint suppression.
internal/​pkg/​object/​command/​starrocks/​arrow_types.go Adds a deprecation lint suppression.
internal/​pkg/​object/​command/​sparkeks/​sparkeks.go Adds uploader deprecation suppressions.
internal/​pkg/​object/​command/​spark/​spark.go Adds uploader deprecation suppressions.
internal/​pkg/​object/​command/​postgres/​postgres.go Removes unused state and wraps errors.
internal/​pkg/​object/​command/​ecs/​ecs.go Removes an unused client field.
internal/​pkg/​heimdall/​stdout_test.go Adds output-capture and telemetry helpers.
internal/​pkg/​heimdall/​router_test.go Tests routing, authentication, health, and body limits.
internal/​pkg/​heimdall/​print_test.go Tests configuration printing and redaction.
internal/​pkg/​heimdall/​keepalive.go Relocates the keepalive default.
internal/​pkg/​heimdall/​job.go Uses shared build metadata; corrects a comment.
internal/​pkg/​heimdall/​heimdall.go Refactors CLI lifecycle and exact routing.
internal/​pkg/​heimdall/​handler.go Limits bodies and fixes query precedence.
internal/​pkg/​heimdall/​handler_test.go Tests payload field precedence.
internal/​pkg/​heimdall/​auth.go Rejects authentication plugin errors.
internal/​pkg/​database/​redact.go Adds database password redaction.
internal/​pkg/​database/​redact_test.go Tests database configuration redaction.
internal/​pkg/​database/​filter.go Parses SQL templates per call.
internal/​pkg/​database/​filter_test.go Tests rendering and concurrent isolation.
internal/​pkg/​aws/​s3.go Adds an uploader deprecation suppression.
internal/​pkg/​auth/​auth.go Adjusts import grouping.
go.mod Updates Go and dependency versions.
entrypoint.sh Uses new binary paths and server subcommand.
Dockerfile Builds through Makefile targets.
docker-compose.yaml Adds readiness checks and build metadata.
configs/​local.yaml Updates plugin paths and adds test fixtures.
configs/​local-cli.yaml Adds host-development configuration.
cmd/​heimdall/​heimdall.go Delegates CLI execution to Heimdall.
.github/​workflows/​stan-ci.yml Adds fork CI and end-to-end checks.
.github/​workflows/​build.yml Uses Makefile checks, builds, and tests.

Review effort: Balanced

Comment thread internal/pkg/database/redact.go Resolved
Comment thread internal/pkg/heimdall/heimdall.go Resolved
Comment thread scripts/ci/smoke.sh Resolved
Comment thread test/e2e/catalog_test.go Resolved
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.

2 participants