Skip to content

Commit

Permalink
Skip signing tests if the GPG mechanism does not support signing
Browse files Browse the repository at this point in the history
Also abort some of the tests early instead of trying to use invalid (or
nil) values.
  • Loading branch information
mtrmac committed Mar 3, 2017
1 parent 8eb70ae commit 38f3e36
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
13 changes: 10 additions & 3 deletions cmd/skopeo/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func assertTestFailed(t *testing.T, stdout string, err error, substring string)
}

func TestStandaloneSign(t *testing.T) {
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
require.NoError(t, err)
defer mech.Close()
if err := mech.SupportsSigning(); err != nil {
t.Skipf("Signing not supported: %v", err)
}

manifestPath := "fixtures/image.manifest.json"
dockerReference := "testing/manifest"
os.Setenv("GNUPGHOME", "fixtures")
Expand Down Expand Up @@ -76,18 +83,18 @@ func TestStandaloneSign(t *testing.T) {
defer os.Remove(sigOutput.Name())
out, err = runSkopeo("standalone-sign", "-o", sigOutput.Name(),
manifestPath, dockerReference, fixturesTestKeyFingerprint)
assert.NoError(t, err)
require.NoError(t, err)
assert.Empty(t, out)

sig, err := ioutil.ReadFile(sigOutput.Name())
require.NoError(t, err)
manifest, err := ioutil.ReadFile(manifestPath)
require.NoError(t, err)
mech, err := signature.NewGPGSigningMechanism()
mech, err = signature.NewGPGSigningMechanism()
require.NoError(t, err)
defer mech.Close()
verified, err := signature.VerifyDockerManifestSignature(sig, manifest, dockerReference, mech, fixturesTestKeyFingerprint)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dockerReference, verified.DockerReference)
assert.Equal(t, fixturesTestImageManifestDigest, verified.DockerManifestDigest)
}
Expand Down
22 changes: 22 additions & 0 deletions integration/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/containers/image/manifest"
"github.com/containers/image/signature"
"github.com/go-check/check"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-tools/image"
Expand Down Expand Up @@ -237,6 +238,13 @@ func (s *CopySuite) TestCopyOCIRoundTrip(c *check.C) {

// --sign-by and --policy copy, primarily using atomic:
func (s *CopySuite) TestCopySignatures(c *check.C) {
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
c.Assert(err, check.IsNil)
defer mech.Close()
if err := mech.SupportsSigning(); err != nil { // FIXME? Test that verification and policy enforcement works, using signatures from fixtures
c.Skip(fmt.Sprintf("Signing not supported: %v", err))
}

dir, err := ioutil.TempDir("", "signatures-dest")
c.Assert(err, check.IsNil)
defer os.RemoveAll(dir)
Expand Down Expand Up @@ -286,6 +294,13 @@ func (s *CopySuite) TestCopySignatures(c *check.C) {

// --policy copy for dir: sources
func (s *CopySuite) TestCopyDirSignatures(c *check.C) {
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
c.Assert(err, check.IsNil)
defer mech.Close()
if err := mech.SupportsSigning(); err != nil { // FIXME? Test that verification and policy enforcement works, using signatures from fixtures
c.Skip(fmt.Sprintf("Signing not supported: %v", err))
}

topDir, err := ioutil.TempDir("", "dir-signatures-top")
c.Assert(err, check.IsNil)
defer os.RemoveAll(topDir)
Expand Down Expand Up @@ -385,6 +400,13 @@ func findRegularFiles(c *check.C, root string) []string {

// --sign-by and policy use for docker: with sigstore
func (s *CopySuite) TestCopyDockerSigstore(c *check.C) {
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
c.Assert(err, check.IsNil)
defer mech.Close()
if err := mech.SupportsSigning(); err != nil { // FIXME? Test that verification and policy enforcement works, using signatures from fixtures
c.Skip(fmt.Sprintf("Signing not supported: %v", err))
}

const ourRegistry = "docker://" + v2DockerRegistryURL + "/"

tmpDir, err := ioutil.TempDir("", "signatures-sigstore")
Expand Down
10 changes: 9 additions & 1 deletion integration/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"strings"

"github.com/containers/image/signature"
"github.com/go-check/check"
)

Expand Down Expand Up @@ -36,7 +37,14 @@ func findFingerprint(lineBytes []byte) (string, error) {
}

func (s *SigningSuite) SetUpTest(c *check.C) {
_, err := exec.LookPath(skopeoBinary)
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
c.Assert(err, check.IsNil)
defer mech.Close()
if err := mech.SupportsSigning(); err != nil { // FIXME? Test that verification and policy enforcement works, using signatures from fixtures
c.Skip(fmt.Sprintf("Signing not supported: %v", err))
}

_, err = exec.LookPath(skopeoBinary)
c.Assert(err, check.IsNil)

s.gpgHome, err = ioutil.TempDir("", "skopeo-gpg")
Expand Down

0 comments on commit 38f3e36

Please sign in to comment.