Skip to content

Commit

Permalink
Changes required to pass on macOS without dirtying the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Mar 21, 2024
1 parent b2e4fc1 commit d3aa5e3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
with:
go-version: "1.20"
cache-dependency-path: "clients/go-tuf-metadata/go.sum"
- name: Install TUF conformance tool
run: make install
- name: Install TUF conformance tool dependencies
run: make dev
- name: Test python-tuf
run: make test-python-tuf
- name: Test go-tuf-metadata
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
env/
pip-wheel-metadata/
*.egg-info/
__pycache__/
.coverage*
html/
dist/
.python-version
build
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
# tuf-conformance section
#########################

.PHONY: install
install:
pip install -e .
env/pyvenv.cfg: pyproject.toml
python3 -m venv env
./env/bin/python -m pip install --upgrade pip
./env/bin/python -m pip install -e .

.PHONY: dev
dev: env/pyvenv.cfg

.PHONY: test-all
test-all: test-python-tuf test-go-tuf-metadata
Expand All @@ -25,16 +29,16 @@ test-all: test-python-tuf test-go-tuf-metadata
#########################

PHONY: test-python-tuf
test-python-tuf:
tuf-conformance "python ./clients/python-tuf/python_tuf.py"
test-python-tuf: dev
./env/bin/tuf-conformance "./env/bin/python ./clients/python-tuf/python_tuf.py"

#########################
# go-tuf-metadata section
#########################

PHONY: test-go-tuf-metadata
test-go-tuf-metadata: build-go-tuf-metadata
tuf-conformance "./clients/go-tuf-metadata/go-tuf-metadata"
test-go-tuf-metadata: dev build-go-tuf-metadata
./env/bin/tuf-conformance "./clients/go-tuf-metadata/go-tuf-metadata"

PHONY: build-go-tuf-metadata
build-go-tuf-metadata:
Expand Down
1 change: 1 addition & 0 deletions clients/go-tuf-metadata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/go-tuf-metadata
11 changes: 6 additions & 5 deletions tuf_conformance/client_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ def __init__(self, client_cmd: str, server: SimulatorServer) -> None:
self.metadata_dir = os.path.join(self._tempdir.name, "metadata")
os.mkdir(self.metadata_dir)

def _run(self, cmd: list[str]):
def _run(self, cmd: list[str]) -> int:
popen = subprocess.Popen(cmd)
while popen.poll() is None:
self._server.handle_request()
return popen.returncode

def init_client(self, data: ClientInitData):
def init_client(self, data: ClientInitData) -> int:
trusted = os.path.join(self._tempdir.name, "initial_root.json")
with open(trusted, "bw") as f:
f.write(data.trusted_root)

cmd = self._cmd.split(" ") + ["--metadata-url", data.metadata_url, "--metadata-dir", self.metadata_dir, "init", trusted]
self._run(cmd)
return self._run(cmd)

def refresh(self, data: ClientInitData):
def refresh(self, data: ClientInitData) -> int:
cmd = self._cmd.split(" ") + ["--metadata-url", data.metadata_url, "--metadata-dir", self.metadata_dir, "refresh"]
self._run(cmd)
return self._run(cmd)
4 changes: 2 additions & 2 deletions tuf_conformance/repository_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from urllib import parse

import securesystemslib.hash as sslib_hash
from securesystemslib.keys import generate_ed25519_key
from securesystemslib.keys import generate_ecdsa_key
from securesystemslib.signer import SSlibKey, SSlibSigner

from tuf.api.metadata import (
Expand Down Expand Up @@ -132,7 +132,7 @@ def all_targets(self) -> Iterator[Tuple[str, Targets]]:

@staticmethod
def create_key() -> Tuple[Key, SSlibSigner]:
key = generate_ed25519_key()
key = generate_ecdsa_key()
return SSlibKey.from_securesystemslib_key(key), SSlibSigner(key)

def add_signer(self, role: str, signer: SSlibSigner) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tuf_conformance/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def test_basic_init_and_refresh(client: ClientRunner, server: SimulatorServer) -

# Run the test: step 1: initialize client
# TODO verify success?
client.init_client(init_data)
assert client.init_client(init_data) == 0

# TODO verify that results are correct, see e.g.
# * repo.metadata_statistics: no requests expected
# * client metadat cache should contain root v1

# Run the test: step 1: Refresh
client.refresh(init_data)
assert client.refresh(init_data) == 0

# Verify that expected requests were made
assert repo.metadata_statistics == [('root', 1), ('root', 2), ('timestamp', None), ('snapshot', 1), ('targets', 1)]
Expand Down
2 changes: 1 addition & 1 deletion tuf_conformance/simulator_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, port: int):

def get_client_init_data(self, repo: str) -> ClientInitData:
return ClientInitData(
f"http://{self.server_name}:{self.server_port}/{repo}/metadata/",
f"http://{self.server_address[0]}:{self.server_address[1]}/{repo}/metadata/",
self.repos[repo].fetch_metadata("root", 1)
)

Expand Down

0 comments on commit d3aa5e3

Please sign in to comment.