2016-08-29 14:45:29 -04:00
|
|
|
package image
|
2015-10-08 14:10:38 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
registrytypes "github.com/docker/docker/api/types/registry"
|
2016-12-05 19:06:29 -05:00
|
|
|
"github.com/docker/docker/cli/trust"
|
2015-10-08 14:10:38 -04:00
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func unsetENV() {
|
|
|
|
os.Unsetenv("DOCKER_CONTENT_TRUST")
|
|
|
|
os.Unsetenv("DOCKER_CONTENT_TRUST_SERVER")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestENVTrustServer(t *testing.T) {
|
|
|
|
defer unsetENV()
|
2015-12-11 21:14:52 -05:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
2015-10-08 14:10:38 -04:00
|
|
|
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil {
|
|
|
|
t.Fatal("Failed to set ENV variable")
|
|
|
|
}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2015-10-08 14:10:38 -04:00
|
|
|
expectedStr := "https://notary-test.com:5000"
|
|
|
|
if err != nil || output != expectedStr {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPENVTrustServer(t *testing.T) {
|
|
|
|
defer unsetENV()
|
2015-12-11 21:14:52 -05:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
2015-10-08 14:10:38 -04:00
|
|
|
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil {
|
|
|
|
t.Fatal("Failed to set ENV variable")
|
|
|
|
}
|
2016-12-05 19:06:29 -05:00
|
|
|
_, err := trust.Server(indexInfo)
|
2015-10-08 14:10:38 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error with invalid scheme")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOfficialTrustServer(t *testing.T) {
|
2015-12-11 21:14:52 -05:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2015-10-08 14:10:38 -04:00
|
|
|
if err != nil || output != registry.NotaryServer {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNonOfficialTrustServer(t *testing.T) {
|
2015-12-11 21:14:52 -05:00
|
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false}
|
2016-12-05 19:06:29 -05:00
|
|
|
output, err := trust.Server(indexInfo)
|
2015-10-08 14:10:38 -04:00
|
|
|
expectedStr := "https://" + indexInfo.Name
|
|
|
|
if err != nil || output != expectedStr {
|
|
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
|
|
}
|
|
|
|
}
|