2016-03-02 08:26:29 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-05-30 06:47:49 -04:00
|
|
|
"bytes"
|
2016-03-02 08:26:29 -05:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2016-05-30 06:47:49 -04:00
|
|
|
"os/exec"
|
2016-03-02 08:26:29 -05:00
|
|
|
"path/filepath"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-03-02 08:26:29 -05:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) {
|
2016-03-02 08:26:29 -05:00
|
|
|
osPath := os.Getenv("PATH")
|
|
|
|
defer os.Setenv("PATH", osPath)
|
|
|
|
|
|
|
|
workingDir, err := os.Getwd()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
|
|
|
|
|
|
|
|
os.Setenv("PATH", testPath)
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
|
|
|
|
|
|
|
|
tmp, err := ioutil.TempDir("", "integration-cli-")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
externalAuthConfig := `{ "credsStore": "shell-test" }`
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
|
|
|
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
b, err := ioutil.ReadFile(configPath)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
|
|
|
|
c.Assert(string(b), checker.Contains, privateRegistryURL)
|
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
|
|
|
|
dockerCmd(c, "--config", tmp, "push", repoName)
|
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(configPath)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(string(b), checker.Not(checker.Contains), privateRegistryURL)
|
|
|
|
|
|
|
|
// check I cannot pull anymore
|
|
|
|
out, _, err := dockerCmdWithError("--config", tmp, "pull", repoName)
|
|
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
2016-03-28 20:16:56 -04:00
|
|
|
c.Assert(out, checker.Contains, "Error: image dockercli/busybox:authtest not found")
|
2016-03-02 08:26:29 -05:00
|
|
|
}
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
// #23100
|
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *check.C) {
|
|
|
|
osPath := os.Getenv("PATH")
|
|
|
|
defer os.Setenv("PATH", osPath)
|
|
|
|
|
|
|
|
workingDir, err := os.Getwd()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
|
|
|
|
|
|
|
|
os.Setenv("PATH", testPath)
|
|
|
|
|
|
|
|
cmd := exec.Command("docker-credential-shell-test", "store")
|
2016-12-30 13:10:04 -05:00
|
|
|
stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": "%s", "Secret": "%s"}`, privateRegistryURL, s.reg.Username(), s.reg.Password())))
|
2016-05-30 06:47:49 -04:00
|
|
|
cmd.Stdin = stdin
|
|
|
|
c.Assert(cmd.Run(), checker.IsNil)
|
|
|
|
|
|
|
|
tmp, err := ioutil.TempDir("", "integration-cli-")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
externalAuthConfig := fmt.Sprintf(`{ "auths": {"https://%s": {}}, "credsStore": "shell-test" }`, privateRegistryURL)
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
|
|
|
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
b, err := ioutil.ReadFile(configPath)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(string(b), checker.Contains, fmt.Sprintf("\"https://%s\": {}", privateRegistryURL))
|
|
|
|
c.Assert(string(b), checker.Contains, fmt.Sprintf("\"%s\": {}", privateRegistryURL))
|
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(configPath)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(string(b), checker.Not(checker.Contains), fmt.Sprintf("\"https://%s\": {}", privateRegistryURL))
|
|
|
|
c.Assert(string(b), checker.Not(checker.Contains), fmt.Sprintf("\"%s\": {}", privateRegistryURL))
|
|
|
|
}
|