1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-05-20 23:34:48 +00:00
parent 1f219672fa
commit 5eef0a28cb
2 changed files with 39 additions and 0 deletions

View file

@ -91,6 +91,8 @@ RUN git config --global user.email 'docker-dummy@example.com'
# Add an unprivileged user to be used for tests which need it # Add an unprivileged user to be used for tests which need it
RUN adduser unprivilegeduser RUN adduser unprivilegeduser
RUN groupadd docker
RUN gpasswd -a unprivilegeduser docker
VOLUME /var/lib/docker VOLUME /var/lib/docker
WORKDIR /go/src/github.com/dotcloud/docker WORKDIR /go/src/github.com/dotcloud/docker

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"testing" "testing"
) )
@ -206,3 +207,39 @@ func TestCpAbsolutePath(t *testing.T) {
logDone("cp - absolute paths relative to container's rootfs") logDone("cp - absolute paths relative to container's rootfs")
} }
// Check that cp with unprivileged user doesn't return any error
func TestCpUnprivilegedUser(t *testing.T) {
out, exitCode, err := cmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
if err != nil || exitCode != 0 {
t.Fatal("failed to create a container", out, err)
}
cleanedContainerID := stripTrailingCharacters(out)
defer deleteContainer(cleanedContainerID)
out, _, err = cmd(t, "wait", cleanedContainerID)
if err != nil || stripTrailingCharacters(out) != "0" {
t.Fatal("failed to set up container", out, err)
}
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
if err = os.Chmod(tmpdir, 0777); err != nil {
t.Fatal(err)
}
path := cpTestName
_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
if err != nil {
t.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
}
logDone("cp - unprivileged user")
}