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"
|
2019-04-04 09:23:19 -04:00
|
|
|
"strings"
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2019-04-04 09:23:19 -04:00
|
|
|
"gotest.tools/assert"
|
2016-03-02 08:26:29 -05:00
|
|
|
)
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) {
|
2017-12-08 18:13:43 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2017-06-11 08:39:28 -04:00
|
|
|
|
2016-03-02 08:26:29 -05:00
|
|
|
osPath := os.Getenv("PATH")
|
|
|
|
defer os.Setenv("PATH", osPath)
|
|
|
|
|
|
|
|
workingDir, err := os.Getwd()
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-02 08:26:29 -05:00
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-02 08:26:29 -05:00
|
|
|
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-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-06-11 08:39:28 -04:00
|
|
|
defer os.RemoveAll(tmp)
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
externalAuthConfig := `{ "credsStore": "shell-test" }`
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
|
|
|
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-02 08:26:29 -05:00
|
|
|
|
2017-06-11 08:39:28 -04:00
|
|
|
_, err = s.d.Cmd("--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
b, err := ioutil.ReadFile(configPath)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, !strings.Contains(string(b), `"auth":`))
|
|
|
|
assert.Assert(c, strings.Contains(string(b), privateRegistryURL))
|
2016-03-02 08:26:29 -05:00
|
|
|
|
2017-06-11 08:39:28 -04:00
|
|
|
_, err = s.d.Cmd("--config", tmp, "tag", "busybox", repoName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-06-11 08:39:28 -04:00
|
|
|
_, err = s.d.Cmd("--config", tmp, "push", repoName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-06-11 08:39:28 -04:00
|
|
|
_, err = s.d.Cmd("--config", tmp, "logout", privateRegistryURL)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(configPath)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, !strings.Contains(string(b), privateRegistryURL))
|
2016-03-02 08:26:29 -05:00
|
|
|
|
|
|
|
// check I cannot pull anymore
|
2017-06-11 08:39:28 -04:00
|
|
|
out, err := s.d.Cmd("--config", tmp, "pull", repoName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "no basic auth credentials"))
|
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()
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
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
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, cmd.Run())
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
tmp, err := ioutil.TempDir("", "integration-cli-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
externalAuthConfig := fmt.Sprintf(`{ "auths": {"https://%s": {}}, "credsStore": "shell-test" }`, privateRegistryURL)
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
|
|
|
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
|
|
|
|
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(configPath)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
|
|
|
|
assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
|
2016-05-30 06:47:49 -04:00
|
|
|
}
|