add more tufrootveriify tests

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-15 06:43:12 -06:00
parent af75fe875c
commit 2ef8eb6a1f

View file

@ -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")
})
}