2016-08-29 14:45:29 -04:00
|
|
|
package image
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/trust"
|
2016-09-08 13:11:39 -04:00
|
|
|
registrytypes "github.com/docker/docker/api/types/registry"
|
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"
|
2020-04-09 07:37:39 -04:00
|
|
|
"gotest.tools/v3/env"
|
2016-09-08 13:11:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestENVTrustServer(t *testing.T) {
|
2022-09-22 10:31:28 -04:00
|
|
|
env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "https://notary-test.example.com:5000"})
|
2016-09-08 13:11:39 -04:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2021-04-30 03:31:41 -04:00
|
|
|
expectedStr := "https://notary-test.example.com:5000"
|
2016-09-08 13:11:39 -04:00
|
|
|
if err != nil || output != expectedStr {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPENVTrustServer(t *testing.T) {
|
2022-09-22 10:31:28 -04:00
|
|
|
env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "http://notary-test.example.com:5000"})
|
2016-09-08 13:11:39 -04:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
2016-12-05 19:06:29 -05:00
|
|
|
_, err := trust.Server(indexInfo)
|
2016-09-08 13:11:39 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error with invalid scheme")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOfficialTrustServer(t *testing.T) {
|
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2018-03-27 17:11:29 -04:00
|
|
|
if err != nil || output != trust.NotaryServer {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", trust.NotaryServer, output)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNonOfficialTrustServer(t *testing.T) {
|
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2016-09-08 13:11:39 -04:00
|
|
|
expectedStr := "https://" + indexInfo.Name
|
|
|
|
if err != nil || output != expectedStr {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
|
|
}
|
|
|
|
}
|
2017-08-24 18:42:21 -04:00
|
|
|
|
|
|
|
func TestAddTargetToAllSignableRolesError(t *testing.T) {
|
2022-02-25 07:10:34 -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-08-24 18:42:21 -04:00
|
|
|
target := client.Target{}
|
|
|
|
err = AddTargetToAllSignableRoles(notaryRepo, &target)
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, err, "client is offline")
|
2017-08-24 18:42:21 -04:00
|
|
|
}
|