2017-09-14 17:58:28 -04:00
|
|
|
package trust
|
|
|
|
|
|
|
|
import (
|
2017-09-15 12:33:01 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2017-09-14 17:58:28 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
|
|
digest "github.com/opencontainers/go-digest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-09-26 12:33:35 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-10-30 12:21:41 -04:00
|
|
|
"github.com/theupdateframework/notary/client"
|
|
|
|
"github.com/theupdateframework/notary/passphrase"
|
|
|
|
"github.com/theupdateframework/notary/trustpinning"
|
2017-09-14 17:58:28 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetTag(t *testing.T) {
|
|
|
|
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
tag := getTag(ref)
|
|
|
|
assert.Equal(t, "", tag)
|
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine:latest")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
tag = getTag(ref)
|
|
|
|
assert.Equal(t, tag, "latest")
|
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
tag = getTag(ref)
|
|
|
|
assert.Equal(t, tag, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetDigest(t *testing.T) {
|
|
|
|
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
d := getDigest(ref)
|
|
|
|
assert.Equal(t, digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d)
|
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine:latest")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
d = getDigest(ref)
|
|
|
|
assert.Equal(t, digest.Digest(""), d)
|
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
d = getDigest(ref)
|
|
|
|
assert.Equal(t, digest.Digest(""), d)
|
|
|
|
}
|
2017-09-15 12:33:01 -04:00
|
|
|
|
|
|
|
func TestGetSignableRolesError(t *testing.T) {
|
|
|
|
tmpDir, err := ioutil.TempDir("", "notary-test-")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
|
|
|
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
|
2017-09-26 12:33:35 -04:00
|
|
|
require.NoError(t, err)
|
2017-09-15 12:33:01 -04:00
|
|
|
target := client.Target{}
|
|
|
|
_, err = GetSignableRoles(notaryRepo, &target)
|
|
|
|
assert.EqualError(t, err, "client is offline")
|
|
|
|
}
|