docker_cli_push_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. testRequires(c, NotArm)
  120. sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  121. // tag the image to upload it to the private registry
  122. dockerCmd(c, "tag", "busybox", sourceRepoName)
  123. // push the image to the registry
  124. out1, _, err := dockerCmdWithError("push", sourceRepoName)
  125. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1))
  126. // ensure that none of the layers were mounted from another repository during push
  127. c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false)
  128. destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL)
  129. // retag the image to upload the same layers to another repo in the same registry
  130. dockerCmd(c, "tag", "busybox", destRepoName)
  131. // push the image to the registry
  132. out2, _, err := dockerCmdWithError("push", destRepoName)
  133. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2))
  134. // ensure that layers were mounted from the first repo during push
  135. c.Assert(strings.Contains(out2, "Mounted from dockercli/busybox"), check.Equals, true)
  136. // ensure that we can pull and run the cross-repo-pushed repository
  137. dockerCmd(c, "rmi", destRepoName)
  138. dockerCmd(c, "pull", destRepoName)
  139. out3, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world")
  140. c.Assert(out3, check.Equals, "hello world")
  141. }
  142. func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c *check.C) {
  143. sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  144. // tag the image to upload it to the private registry
  145. dockerCmd(c, "tag", "busybox", sourceRepoName)
  146. // push the image to the registry
  147. out1, _, err := dockerCmdWithError("push", sourceRepoName)
  148. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1))
  149. // ensure that none of the layers were mounted from another repository during push
  150. c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false)
  151. destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL)
  152. // retag the image to upload the same layers to another repo in the same registry
  153. dockerCmd(c, "tag", "busybox", destRepoName)
  154. // push the image to the registry
  155. out2, _, err := dockerCmdWithError("push", destRepoName)
  156. c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2))
  157. // schema1 registry should not support cross-repo layer mounts, so ensure that this does not happen
  158. c.Assert(strings.Contains(out2, "Mounted from dockercli/busybox"), check.Equals, false)
  159. // ensure that we can pull and run the second pushed repository
  160. dockerCmd(c, "rmi", destRepoName)
  161. dockerCmd(c, "pull", destRepoName)
  162. out3, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world")
  163. c.Assert(out3, check.Equals, "hello world")
  164. }
  165. func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
  166. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  167. // tag the image and upload it to the private registry
  168. dockerCmd(c, "tag", "busybox", repoName)
  169. pushCmd := exec.Command(dockerBinary, "push", repoName)
  170. s.trustedCmd(pushCmd)
  171. out, _, err := runCommandWithOutput(pushCmd)
  172. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  173. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  174. // Try pull after push
  175. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  176. s.trustedCmd(pullCmd)
  177. out, _, err = runCommandWithOutput(pullCmd)
  178. c.Assert(err, check.IsNil, check.Commentf(out))
  179. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  180. }
  181. func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
  182. repoName := fmt.Sprintf("%v/dockerclienv/trusted:latest", privateRegistryURL)
  183. // tag the image and upload it to the private registry
  184. dockerCmd(c, "tag", "busybox", repoName)
  185. pushCmd := exec.Command(dockerBinary, "push", repoName)
  186. s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678")
  187. out, _, err := runCommandWithOutput(pushCmd)
  188. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  189. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  190. // Try pull after push
  191. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  192. s.trustedCmd(pullCmd)
  193. out, _, err = runCommandWithOutput(pullCmd)
  194. c.Assert(err, check.IsNil, check.Commentf(out))
  195. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  196. }
  197. // This test ensures backwards compatibility with old ENV variables. Should be
  198. // deprecated by 1.10
  199. func (s *DockerTrustSuite) TestTrustedPushWithDeprecatedEnvPasswords(c *check.C) {
  200. repoName := fmt.Sprintf("%v/dockercli/trusteddeprecated:latest", privateRegistryURL)
  201. // tag the image and upload it to the private registry
  202. dockerCmd(c, "tag", "busybox", repoName)
  203. pushCmd := exec.Command(dockerBinary, "push", repoName)
  204. s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "12345678")
  205. out, _, err := runCommandWithOutput(pushCmd)
  206. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  207. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  208. }
  209. func (s *DockerTrustSuite) TestTrustedPushWithFailingServer(c *check.C) {
  210. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  211. // tag the image and upload it to the private registry
  212. dockerCmd(c, "tag", "busybox", repoName)
  213. pushCmd := exec.Command(dockerBinary, "push", repoName)
  214. s.trustedCmdWithServer(pushCmd, "https://example.com:81/")
  215. out, _, err := runCommandWithOutput(pushCmd)
  216. c.Assert(err, check.NotNil, check.Commentf("Missing error while running trusted push w/ no server"))
  217. c.Assert(out, checker.Contains, "error contacting notary server", check.Commentf("Missing expected output on trusted push"))
  218. }
  219. func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
  220. repoName := fmt.Sprintf("%v/dockercli/trusted:latest", privateRegistryURL)
  221. // tag the image and upload it to the private registry
  222. dockerCmd(c, "tag", "busybox", repoName)
  223. pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName)
  224. s.trustedCmdWithServer(pushCmd, "https://example.com/")
  225. out, _, err := runCommandWithOutput(pushCmd)
  226. c.Assert(err, check.IsNil, check.Commentf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out))
  227. 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:"))
  228. }
  229. func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
  230. repoName := fmt.Sprintf("%v/dockerclitag/trusted:latest", privateRegistryURL)
  231. // tag the image and upload it to the private registry
  232. dockerCmd(c, "tag", "busybox", repoName)
  233. dockerCmd(c, "push", repoName)
  234. pushCmd := exec.Command(dockerBinary, "push", repoName)
  235. s.trustedCmd(pushCmd)
  236. out, _, err := runCommandWithOutput(pushCmd)
  237. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  238. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  239. // Try pull after push
  240. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  241. s.trustedCmd(pullCmd)
  242. out, _, err = runCommandWithOutput(pullCmd)
  243. c.Assert(err, check.IsNil, check.Commentf(out))
  244. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  245. }
  246. func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
  247. repoName := fmt.Sprintf("%v/dockerclipushpush/trusted:latest", privateRegistryURL)
  248. // tag the image and upload it to the private registry
  249. dockerCmd(c, "tag", "busybox", repoName)
  250. // Do a trusted push
  251. pushCmd := exec.Command(dockerBinary, "push", repoName)
  252. s.trustedCmd(pushCmd)
  253. out, _, err := runCommandWithOutput(pushCmd)
  254. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  255. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  256. // Do another trusted push
  257. pushCmd = exec.Command(dockerBinary, "push", repoName)
  258. s.trustedCmd(pushCmd)
  259. out, _, err = runCommandWithOutput(pushCmd)
  260. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  261. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  262. dockerCmd(c, "rmi", repoName)
  263. // Try pull to ensure the double push did not break our ability to pull
  264. pullCmd := exec.Command(dockerBinary, "pull", repoName)
  265. s.trustedCmd(pullCmd)
  266. out, _, err = runCommandWithOutput(pullCmd)
  267. c.Assert(err, check.IsNil, check.Commentf("Error running trusted pull: %s\n%s", err, out))
  268. c.Assert(out, checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted pull with --disable-content-trust"))
  269. }
  270. func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
  271. repoName := fmt.Sprintf("%v/dockercliincorretpwd/trusted:latest", privateRegistryURL)
  272. // tag the image and upload it to the private registry
  273. dockerCmd(c, "tag", "busybox", repoName)
  274. // Push with default passphrases
  275. pushCmd := exec.Command(dockerBinary, "push", repoName)
  276. s.trustedCmd(pushCmd)
  277. out, _, err := runCommandWithOutput(pushCmd)
  278. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  279. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out))
  280. // Push with wrong passphrases
  281. pushCmd = exec.Command(dockerBinary, "push", repoName)
  282. s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
  283. out, _, err = runCommandWithOutput(pushCmd)
  284. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
  285. c.Assert(out, checker.Contains, "could not find necessary signing keys", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
  286. }
  287. // This test ensures backwards compatibility with old ENV variables. Should be
  288. // deprecated by 1.10
  289. func (s *DockerTrustSuite) TestTrustedPushWithIncorrectDeprecatedPassphraseForNonRoot(c *check.C) {
  290. repoName := fmt.Sprintf("%v/dockercliincorretdeprecatedpwd/trusted:latest", privateRegistryURL)
  291. // tag the image and upload it to the private registry
  292. dockerCmd(c, "tag", "busybox", repoName)
  293. // Push with default passphrases
  294. pushCmd := exec.Command(dockerBinary, "push", repoName)
  295. s.trustedCmd(pushCmd)
  296. out, _, err := runCommandWithOutput(pushCmd)
  297. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  298. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  299. // Push with wrong passphrases
  300. pushCmd = exec.Command(dockerBinary, "push", repoName)
  301. s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "87654321")
  302. out, _, err = runCommandWithOutput(pushCmd)
  303. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
  304. c.Assert(out, checker.Contains, "could not find necessary signing keys", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
  305. }
  306. func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
  307. c.Skip("Currently changes system time, causing instability")
  308. repoName := fmt.Sprintf("%v/dockercliexpiredsnapshot/trusted:latest", privateRegistryURL)
  309. // tag the image and upload it to the private registry
  310. dockerCmd(c, "tag", "busybox", repoName)
  311. // Push with default passphrases
  312. pushCmd := exec.Command(dockerBinary, "push", repoName)
  313. s.trustedCmd(pushCmd)
  314. out, _, err := runCommandWithOutput(pushCmd)
  315. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  316. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  317. // Snapshots last for three years. This should be expired
  318. fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
  319. runAtDifferentDate(fourYearsLater, func() {
  320. // Push with wrong passphrases
  321. pushCmd = exec.Command(dockerBinary, "push", repoName)
  322. s.trustedCmd(pushCmd)
  323. out, _, err = runCommandWithOutput(pushCmd)
  324. c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with expired snapshot: \n%s", out))
  325. c.Assert(out, checker.Contains, "repository out-of-date", check.Commentf("Missing expected output on trusted push with expired snapshot"))
  326. })
  327. }
  328. func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
  329. c.Skip("Currently changes system time, causing instability")
  330. repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppush/trusted:latest", privateRegistryURL)
  331. // tag the image and upload it to the private registry
  332. dockerCmd(c, "tag", "busybox", repoName)
  333. // Push with default passphrases
  334. pushCmd := exec.Command(dockerBinary, "push", repoName)
  335. s.trustedCmd(pushCmd)
  336. out, _, err := runCommandWithOutput(pushCmd)
  337. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  338. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
  339. // The timestamps expire in two weeks. Lets check three
  340. threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
  341. // Should succeed because the server transparently re-signs one
  342. runAtDifferentDate(threeWeeksLater, func() {
  343. pushCmd := exec.Command(dockerBinary, "push", repoName)
  344. s.trustedCmd(pushCmd)
  345. out, _, err := runCommandWithOutput(pushCmd)
  346. c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
  347. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp"))
  348. })
  349. }
  350. func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegation(c *check.C) {
  351. repoName := fmt.Sprintf("%v/dockerclireleasedelegation/trusted", privateRegistryURL)
  352. targetName := fmt.Sprintf("%s:latest", repoName)
  353. pwd := "12345678"
  354. s.setupDelegations(c, repoName, pwd)
  355. // tag the image and upload it to the private registry
  356. dockerCmd(c, "tag", "busybox", targetName)
  357. pushCmd := exec.Command(dockerBinary, "-D", "push", targetName)
  358. s.trustedCmdWithPassphrases(pushCmd, pwd, pwd)
  359. out, _, err := runCommandWithOutput(pushCmd)
  360. c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
  361. c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
  362. // Try pull after push
  363. pullCmd := exec.Command(dockerBinary, "pull", targetName)
  364. s.trustedCmd(pullCmd)
  365. out, _, err = runCommandWithOutput(pullCmd)
  366. c.Assert(err, check.IsNil, check.Commentf(out))
  367. c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
  368. // check to make sure that the target has been added to targets/releases and not targets
  369. contents, err := ioutil.ReadFile(filepath.Join(cliconfig.ConfigDir(), "trust/tuf", repoName, "metadata/targets.json"))
  370. c.Assert(err, check.IsNil, check.Commentf("Unable to read targets metadata"))
  371. c.Assert(strings.Contains(string(contents), `"latest"`), checker.False, check.Commentf(string(contents)))
  372. contents, err = ioutil.ReadFile(filepath.Join(cliconfig.ConfigDir(), "trust/tuf", repoName, "metadata/targets/releases.json"))
  373. c.Assert(err, check.IsNil, check.Commentf("Unable to read targets/releases metadata"))
  374. c.Assert(string(contents), checker.Contains, `"latest"`, check.Commentf(string(contents)))
  375. }