func (s *DockerRegistrySuite) TestPullConflict(c *check.C) {
	repoName := privateRegistryURL + "/dockercli/conflict"

	_, err := buildImage(repoName, `
	    FROM scratch
	    ENV IMAGE conflict
	    CMD echo conflict
	`, true)
	if err != nil {
		c.Fatal(err)
	}

	dockerCmd(c, "push", repoName)

	// Pull to make it content-addressable
	dockerCmd(c, "rmi", repoName)
	dockerCmd(c, "pull", repoName)

	IDBeforeLoad := imageID(c, repoName)

	// Load/save to turn this into an unverified image with the same ID
	tmpDir, err := ioutil.TempDir("", "conflict-save-output")
	if err != nil {
		c.Errorf("failed to create temporary directory: %s", err)
	}
	defer os.RemoveAll(tmpDir)

	tarFile := filepath.Join(tmpDir, "repo.tar")

	dockerCmd(c, "save", "-o", tarFile, repoName)
	dockerCmd(c, "rmi", repoName)
	dockerCmd(c, "load", "-i", tarFile)

	// Check that the the ID is the same after save/load.
	IDAfterLoad := imageID(c, repoName)

	if IDAfterLoad != IDBeforeLoad {
		c.Fatal("image's ID should be the same after save/load")
	}

	// Repull
	dockerCmd(c, "pull", repoName)

	// Check that the ID is now different because of the conflict.
	IDAfterPull1 := imageID(c, repoName)

	// Expect the new ID to be SHA256(oldID)
	expectedIDDigest, err := digest.FromBytes([]byte(IDBeforeLoad))
	if err != nil {
		c.Fatalf("digest error: %v", err)
	}
	expectedID := expectedIDDigest.Hex()
	if IDAfterPull1 != expectedID {
		c.Fatalf("image's ID should have changed on pull to %s (got %s)", expectedID, IDAfterPull1)
	}

	// A second pull should use the new ID again.
	dockerCmd(c, "pull", repoName)

	IDAfterPull2 := imageID(c, repoName)

	if IDAfterPull2 != IDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a repull")
	}
}
// TestPullConflict provides coverage of the situation where a computed
// strongID conflicts with some unverifiable data in the graph.
TestPullConflict provides coverage of the situation where a computed
strongID conflicts with some unverifiable data in the graph.
// TestPullConflict provides coverage of the situation where a computed // strongID conflicts with some unverifiable data in the graph .
func (s *DockerRegistrySuite) TestPullConflict(c *check.C) {
	repoName := privateRegistryURL + "/dockercli/conflict"
	_, err := buildImage(repoName, `
	    FROM scratch
	    ENV IMAGE conflict
	    CMD echo conflict
	`, true)
	if err != nil {
		c.Fatal(err)
	}
	dockerCmd(c, "push", repoName)
	dockerCmd(c, "rmi", repoName)
	dockerCmd(c, "pull", repoName)
	IDBeforeLoad := imageID(c, repoName)
	tmpDir, err := ioutil.TempDir("", "conflict-save-output")
	if err != nil {
		c.Errorf("failed to create temporary directory: %s", err)
	}
	defer os.RemoveAll(tmpDir)
	tarFile := filepath.Join(tmpDir, "repo.tar")
	dockerCmd(c, "save", "-o", tarFile, repoName)
	dockerCmd(c, "rmi", repoName)
	dockerCmd(c, "load", "-i", tarFile)
	IDAfterLoad := imageID(c, repoName)
	if IDAfterLoad != IDBeforeLoad {
		c.Fatal("image's ID should be the same after save/load")
	}
	dockerCmd(c, "pull", repoName)
	IDAfterPull1 := imageID(c, repoName)
	expectedIDDigest, err := digest.FromBytes([]byte(IDBeforeLoad))
	if err != nil {
		c.Fatalf("digest error: %v", err)
	}
	expectedID := expectedIDDigest.Hex()
	if IDAfterPull1 != expectedID {
		c.Fatalf("image's ID should have changed on pull to %s (got %s)", expectedID, IDAfterPull1)
	}
	dockerCmd(c, "pull", repoName)
	IDAfterPull2 := imageID(c, repoName)
	if IDAfterPull2 != IDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a repull")
	}
}
func ( s * DockerRegistrySuite ) TestPullConflict ( c * check . C ) { repoName := privateRegistryURL + " " _ , err := buildImage ( repoName , `
	    FROM scratch
	    ENV IMAGE conflict
	    CMD echo conflict
	` , true ) if err != nil { c . Fatal ( err ) } dockerCmd ( c , " " , repoName ) dockerCmd ( c , " " , repoName ) dockerCmd ( c , " " , repoName ) IDBeforeLoad := imageID ( c , repoName ) tmpDir , err := ioutil . TempDir ( " " , " " ) if err != nil { c . Errorf ( " " , err ) } defer os . RemoveAll ( tmpDir ) tarFile := filepath . Join ( tmpDir , " " ) dockerCmd ( c , " " , " " , tarFile , repoName ) dockerCmd ( c , " " , repoName ) dockerCmd ( c , " " , " " , tarFile ) IDAfterLoad := imageID ( c , repoName ) if IDAfterLoad != IDBeforeLoad { c . Fatal ( " " ) } dockerCmd ( c , " " , repoName ) IDAfterPull1 := imageID ( c , repoName ) expectedIDDigest , err := digest . FromBytes ( [ ] byte ( IDBeforeLoad ) ) if err != nil { c . Fatalf ( " " , err ) } expectedID := expectedIDDigest . Hex ( ) if IDAfterPull1 != expectedID { c . Fatalf ( " " , expectedID , IDAfterPull1 ) } dockerCmd ( c , " " , repoName ) IDAfterPull2 := imageID ( c , repoName ) if IDAfterPull2 != IDAfterPull1 { c . Fatal ( " " ) } }
TestPullConflict provides coverage of the situation where a computed
strongID conflicts with some unverifiable data in the graph.
TestPullConflict provides coverage of the situation where a computed strongID conflicts with some unverifiable data in the graph .
// Pull to make it content-addressable // Load/save to turn this into an unverified image with the same ID // Check that the the ID is the same after save/load. // Repull // Check that the ID is now different because of the conflict. // Expect the new ID to be SHA256(oldID) // A second pull should use the new ID again.