docker_cli_push_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. package main
  2. import (
  3. "archive/tar"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "os/exec"
  8. "path/filepath"
  9. "strings"
  10. "time"
  11. "github.com/docker/docker/cliconfig"
  12. "github.com/docker/docker/pkg/integration/checker"
  13. "github.com/go-check/check"
  14. )
  15. // Pushing an image to a private registry.
  16. func testPushBusyboxImage(c *check.C) {
  17. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  18. // tag the image to upload it to the private registry
  19. dockerCmd(c, "tag", "busybox", repoName)
  20. // push the image to the registry
  21. dockerCmd(c, "push", repoName)
  22. }
  23. func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
  24. testPushBusyboxImage(c)
  25. }
  26. func (s *DockerSchema1RegistrySuite) TestPushBusyboxImage(c *check.C) {
  27. testPushBusyboxImage(c)
  28. }
  29. // pushing an image without a prefix should throw an error
  30. func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
  31. out, _, err := dockerCmdWithError("push", "busybox")
  32. c.Assert(err, check.NotNil, check.Commentf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out))
  33. }
  34. func testPushUntagged(c *check.C) {
  35. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  36. expected := "Repository does not exist"
  37. out, _, err := dockerCmdWithError("push", repoName)
  38. c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
  39. c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
  40. }
  41. func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
  42. testPushUntagged(c)
  43. }
  44. func (s *DockerSchema1RegistrySuite) TestPushUntagged(c *check.C) {
  45. testPushUntagged(c)
  46. }
  47. func testPushBadTag(c *check.C) {
  48. repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
  49. expected := "does not exist"
  50. out, _, err := dockerCmdWithError("push", repoName)
  51. c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
  52. c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
  53. }
  54. func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
  55. testPushBadTag(c)
  56. }
  57. func (s *DockerSchema1RegistrySuite) TestPushBadTag(c *check.C) {
  58. testPushBadTag(c)
  59. }
  60. func testPushMultipleTags(c *check.C) {
  61. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  62. repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
  63. repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
  64. // tag the image and upload it to the private registry
  65. dockerCmd(c, "tag", "busybox", repoTag1)
  66. dockerCmd(c, "tag", "busybox", repoTag2)
  67. dockerCmd(c, "push", repoName)
  68. // Ensure layer list is equivalent for repoTag1 and repoTag2
  69. out1, _ := dockerCmd(c, "pull", repoTag1)
  70. imageAlreadyExists := ": Image already exists"
  71. var out1Lines []string
  72. for _, outputLine := range strings.Split(out1, "\n") {
  73. if strings.Contains(outputLine, imageAlreadyExists) {
  74. out1Lines = append(out1Lines, outputLine)
  75. }
  76. }
  77. out2, _ := dockerCmd(c, "pull", repoTag2)
  78. var out2Lines []string
  79. for _, outputLine := range strings.Split(out2, "\n") {
  80. if strings.Contains(outputLine, imageAlreadyExists) {
  81. out1Lines = append(out1Lines, outputLine)
  82. }
  83. }
  84. c.Assert(out2Lines, checker.HasLen, len(out1Lines))
  85. for i := range out1Lines {
  86. c.Assert(out1Lines[i], checker.Equals, out2Lines[i])
  87. }
  88. }
  89. func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
  90. testPushMultipleTags(c)
  91. }
  92. func (s *DockerSchema1RegistrySuite) TestPushMultipleTags(c *check.C) {
  93. testPushMultipleTags(c)
  94. }
  95. func testPushEmptyLayer(c *check.C) {
  96. repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
  97. emptyTarball, err := ioutil.TempFile("", "empty_tarball")
  98. c.Assert(err, check.IsNil, check.Commentf("Unable to create test file"))
  99. tw := tar.NewWriter(emptyTarball)
  100. err = tw.Close()
  101. c.Assert(err, check.IsNil, check.Commentf("Error creating empty tarball"))
  102. freader, err := os.Open(emptyTarball.Name())
  103. c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball"))
  104. importCmd := exec.Command(dockerBinary, "import", "-", repoName)
  105. importCmd.Stdin = freader
  106. out, _, err := runCommandWithOutput(importCmd)
  107. c.Assert(err, check.IsNil, check.Commentf("import failed: %q", out))
  108. // Now verify we can push it
  109. out, _, err = dockerCmdWithError("push", repoName)
  110. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out))
  111. }
  112. func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
  113. testPushEmptyLayer(c)
  114. }
  115. func (s *DockerSchema1RegistrySuite) TestPushEmptyLayer(c *check.C) {
  116. testPushEmptyLayer(c)
  117. }
  118. func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *check.C) {
  119. sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  120. // tag the image to upload it to the private registry
  121. dockerCmd(c, "tag", "busybox", sourceRepoName)
  122. // push the image to the registry
  123. out1, _, err := dockerCmdWithError("push", sourceRepoName)
  124. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1))
  125. // ensure that none of the layers were mounted from another repository during push
  126. c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false)
  127. destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL)
  128. // retag the image to upload the same layers to another repo in the same registry
  129. dockerCmd(c, "tag", "busybox", destRepoName)
  130. // push the image to the registry
  131. out2, _, err := dockerCmdWithError("push", destRepoName)
  132. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2))
  133. // ensure that layers were mounted from the first repo during push
  134. c.Assert(strings.Contains(out2, "Mounted from dockercli/busybox"), check.Equals, true)
  135. // ensure that we can pull and run the cross-repo-pushed repository
  136. dockerCmd(c, "rmi", destRepoName)
  137. dockerCmd(c, "pull", destRepoName)
  138. out3, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world")
  139. c.Assert(out3, check.Equals, "hello world")
  140. }
  141. func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c *check.C) {
  142. sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  143. // tag the image to upload it to the private registry
  144. dockerCmd(c, "tag", "busybox", sourceRepoName)
  145. // push the image to the registry
  146. out1, _, err := dockerCmdWithError("push", sourceRepoName)
  147. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1))
  148. // ensure that none of the layers were mounted from another repository during push
  149. c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false)
  150. destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL)
  151. // retag the image to upload the same layers to another repo in the same registry
  152. dockerCmd(c, "tag", "busybox", destRepoName)
  153. // push the image to the registry
  154. out2, _, err := dockerCmdWithError("push", destRepoName)
  155. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2))
  156. // schema1 registry should not support cross-repo layer mounts, so ensure that this does not happen
  157. c.Assert(strings.Contains(out2, "Mounted from dockercli/busybox"), check.Equals, false)
  158. // ensure that we can pull and run the second pushed repository
  159. dockerCmd(c, "rmi", destRepoName)
  160. dockerCmd(c, "pull", destRepoName)
  161. out3, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world")
  162. c.Assert(out3, check.Equals, "hello world")
  163. }
  164. func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
  165. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  166. // tag the image and upload it to the private registry
  167. dockerCmd(c, "tag", "busybox", repoName)
  168. pushCmd := exec.Command(dockerBinary, "push", repoName)
  169. s.trustedCmd(pushCmd)
  170. out, _, err := runCommandWithOutput(pushCmd)
  171. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  172. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  173. // Try pull after push
  174. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  175. s.trustedCmd(pullCmd)
  176. out, _, err = runCommandWithOutput(pullCmd)
  177. c.Assert(err, check.IsNil, check.Commentf(out))
  178. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  179. }
  180. func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
  181. repoName := fmt.Sprintf("%v/dockerclienv/trusted:latest", privateRegistryURL)
  182. // tag the image and upload it to the private registry
  183. dockerCmd(c, "tag", "busybox", repoName)
  184. pushCmd := exec.Command(dockerBinary, "push", repoName)
  185. s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678")
  186. out, _, err := runCommandWithOutput(pushCmd)
  187. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  188. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  189. // Try pull after push
  190. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  191. s.trustedCmd(pullCmd)
  192. out, _, err = runCommandWithOutput(pullCmd)
  193. c.Assert(err, check.IsNil, check.Commentf(out))
  194. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  195. }
  196. // This test ensures backwards compatibility with old ENV variables. Should be
  197. // deprecated by 1.10
  198. func (s *DockerTrustSuite) TestTrustedPushWithDeprecatedEnvPasswords(c *check.C) {
  199. repoName := fmt.Sprintf("%v/dockercli/trusteddeprecated:latest", privateRegistryURL)
  200. // tag the image and upload it to the private registry
  201. dockerCmd(c, "tag", "busybox", repoName)
  202. pushCmd := exec.Command(dockerBinary, "push", repoName)
  203. s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "12345678")
  204. out, _, err := runCommandWithOutput(pushCmd)
  205. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  206. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  207. }
  208. func (s *DockerTrustSuite) TestTrustedPushWithFailingServer(c *check.C) {
  209. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  210. // tag the image and upload it to the private registry
  211. dockerCmd(c, "tag", "busybox", repoName)
  212. pushCmd := exec.Command(dockerBinary, "push", repoName)
  213. s.trustedCmdWithServer(pushCmd, "https://example.com:81/")
  214. out, _, err := runCommandWithOutput(pushCmd)
  215. c.Assert(err, check.NotNil, check.Commentf("Missing error while running trusted push w/ no server"))
  216. c.Assert(out, checker.Contains, "error contacting notary server", check.Commentf("Missing expected output on trusted push"))
  217. }
  218. func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
  219. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  220. // tag the image and upload it to the private registry
  221. dockerCmd(c, "tag", "busybox", repoName)
  222. pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName)
  223. s.trustedCmdWithServer(pushCmd, "https://example.com/")
  224. out, _, err := runCommandWithOutput(pushCmd)
  225. c.Assert(err, check.IsNil, check.Commentf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out))
  226. c.Assert(out, check.Not(checker.Contains), "Error establishing connection to notary repository", check.Commentf("Missing expected output on trusted push with --disable-content-trust:"))
  227. }
  228. func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
  229. repoName := fmt.Sprintf("%v/dockerclitag/trusted:latest", privateRegistryURL)
  230. // tag the image and upload it to the private registry
  231. dockerCmd(c, "tag", "busybox", repoName)
  232. dockerCmd(c, "push", repoName)
  233. pushCmd := exec.Command(dockerBinary, "push", repoName)
  234. s.trustedCmd(pushCmd)
  235. out, _, err := runCommandWithOutput(pushCmd)
  236. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  237. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  238. // Try pull after push
  239. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  240. s.trustedCmd(pullCmd)
  241. out, _, err = runCommandWithOutput(pullCmd)
  242. c.Assert(err, check.IsNil, check.Commentf(out))
  243. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  244. }
  245. func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
  246. repoName := fmt.Sprintf("%v/dockerclipushpush/trusted:latest", privateRegistryURL)
  247. // tag the image and upload it to the private registry
  248. dockerCmd(c, "tag", "busybox", repoName)
  249. // Do a trusted push
  250. pushCmd := exec.Command(dockerBinary, "push", repoName)
  251. s.trustedCmd(pushCmd)
  252. out, _, err := runCommandWithOutput(pushCmd)
  253. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  254. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  255. // Do another trusted push
  256. pushCmd = exec.Command(dockerBinary, "push", repoName)
  257. s.trustedCmd(pushCmd)
  258. out, _, err = runCommandWithOutput(pushCmd)
  259. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  260. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  261. dockerCmd(c, "rmi", repoName)
  262. // Try pull to ensure the double push did not break our ability to pull
  263. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  264. s.trustedCmd(pullCmd)
  265. out, _, err = runCommandWithOutput(pullCmd)
  266. c.Assert(err, check.IsNil, check.Commentf("Error running trusted pull: %s\n%s", err, out))
  267. c.Assert(out, checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted pull with --disable-content-trust"))
  268. }
  269. func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
  270. repoName := fmt.Sprintf("%v/dockercliincorretpwd/trusted:latest", privateRegistryURL)
  271. // tag the image and upload it to the private registry
  272. dockerCmd(c, "tag", "busybox", repoName)
  273. // Push with default passphrases
  274. pushCmd := exec.Command(dockerBinary, "push", repoName)
  275. s.trustedCmd(pushCmd)
  276. out, _, err := runCommandWithOutput(pushCmd)
  277. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  278. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out))
  279. // Push with wrong passphrases
  280. pushCmd = exec.Command(dockerBinary, "push", repoName)
  281. s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
  282. out, _, err = runCommandWithOutput(pushCmd)
  283. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
  284. c.Assert(out, checker.Contains, "could not find necessary signing keys", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
  285. }
  286. // This test ensures backwards compatibility with old ENV variables. Should be
  287. // deprecated by 1.10
  288. func (s *DockerTrustSuite) TestTrustedPushWithIncorrectDeprecatedPassphraseForNonRoot(c *check.C) {
  289. repoName := fmt.Sprintf("%v/dockercliincorretdeprecatedpwd/trusted:latest", privateRegistryURL)
  290. // tag the image and upload it to the private registry
  291. dockerCmd(c, "tag", "busybox", repoName)
  292. // Push with default passphrases
  293. pushCmd := exec.Command(dockerBinary, "push", repoName)
  294. s.trustedCmd(pushCmd)
  295. out, _, err := runCommandWithOutput(pushCmd)
  296. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  297. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  298. // Push with wrong passphrases
  299. pushCmd = exec.Command(dockerBinary, "push", repoName)
  300. s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "87654321")
  301. out, _, err = runCommandWithOutput(pushCmd)
  302. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
  303. c.Assert(out, checker.Contains, "could not find necessary signing keys", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
  304. }
  305. func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
  306. c.Skip("Currently changes system time, causing instability")
  307. repoName := fmt.Sprintf("%v/dockercliexpiredsnapshot/trusted:latest", privateRegistryURL)
  308. // tag the image and upload it to the private registry
  309. dockerCmd(c, "tag", "busybox", repoName)
  310. // Push with default passphrases
  311. pushCmd := exec.Command(dockerBinary, "push", repoName)
  312. s.trustedCmd(pushCmd)
  313. out, _, err := runCommandWithOutput(pushCmd)
  314. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  315. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  316. // Snapshots last for three years. This should be expired
  317. fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
  318. runAtDifferentDate(fourYearsLater, func() {
  319. // Push with wrong passphrases
  320. pushCmd = exec.Command(dockerBinary, "push", repoName)
  321. s.trustedCmd(pushCmd)
  322. out, _, err = runCommandWithOutput(pushCmd)
  323. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with expired snapshot: \n%s", out))
  324. c.Assert(out, checker.Contains, "repository out-of-date", check.Commentf("Missing expected output on trusted push with expired snapshot"))
  325. })
  326. }
  327. func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
  328. c.Skip("Currently changes system time, causing instability")
  329. repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppush/trusted:latest", privateRegistryURL)
  330. // tag the image and upload it to the private registry
  331. dockerCmd(c, "tag", "busybox", repoName)
  332. // Push with default passphrases
  333. pushCmd := exec.Command(dockerBinary, "push", repoName)
  334. s.trustedCmd(pushCmd)
  335. out, _, err := runCommandWithOutput(pushCmd)
  336. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  337. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  338. // The timestamps expire in two weeks. Lets check three
  339. threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
  340. // Should succeed because the server transparently re-signs one
  341. runAtDifferentDate(threeWeeksLater, func() {
  342. pushCmd := exec.Command(dockerBinary, "push", repoName)
  343. s.trustedCmd(pushCmd)
  344. out, _, err := runCommandWithOutput(pushCmd)
  345. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  346. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp"))
  347. })
  348. }
  349. func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegation(c *check.C) {
  350. repoName := fmt.Sprintf("%v/dockerclireleasedelegation/trusted", privateRegistryURL)
  351. targetName := fmt.Sprintf("%s:latest", repoName)
  352. pwd := "12345678"
  353. s.setupDelegations(c, repoName, pwd)
  354. // tag the image and upload it to the private registry
  355. dockerCmd(c, "tag", "busybox", targetName)
  356. pushCmd := exec.Command(dockerBinary, "-D", "push", targetName)
  357. s.trustedCmdWithPassphrases(pushCmd, pwd, pwd)
  358. out, _, err := runCommandWithOutput(pushCmd)
  359. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  360. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  361. // Try pull after push
  362. pullCmd := exec.Command(dockerBinary, "pull", targetName)
  363. s.trustedCmd(pullCmd)
  364. out, _, err = runCommandWithOutput(pullCmd)
  365. c.Assert(err, check.IsNil, check.Commentf(out))
  366. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  367. // check to make sure that the target has been added to targets/releases and not targets
  368. contents, err := ioutil.ReadFile(filepath.Join(cliconfig.ConfigDir(), "trust/tuf", repoName, "metadata/targets.json"))
  369. c.Assert(err, check.IsNil, check.Commentf("Unable to read targets metadata"))
  370. c.Assert(strings.Contains(string(contents), `"latest"`), checker.False, check.Commentf(string(contents)))
  371. contents, err = ioutil.ReadFile(filepath.Join(cliconfig.ConfigDir(), "trust/tuf", repoName, "metadata/targets/releases.json"))
  372. c.Assert(err, check.IsNil, check.Commentf("Unable to read targets/releases metadata"))
  373. c.Assert(string(contents), checker.Contains, `"latest"`, check.Commentf(string(contents)))
  374. }