docker_cli_logout_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. "github.com/docker/docker/pkg/integration/checker"
  8. "github.com/go-check/check"
  9. )
  10. func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) {
  11. osPath := os.Getenv("PATH")
  12. defer os.Setenv("PATH", osPath)
  13. workingDir, err := os.Getwd()
  14. c.Assert(err, checker.IsNil)
  15. absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
  16. c.Assert(err, checker.IsNil)
  17. testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
  18. os.Setenv("PATH", testPath)
  19. repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
  20. tmp, err := ioutil.TempDir("", "integration-cli-")
  21. c.Assert(err, checker.IsNil)
  22. externalAuthConfig := `{ "credsStore": "shell-test" }`
  23. configPath := filepath.Join(tmp, "config.json")
  24. err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
  25. c.Assert(err, checker.IsNil)
  26. dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL)
  27. b, err := ioutil.ReadFile(configPath)
  28. c.Assert(err, checker.IsNil)
  29. c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
  30. c.Assert(string(b), checker.Contains, privateRegistryURL)
  31. dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
  32. dockerCmd(c, "--config", tmp, "push", repoName)
  33. dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
  34. b, err = ioutil.ReadFile(configPath)
  35. c.Assert(err, checker.IsNil)
  36. c.Assert(string(b), checker.Not(checker.Contains), privateRegistryURL)
  37. // check I cannot pull anymore
  38. out, _, err := dockerCmdWithError("--config", tmp, "pull", repoName)
  39. c.Assert(err, check.NotNil, check.Commentf(out))
  40. c.Assert(out, checker.Contains, "Error: image dockercli/busybox:authtest not found")
  41. }