blitz_api/tests
fusion44 97cbd4cb55
fix(setup): make input validation effective and tighten setup endpoints
password_valid()/name_valid() ended in `return re.match(...)`, which yields a
Match object or None. The setup router tests them with `is False`, and
`None is False` is False, so the charset check never rejected anything --
only the length and space rules were doing any work. The validators now return
real booleans, and use fullmatch: with re.match the trailing `$` also matches
just before a final newline.

Impact is bounded, and this is a correctness bug rather than a vulnerability.
These call sites are reachable only while the node is in `state=waitsetup`,
and that same endpoint hands the caller a signed admin JWT by design, on a
device where blitzapi has passwordless sudo. A malformed hostname reaching the
setup file -- which provisioning sources as bash -- therefore grants nothing
the caller does not already have, and in practice the value comes from the
operator's own setup form. What it does cost: a hostname containing a quote or
`$` corrupts the setup file and breaks provisioning, and the charset gate
would not hold as a defence if the setup flow ever gains operator binding.

Also in this change:

- Gate /setup-start-done and /setup-start-info on setupPhase != "done", as
  /setup/shutdown already does. `state` lives in the unauthenticated key-value
  store, so a local process could flip it back to "waitsetup" on a fully
  provisioned node and be handed an admin JWT. Unlike the above, that is a
  real escalation, because setup is supposed to be closed at that point.
- raise HTTPException instead of returning it (18 sites). FastAPI serialised
  the returned object as a 200 body, so rejections looked like successes; the
  WebUI stored that body as its access token.
- Fix the status.status.HTTP_405_METHOD_NOT_ALLOWED typo (3 sites) that raised
  AttributeError and surfaced as an unhandled 500.
- Create the setup file 0600. It holds passwords A/B/C in cleartext and
  provisioning appends the wallet seed words, on a tmpfs mounted mode=0777.

Regression tests in tests/test_setup_input_validation.py; all nine fail before
this change and pass after.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 10:51:07 +02:00
..
models feat: implement Ruff as a linter; fix given errors 2023-06-25 07:17:00 +02:00
routers feat(api): implement GET /system/health readiness endpoint (#145) 2026-07-12 18:41:18 +02:00
__init__.py test: Add testing dependencies and first tests 2021-10-02 12:00:44 +02:00
test_app_manage_lock.py fix(api): release Redis connections in channel listeners/notifiers 2026-07-03 22:40:14 +02:00
test_apps_uninstall_keep_data.py fix(apps): honour keep_data on uninstall and fix install log name 2026-07-03 20:58:35 +02:00
test_bitcoin_rpc_success.py test(bitcoind): lock JSON-RPC 2.0 success handling (no error key) 2026-07-08 13:47:11 +02:00
test_bitcoin_rpc_warmup.py fix(bitcoind): handle JSON-RPC errors returned with HTTP 200 2026-07-08 13:30:04 +02:00
test_change_password.py fix(system): stop leaking passwords via change-password endpoint 2026-07-03 21:42:25 +02:00
test_channel_cleanup.py fix(api): release Redis connections in channel listeners/notifiers 2026-07-03 22:40:14 +02:00
test_cln_list_all_tx.py fix(lightning): include payments in CLN list_all_tx 2026-07-03 20:45:21 +02:00
test_cln_shell_safety.py fix(lightning): prevent shell injection in CLN local calls 2026-07-03 19:58:41 +02:00
test_decode_pay_request_errors.py fix(lightning): clear error for undecodable/wrong-network invoices 2026-07-12 18:41:18 +02:00
test_electrs_advanced_status.py fix(apps): report electrs installed/configured/online in advanced status 2026-07-08 13:07:52 +02:00
test_error_handlers.py feat(api): normalize all error responses to the ErrorMessage shape 2026-07-12 18:41:18 +02:00
test_error_response.py feat(api): add gated build_error_response for consistent errors 2026-07-12 18:41:18 +02:00
test_exec_bash_timeout.py fix(api): catch subprocess timeouts in exec_bash_command 2026-07-03 19:59:57 +02:00
test_hardware_info_vm.py fix(system): tolerate empty hardware Redis values on VM setups 2026-07-08 14:45:21 +02:00
test_hw_gatherer_resilience.py feat(api): serve realtime updates over /ws WebSocket 2026-07-12 18:41:18 +02:00
test_jwt.py fix(auth): correct JWT expiry unit and use standard exp claim 2026-07-03 20:35:34 +02:00
test_lnd_transient_errors.py fix(lnd): return a retryable status while the RPC server starts up 2026-07-11 10:02:20 +02:00
test_native_python_errors.py fix(system): stop native_python impl swallowing errors into None 2026-07-03 21:44:25 +02:00
test_send_coins_input.py refactor(lightning): migrate SendCoinsInput validator to Pydantic v2 2026-07-03 22:22:05 +02:00
test_setup_input_validation.py fix(setup): make input validation effective and tighten setup endpoints 2026-08-16 10:51:07 +02:00
test_startup_status.py refactor(api): hoist api_startup_status into a shared leaf module 2026-07-12 18:41:18 +02:00
test_system_health.py feat(api): add pure build_health_info + rename subsystem field to healthy 2026-07-12 18:41:18 +02:00
test_warmup_events.py feat(api): serve realtime updates over /ws WebSocket 2026-07-12 18:41:18 +02:00
test_ws_endpoint.py feat(api): serve realtime updates over /ws WebSocket 2026-07-12 18:41:18 +02:00
test_ws_manager.py fix(api): harden WebSocket auth handshake against bad/disconnecting clients 2026-07-12 18:41:18 +02:00
utils.py chore: format source using the pre_commit command 2022-03-20 17:20:56 +01:00