Skip to content

Commit

Permalink
test: Update Python interop tests to python-tuf v1.0.0 (#228)
Browse files Browse the repository at this point in the history
* Add python-tuf-v1.0.0 client/generator

Signed-off-by: Zachary Newman <z@znewman.net>
Signed-off-by: Asra Ali <asraa@google.com>

* Update python_interop Makefile to generate v1.0.0

Signed-off-by: Zachary Newman <z@znewman.net>
Signed-off-by: Asra Ali <asraa@google.com>

* Make Python interop tests run against v1.0.0.

A few changes, besides pointing at the new directory:

- the python-tuf repo says "High-level support for implementing
  repository operations is planned but not yet provided;" this includes
  consistent snapshot, so we'll add a consistent snapshot test at that
  point.
- make a new tmp dir for each Python client test (it gets confused
  otherwise)
- the new python-tuf client downloads `foo/bar.txt` to
  `targets/foo%2Fbar.txt` so check for it there

Signed-off-by: Zachary Newman <z@znewman.net>
Signed-off-by: Asra Ali <asraa@google.com>

* Remove old python_interop for python-tuf v0.11.1

Signed-off-by: Zachary Newman <z@znewman.net>
Signed-off-by: Asra Ali <asraa@google.com>

* Add consistent snapshot (generator + test)

Signed-off-by: Asra Ali <asraa@google.com>

* Regenerate python_interop testdata

Signed-off-by: Asra Ali <asraa@google.com>

* update testadata and requirements

Signed-off-by: Asra Ali <asraa@google.com>

* remove addition of snapshot meta in timestamp

Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Zachary Newman <z@znewman.net>
Signed-off-by: Asra Ali <asraa@google.com>
Co-authored-by: Asra Ali <asraa@google.com>
  • Loading branch information
znewman01 and asraa authored Aug 26, 2022
1 parent 9b6c503 commit d7ff71b
Show file tree
Hide file tree
Showing 56 changed files with 515 additions and 974 deletions.
23 changes: 11 additions & 12 deletions client/python_interop/python_interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -43,11 +44,11 @@ func (InteropSuite) TestGoClientPythonGenerated(c *C) {
// start file server
cwd, err := os.Getwd()
c.Assert(err, IsNil)
testDataDir := filepath.Join(cwd, "testdata", "python-tuf-v0.11.1")
testDataDir := filepath.Join(cwd, "testdata", "python-tuf-v1.0.0")
addr, cleanup := startFileServer(c, testDataDir)
defer cleanup()

for _, dir := range []string{"with-consistent-snapshot", "without-consistent-snapshot"} {
for _, dir := range []string{"without-consistent-snapshot", "with-consistent-snapshot"} {
remote, err := client.HTTPRemoteStore(
fmt.Sprintf("http://%s/%s/repository", addr, dir),
&client.HTTPRemoteOptions{MetadataPath: "metadata", TargetsPath: "targets"},
Expand All @@ -57,7 +58,7 @@ func (InteropSuite) TestGoClientPythonGenerated(c *C) {

// initiate a client with the root metadata
client := client.NewClient(client.MemoryLocalStore(), remote)
rootJSON, err := ioutil.ReadFile(filepath.Join(testDataDir, dir, "repository", "metadata", "root.json"))
rootJSON, err := ioutil.ReadFile(filepath.Join(testDataDir, dir, "repository", "metadata", "1.root.json"))
c.Assert(err, IsNil)
c.Assert(client.Init(rootJSON), IsNil)

Expand Down Expand Up @@ -112,18 +113,17 @@ func (InteropSuite) TestPythonClientGoGenerated(c *C) {
cwd, err := os.Getwd()
c.Assert(err, IsNil)

tmp := c.MkDir()
files := map[string][]byte{
"foo.txt": []byte("foo"),
"bar/baz.txt": []byte("baz"),
}

// start file server
addr, cleanup := startFileServer(c, tmp)
defer cleanup()

for _, consistentSnapshot := range []bool{false, true} {
// generate repository
tmp := c.MkDir()
// start file server
addr, cleanup := startFileServer(c, tmp)
defer cleanup()
name := fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot)
dir := filepath.Join(tmp, name)
generateRepoFS(c, dir, files, consistentSnapshot)
Expand All @@ -134,14 +134,13 @@ func (InteropSuite) TestPythonClientGoGenerated(c *C) {
prevDir := filepath.Join(clientDir, "tufrepo", "metadata", "previous")
c.Assert(os.MkdirAll(currDir, 0755), IsNil)
c.Assert(os.MkdirAll(prevDir, 0755), IsNil)
rootJSON, err := ioutil.ReadFile(filepath.Join(dir, "repository", "root.json"))
rootJSON, err := ioutil.ReadFile(filepath.Join(dir, "repository", "1.root.json"))
c.Assert(err, IsNil)
c.Assert(ioutil.WriteFile(filepath.Join(currDir, "root.json"), rootJSON, 0644), IsNil)

args := []string{
filepath.Join(cwd, "testdata", "python-tuf-v0.11.1", "client.py"),
filepath.Join(cwd, "testdata", "python-tuf-v1.0.0", "client.py"),
"--repo=http://" + addr + "/" + name,
"--verbose=5",
}
for path := range files {
args = append(args, path)
Expand All @@ -156,7 +155,7 @@ func (InteropSuite) TestPythonClientGoGenerated(c *C) {

// check the target files got downloaded
for path, expected := range files {
actual, err := ioutil.ReadFile(filepath.Join(clientDir, "tuftargets", path))
actual, err := ioutil.ReadFile(filepath.Join(clientDir, "tuftargets", url.QueryEscape(path)))
c.Assert(err, IsNil)
c.Assert(actual, DeepEquals, expected)
}
Expand Down
8 changes: 5 additions & 3 deletions client/python_interop/testdata/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
PYTHON_TUF=python-tuf-v1.0.0

all:
docker build -t tuf-gen ./generate
docker run tuf-gen | tar x
docker build -t tuf-gen ./$(PYTHON_TUF)
docker run tuf-gen | tar x -C $(PYTHON_TUF)

clean:
rm -rf python-tuf-0.9/with{,out}-consistent-snapshot
rm -rf $(PYTHON_TUF)/with{,out}-consistent-snapshot

.PHONY: all clean
2 changes: 0 additions & 2 deletions client/python_interop/testdata/python-tuf-v0.11.1/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions client/python_interop/testdata/python-tuf-v0.11.1/Dockerfile

This file was deleted.

244 changes: 0 additions & 244 deletions client/python_interop/testdata/python-tuf-v0.11.1/client.py

This file was deleted.

Loading

0 comments on commit d7ff71b

Please sign in to comment.