Skip to content

tests: Add end-to-end test for the examples#2948

Open
arpitjain099 wants to merge 1 commit into
theupdateframework:developfrom
arpitjain099:test/examples-e2e
Open

tests: Add end-to-end test for the examples#2948
arpitjain099 wants to merge 1 commit into
theupdateframework:developfrom
arpitjain099:test/examples-e2e

Conversation

@arpitjain099
Copy link
Copy Markdown

Description of the changes being introduced by the pull request:

This adds an end-to-end test that runs the repository, uploader and client examples against each other, which is the part of #2228 that was not covered by the tuf.repository interface tests already merged in #2651.

The new tests/test_examples_e2e.py drives the three examples the way a user runs them from the command line (see their READMEs):

  • examples/repository/repo is started as a live HTTP server on a free port
  • examples/uploader/uploader does Trust-On-First-Use, claims a delegation, and uploads target files to that server
  • examples/client/client does Trust-On-First-Use and downloads the uploaded targets

Because the client downloads through ngclient.Updater, a successful download means the metadata chain and the target hash both verified, so the test asserts the downloaded content matches what the uploader published.

It also covers the "client that has metadata version N can successfully update to N+M" case from the issue: after the client is initialized and has downloaded a first target, the uploader adds a second target (which publishes new targets, snapshot and timestamp metadata). The test checks that the snapshot version advanced and that the already-initialized client can then refresh and download the new target.

A few notes on how it stays deterministic and isolated:

  • the example scripts import their private helper modules by name (from _simplerepo import SimpleRepository), so each example dir is put on PYTHONPATH
  • the client and uploader store trusted metadata and keys under Path.home(), so HOME is pointed at a temporary directory; nothing touches the real home dir and every run starts from a clean repository
  • readiness is handled by polling for 1.root.json (reusing tests.utils.wait_for_server for the port) rather than sleeping

The examples themselves are not modified; this only wires the existing ones together as a test. Ran locally with python -m unittest tests.test_examples_e2e (also green under the project's surrounding example tests), and ruff check / ruff format / mypy are clean on the new file.

I kept this scoped to the examples e2e slice. Whether the remaining idea in the issue (unit-testing SimpleRepository directly) is still wanted, and whether #2228 should stay open for it, is up to you.

Addresses #2228

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Add an integration test that runs the repository, uploader and client
examples against each other, the way a user runs them from the command
line:

* start examples/repository/repo as a live HTTP server
* run examples/uploader/uploader to TOFU, claim a delegation and upload
  target files
* run examples/client/client to TOFU and download the uploaded targets,
  which verifies them against the repository metadata

The test uploads a second target after the client is already
initialized and then downloads it, so the client has to update from the
metadata version it trusts (N) to a newer version (N+M). This covers the
still-open "examples" part of issue theupdateframework#2228; the tuf.repository interface
tests requested there landed earlier in PR theupdateframework#2651.

The test is hermetic: it points HOME at a temporary directory so the
client and uploader trust stores do not touch the real home directory,
runs the server on a free port, and polls for readiness instead of
sleeping.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099 arpitjain099 requested a review from a team as a code owner June 3, 2026 00:37
@jku
Copy link
Copy Markdown
Member

jku commented Jun 3, 2026

TimeoutError: Could not connect to the repository example on port 39201

It's been so long since I touched tests that actually setup http servers that I don't have any useful advice but that issue does reproduce locally for me.

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