2017-09-14 17:58:28 -04:00
|
|
|
package trust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-08-30 18:36:58 -04:00
|
|
|
"github.com/distribution/reference"
|
2022-03-04 08:43:34 -05:00
|
|
|
"github.com/opencontainers/go-digest"
|
2017-10-30 12:21:41 -04:00
|
|
|
"github.com/theupdateframework/notary/client"
|
|
|
|
"github.com/theupdateframework/notary/passphrase"
|
|
|
|
"github.com/theupdateframework/notary/trustpinning"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-09-14 17:58:28 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetTag(t *testing.T) {
|
|
|
|
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
tag := getTag(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("", tag))
|
2017-09-14 17:58:28 -04:00
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine:latest")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
tag = getTag(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(tag, "latest"))
|
2017-09-14 17:58:28 -04:00
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
tag = getTag(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(tag, ""))
|
2017-09-14 17:58:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetDigest(t *testing.T) {
|
|
|
|
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
d := getDigest(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d))
|
2017-09-14 17:58:28 -04:00
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine:latest")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
d = getDigest(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(digest.Digest(""), d))
|
2017-09-14 17:58:28 -04:00
|
|
|
|
|
|
|
ref, err = reference.ParseNormalizedNamed("alpine")
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-14 17:58:28 -04:00
|
|
|
d = getDigest(ref)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(digest.Digest(""), d))
|
2017-09-14 17:58:28 -04:00
|
|
|
}
|
2017-09-15 12:33:01 -04:00
|
|
|
|
|
|
|
func TestGetSignableRolesError(t *testing.T) {
|
2022-02-25 09:30:02 -05:00
|
|
|
notaryRepo, err := client.NewFileCachedRepository(t.TempDir(), "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-15 12:33:01 -04:00
|
|
|
target := client.Target{}
|
|
|
|
_, err = GetSignableRoles(notaryRepo, &target)
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, err, "client is offline")
|
2017-09-15 12:33:01 -04:00
|
|
|
}
|