From 2ef8eb6a1f2cc9d48dd87b4117a168c359e9dab4 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Fri, 15 Mar 2024 06:43:12 -0600 Subject: [PATCH] add more tufrootveriify tests Signed-off-by: Meredith Lancaster --- .../tufrootverify/tufrootverify_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/cmd/attestation/tufrootverify/tufrootverify_test.go b/pkg/cmd/attestation/tufrootverify/tufrootverify_test.go index f48357487..1e0868c2e 100644 --- a/pkg/cmd/attestation/tufrootverify/tufrootverify_test.go +++ b/pkg/cmd/attestation/tufrootverify/tufrootverify_test.go @@ -4,11 +4,13 @@ import ( "bytes" "testing" + "github.com/cli/cli/v2/pkg/cmd/attestation/test" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewTUFRootVerifyCmd(t *testing.T) { @@ -32,6 +34,11 @@ func TestNewTUFRootVerifyCmd(t *testing.T) { cli: "--mirror https://tuf-repo.github.com", wantsErr: true, }, + { + name: "Has all required flags", + cli: "--mirror https://tuf-repo.github.com --root ../verification/embed/tuf-repo.github.com/root.json", + wantsErr: false, + }, } for _, tc := range testcases { @@ -55,3 +62,20 @@ func TestNewTUFRootVerifyCmd(t *testing.T) { }) } } + +func TestTUFRootVerify(t *testing.T) { + mirror := "https://tuf-repo.github.com" + root := test.NormalizeRelativePath("../verification/embed/tuf-repo.github.com/root.json") + + t.Run("successfully verifies TUF root", func(t *testing.T) { + err := tufRootVerify(mirror, root) + require.NoError(t, err) + }) + + t.Run("fails because the root cannot be found", func(t *testing.T) { + notFoundRoot := test.NormalizeRelativePath("./does/not/exist/root.json") + err := tufRootVerify(mirror, notFoundRoot) + require.Error(t, err) + require.ErrorContains(t, err, "failed to read root file") + }) +}