Skip to content

Commit

Permalink
Refactor basic tests
Browse files Browse the repository at this point in the history
Split the first test into two:
* One that checks the expected requests
* Other that checks trusted roles metadata

In the second test, actually compare the metadata content instead of
just the version number.

Also add a message into assert_metadata() assertion.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
jku committed Oct 2, 2024
1 parent 894fd4d commit 9b2d564
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tuf_conformance/client_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ def assert_metadata(self, role: str, expected_bytes: bytes | None) -> None:
else:
expected = None

assert trusted == expected
assert trusted == expected, f"Unexpected trusted role {role} content"
39 changes: 22 additions & 17 deletions tuf_conformance/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@
from tuf_conformance.simulator_server import SimulatorServer


def test_basic_init_and_refresh(client: ClientRunner, server: SimulatorServer) -> None:
def test_basic_refresh_requests(client: ClientRunner, server: SimulatorServer) -> None:
"""Test basic client functionality.
Run a refresh, verify client trusted metadata and requests made by the client
Run a refresh, verify requests made by the client
"""
init_data, repo = server.new_test(client.test_name)
# Run the test: step 1: initialize client
assert client.init_client(init_data) == 0

# Run the test: step 2: Refresh
# Run client refresh, verify that expected requests were made
assert client.refresh(init_data) == 0
# Verify that expected requests were made
assert repo.metadata_statistics == [
("root", 2),
("timestamp", None),
("snapshot", 1),
("targets", 1),
]

# verify client metadata looks as expected
assert client.version(Root.type) == 1
assert client.version(Timestamp.type) == 1
assert client.version(Snapshot.type) == 1
assert client.version(Targets.type) == 1

def test_basic_refresh_trusted_data(
client: ClientRunner, server: SimulatorServer
) -> None:
"""Test basic client functionality.
Run a refresh, verify clients trusted metadata
"""
init_data, repo = server.new_test(client.test_name)
assert client.init_client(init_data) == 0

# Run client refresh, verify that trusted metadata is as expected
assert client.refresh(init_data) == 0

for role in [Root.type, Timestamp.type, Snapshot.type, Targets.type]:
client.assert_metadata(role, repo.fetch_metadata(role))


def test_implicit_refresh(client: ClientRunner, server: SimulatorServer) -> None:
Expand All @@ -45,21 +54,17 @@ def test_implicit_refresh(client: ClientRunner, server: SimulatorServer) -> None
init_data, repo = server.new_test(client.test_name)
assert client.init_client(init_data) == 0

# Run download, verify that requests and trusted metadata are as expected
assert client.download_target(init_data, "nonexistent artifact") == 1

# Verify that expected requests were made
assert repo.metadata_statistics == [
("root", 2),
("timestamp", None),
("snapshot", 1),
("targets", 1),
]

# verify client metadata looks as expected
assert client.version(Root.type) == 1
assert client.version(Timestamp.type) == 1
assert client.version(Snapshot.type) == 1
assert client.version(Targets.type) == 1
for role in [Root.type, Timestamp.type, Snapshot.type, Targets.type]:
client.assert_metadata(role, repo.fetch_metadata(role))


def test_invalid_initial_root(client: ClientRunner, server: SimulatorServer) -> None:
Expand Down
3 changes: 1 addition & 2 deletions tuf_conformance/test_updater_key_rotations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
from dataclasses import dataclass

import pytest
from securesystemslib.signer import CryptoSigner
from tuf.api.metadata import Metadata, Root, Snapshot, Targets, Timestamp
from tuf.api.metadata import Root, Snapshot, Targets, Timestamp

from tuf_conformance.client_runner import ClientRunner
from tuf_conformance.simulator_server import SimulatorServer
Expand Down

0 comments on commit 9b2d564

Please sign in to comment.