docker_cli_push_test.go 21 KB

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