docker_cli_push_test.go 21 KB

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