Skip to content

test-infra: shared Postgres harness and keystore temp paths #85

Description

@LKSNDRTMLKV

Two test-infrastructure findings surfaced while reviewing Codacy output on #57. Neither is a live vulnerability — both are test-only — but both are the kind of thing that gets copied one more time every time someone adds a suite.

1. The Postgres testcontainer harness is duplicated eight times

start_pg() — spin up postgres:17, wait for readiness, sleep 1.5s, CREATE ROLE odal_app, run migrations via the admin URL, reconnect as the app role — is copy-pasted across:

  • crates/dpp-dal/tests/pg_integration.rs
  • crates/dpp-dal/tests/pg_seal_outbox.rs
  • crates/dpp-node/tests/import_job_store.rs
  • crates/dpp-node/tests/registry_outbox.rs
  • crates/dpp-node/tests/seal_outbox.rs
  • crates/dpp-node/tests/smoke.rs
  • crates/dpp-node/tests/webhook_outbox.rs
  • crates/dpp-vault/tests/helpers/mod.rs

Six predate #57; two were added by it, following the established pattern. This is the main contributor to the duplication metric Codacy reports on PRs touching the Docker tiers.

The cost is not aesthetics: the readiness logic carries a hardcoded sleep(1500ms) that every copy has to get right independently, and a change to the bootstrap sequence (a new role grant, a different image pin) means eight edits or seven silent divergences.

Shape of a fix: a dpp-test-support dev-only crate exposing start_pg() and the passport fixtures. Cross-crate sharing of #[cfg(test)] code needs a real crate — a mod helpers cannot reach across crate boundaries, which is exactly why this got copied.

2. Five tests write a real keystore to a predictable shared-temp path

KeyStore holds Ed25519 private keys. These open one at std::env::temp_dir()/<name>-<uuid>.json, with no cleanup:

  • crates/dpp-identity/src/handlers/rotate_key.rs:102
  • crates/dpp-identity/src/handlers/verify.rs:94
  • crates/dpp-identity/src/router.rs:82
  • crates/dpp-node/src/infra/ruleset.rs:145
  • crates/dpp-node/tests/smoke.rs:163

Severity is low and worth stating plainly: the passphrases are literals like "test", the keys are throwaway, and nothing production-adjacent reads these paths. It is hygiene, not an exposure. But it is the same finding Codacy raised against the two instances #57 added — those were changed to tempfile::tempdir(), which gives restrictive permissions and removal on drop. These five predate the check and so are invisible to it.

Every run also leaves the file behind, so a long-lived dev machine accumulates them.

Shape of a fix: tempfile::tempdir(), ideally via the shared harness from (1) so there is one place that knows how to make a throwaway keystore.

Sequencing

(1) subsumes (2) if the extracted harness owns keystore creation, so doing them together is cheaper than separately. Neither blocks anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions