Signed-off-by: GoBella <caili_welcome@163.com>
| ... | ... |
@@ -4,9 +4,9 @@ import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"io/ioutil" |
| 6 | 6 |
"os/exec" |
| 7 |
- "strings" |
|
| 8 | 7 |
"time" |
| 9 | 8 |
|
| 9 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 10 | 10 |
"github.com/go-check/check" |
| 11 | 11 |
) |
| 12 | 12 |
|
| ... | ... |
@@ -17,27 +17,18 @@ func (s *DockerTrustSuite) TestTrustedPull(c *check.C) {
|
| 17 | 17 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 18 | 18 |
s.trustedCmd(pullCmd) |
| 19 | 19 |
out, _, err := runCommandWithOutput(pullCmd) |
| 20 |
- if err != nil {
|
|
| 21 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 22 |
- } |
|
| 23 | 20 |
|
| 24 |
- if !strings.Contains(string(out), "Tagging") {
|
|
| 25 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 26 |
- } |
|
| 21 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 22 |
+ c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) |
|
| 27 | 23 |
|
| 28 | 24 |
dockerCmd(c, "rmi", repoName) |
| 29 |
- |
|
| 30 | 25 |
// Try untrusted pull to ensure we pushed the tag to the registry |
| 31 | 26 |
pullCmd = exec.Command(dockerBinary, "pull", "--disable-content-trust=true", repoName) |
| 32 | 27 |
s.trustedCmd(pullCmd) |
| 33 | 28 |
out, _, err = runCommandWithOutput(pullCmd) |
| 34 |
- if err != nil {
|
|
| 35 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 36 |
- } |
|
| 29 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 30 |
+ c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out)) |
|
| 37 | 31 |
|
| 38 |
- if !strings.Contains(string(out), "Status: Downloaded") {
|
|
| 39 |
- c.Fatalf("Missing expected output on trusted pull with --disable-content-trust:\n%s", out)
|
|
| 40 |
- } |
|
| 41 | 32 |
} |
| 42 | 33 |
|
| 43 | 34 |
func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) {
|
| ... | ... |
@@ -47,13 +38,9 @@ func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) {
|
| 47 | 47 |
pullCmd := exec.Command(dockerBinary, "--config", "/tmp/docker-isolated", "pull", repoName) |
| 48 | 48 |
s.trustedCmd(pullCmd) |
| 49 | 49 |
out, _, err := runCommandWithOutput(pullCmd) |
| 50 |
- if err != nil {
|
|
| 51 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 52 |
- } |
|
| 53 | 50 |
|
| 54 |
- if !strings.Contains(string(out), "Tagging") {
|
|
| 55 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 56 |
- } |
|
| 51 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 52 |
+ c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(string(out))) |
|
| 57 | 53 |
|
| 58 | 54 |
dockerCmd(c, "rmi", repoName) |
| 59 | 55 |
} |
| ... | ... |
@@ -69,13 +56,9 @@ func (s *DockerTrustSuite) TestUntrustedPull(c *check.C) {
|
| 69 | 69 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 70 | 70 |
s.trustedCmd(pullCmd) |
| 71 | 71 |
out, _, err := runCommandWithOutput(pullCmd) |
| 72 |
- if err == nil {
|
|
| 73 |
- c.Fatalf("Error expected when running trusted pull with:\n%s", out)
|
|
| 74 |
- } |
|
| 75 | 72 |
|
| 76 |
- if !strings.Contains(string(out), "no trust data available") {
|
|
| 77 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 78 |
- } |
|
| 73 |
+ c.Assert(err, check.NotNil, check.Commentf(out)) |
|
| 74 |
+ c.Assert(string(out), checker.Contains, "no trust data available", check.Commentf(out)) |
|
| 79 | 75 |
} |
| 80 | 76 |
|
| 81 | 77 |
func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
|
| ... | ... |
@@ -90,13 +73,9 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
|
| 90 | 90 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 91 | 91 |
s.trustedCmd(pullCmd) |
| 92 | 92 |
out, _, err := runCommandWithOutput(pullCmd) |
| 93 |
- if err == nil {
|
|
| 94 |
- c.Fatalf("Error running trusted pull in the distant future: %s\n%s", err, out)
|
|
| 95 |
- } |
|
| 96 | 93 |
|
| 97 |
- if !strings.Contains(string(out), "could not validate the path to a trusted root") {
|
|
| 98 |
- c.Fatalf("Missing expected output on trusted pull in the distant future:\n%s", out)
|
|
| 99 |
- } |
|
| 94 |
+ c.Assert(err, check.NotNil, check.Commentf(out)) |
|
| 95 |
+ c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf(out)) |
|
| 100 | 96 |
}) |
| 101 | 97 |
|
| 102 | 98 |
runAtDifferentDate(elevenYearsFromNow, func() {
|
| ... | ... |
@@ -104,13 +83,9 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
|
| 104 | 104 |
pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName) |
| 105 | 105 |
s.trustedCmd(pullCmd) |
| 106 | 106 |
out, _, err := runCommandWithOutput(pullCmd) |
| 107 |
- if err != nil {
|
|
| 108 |
- c.Fatalf("Error running untrusted pull in the distant future: %s\n%s", err, out)
|
|
| 109 |
- } |
|
| 110 | 107 |
|
| 111 |
- if !strings.Contains(string(out), "Status: Downloaded") {
|
|
| 112 |
- c.Fatalf("Missing expected output on untrusted pull in the distant future:\n%s", out)
|
|
| 113 |
- } |
|
| 108 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 109 |
+ c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out)) |
|
| 114 | 110 |
}) |
| 115 | 111 |
} |
| 116 | 112 |
|
| ... | ... |
@@ -127,35 +102,25 @@ func (s *DockerTrustSuite) TestTrustedPullFromBadTrustServer(c *check.C) {
|
| 127 | 127 |
pushCmd := exec.Command(dockerBinary, "push", repoName) |
| 128 | 128 |
s.trustedCmd(pushCmd) |
| 129 | 129 |
out, _, err := runCommandWithOutput(pushCmd) |
| 130 |
- if err != nil {
|
|
| 131 |
- c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
|
| 132 |
- } |
|
| 133 |
- if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
| 134 |
- c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
| 135 |
- } |
|
| 136 | 130 |
|
| 131 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 132 |
+ c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) |
|
| 137 | 133 |
dockerCmd(c, "rmi", repoName) |
| 138 | 134 |
|
| 139 | 135 |
// Try pull |
| 140 | 136 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 141 | 137 |
s.trustedCmd(pullCmd) |
| 142 | 138 |
out, _, err = runCommandWithOutput(pullCmd) |
| 143 |
- if err != nil {
|
|
| 144 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 145 |
- } |
|
| 146 |
- |
|
| 147 |
- if !strings.Contains(string(out), "Tagging") {
|
|
| 148 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 149 |
- } |
|
| 150 | 139 |
|
| 140 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 141 |
+ c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) |
|
| 151 | 142 |
dockerCmd(c, "rmi", repoName) |
| 152 | 143 |
|
| 153 | 144 |
// Kill the notary server, start a new "evil" one. |
| 154 | 145 |
s.not.Close() |
| 155 | 146 |
s.not, err = newTestNotary(c) |
| 156 |
- if err != nil {
|
|
| 157 |
- c.Fatalf("Restarting notary server failed.")
|
|
| 158 |
- } |
|
| 147 |
+ |
|
| 148 |
+ c.Assert(err, check.IsNil, check.Commentf("Restarting notary server failed."))
|
|
| 159 | 149 |
|
| 160 | 150 |
// In order to make an evil server, lets re-init a client (with a different trust dir) and push new data. |
| 161 | 151 |
// tag an image and upload it to the private registry |
| ... | ... |
@@ -165,24 +130,17 @@ func (s *DockerTrustSuite) TestTrustedPullFromBadTrustServer(c *check.C) {
|
| 165 | 165 |
pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName) |
| 166 | 166 |
s.trustedCmd(pushCmd) |
| 167 | 167 |
out, _, err = runCommandWithOutput(pushCmd) |
| 168 |
- if err != nil {
|
|
| 169 |
- c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
|
| 170 |
- } |
|
| 171 |
- if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
| 172 |
- c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
| 173 |
- } |
|
| 168 |
+ |
|
| 169 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 170 |
+ c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) |
|
| 174 | 171 |
|
| 175 | 172 |
// Now, try pulling with the original client from this new trust server. This should fail. |
| 176 | 173 |
pullCmd = exec.Command(dockerBinary, "pull", repoName) |
| 177 | 174 |
s.trustedCmd(pullCmd) |
| 178 | 175 |
out, _, err = runCommandWithOutput(pullCmd) |
| 179 |
- if err == nil {
|
|
| 180 |
- c.Fatalf("Expected to fail on this pull due to different remote data: %s\n%s", err, out)
|
|
| 181 |
- } |
|
| 182 | 176 |
|
| 183 |
- if !strings.Contains(string(out), "failed to validate data with current trusted certificates") {
|
|
| 184 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 185 |
- } |
|
| 177 |
+ c.Assert(err, check.NotNil, check.Commentf(out)) |
|
| 178 |
+ c.Assert(string(out), checker.Contains, "failed to validate data with current trusted certificates", check.Commentf(out)) |
|
| 186 | 179 |
} |
| 187 | 180 |
|
| 188 | 181 |
func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
|
| ... | ... |
@@ -195,13 +153,9 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
|
| 195 | 195 |
pushCmd := exec.Command(dockerBinary, "push", repoName) |
| 196 | 196 |
s.trustedCmd(pushCmd) |
| 197 | 197 |
out, _, err := runCommandWithOutput(pushCmd) |
| 198 |
- if err != nil {
|
|
| 199 |
- c.Fatalf("trusted push failed: %s\n%s", err, out)
|
|
| 200 |
- } |
|
| 201 | 198 |
|
| 202 |
- if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
| 203 |
- c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
| 204 |
- } |
|
| 199 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 200 |
+ c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) |
|
| 205 | 201 |
|
| 206 | 202 |
dockerCmd(c, "rmi", repoName) |
| 207 | 203 |
|
| ... | ... |
@@ -213,13 +167,9 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
|
| 213 | 213 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 214 | 214 |
s.trustedCmd(pullCmd) |
| 215 | 215 |
out, _, err = runCommandWithOutput(pullCmd) |
| 216 |
- if err == nil {
|
|
| 217 |
- c.Fatalf("Missing expected error running trusted pull with expired snapshots")
|
|
| 218 |
- } |
|
| 219 | 216 |
|
| 220 |
- if !strings.Contains(string(out), "repository out-of-date") {
|
|
| 221 |
- c.Fatalf("Missing expected output on trusted pull with expired snapshot:\n%s", out)
|
|
| 222 |
- } |
|
| 217 |
+ c.Assert(err, check.NotNil, check.Commentf("Missing expected error running trusted pull with expired snapshots"))
|
|
| 218 |
+ c.Assert(string(out), checker.Contains, "repository out-of-date", check.Commentf(out)) |
|
| 223 | 219 |
}) |
| 224 | 220 |
} |
| 225 | 221 |
|
| ... | ... |
@@ -229,25 +179,16 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) {
|
| 229 | 229 |
pullCmd := exec.Command(dockerBinary, "pull", repoName) |
| 230 | 230 |
s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver") |
| 231 | 231 |
out, _, err := runCommandWithOutput(pullCmd) |
| 232 |
- if err == nil {
|
|
| 233 |
- c.Fatalf("Expected error pulling with invalid notary server:\n%s", out)
|
|
| 234 |
- } |
|
| 235 |
- |
|
| 236 |
- if !strings.Contains(string(out), "error contacting notary server") {
|
|
| 237 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 238 |
- } |
|
| 239 | 232 |
|
| 233 |
+ c.Assert(err, check.NotNil, check.Commentf(out)) |
|
| 234 |
+ c.Assert(string(out), checker.Contains, "error contacting notary server", check.Commentf(out)) |
|
| 240 | 235 |
// Do valid trusted pull to warm cache |
| 241 | 236 |
pullCmd = exec.Command(dockerBinary, "pull", repoName) |
| 242 | 237 |
s.trustedCmd(pullCmd) |
| 243 | 238 |
out, _, err = runCommandWithOutput(pullCmd) |
| 244 |
- if err != nil {
|
|
| 245 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 246 |
- } |
|
| 247 | 239 |
|
| 248 |
- if !strings.Contains(string(out), "Tagging") {
|
|
| 249 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 250 |
- } |
|
| 240 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 241 |
+ c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) |
|
| 251 | 242 |
|
| 252 | 243 |
dockerCmd(c, "rmi", repoName) |
| 253 | 244 |
|
| ... | ... |
@@ -255,11 +196,7 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) {
|
| 255 | 255 |
pullCmd = exec.Command(dockerBinary, "pull", repoName) |
| 256 | 256 |
s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver") |
| 257 | 257 |
out, _, err = runCommandWithOutput(pullCmd) |
| 258 |
- if err != nil {
|
|
| 259 |
- c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
|
| 260 |
- } |
|
| 261 | 258 |
|
| 262 |
- if !strings.Contains(string(out), "Tagging") {
|
|
| 263 |
- c.Fatalf("Missing expected output on trusted pull:\n%s", out)
|
|
| 264 |
- } |
|
| 259 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 260 |
+ c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) |
|
| 265 | 261 |
} |