Browse code

add test

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/05/21 08:34:48
Showing 2 changed files
... ...
@@ -91,6 +91,8 @@ RUN	git config --global user.email 'docker-dummy@example.com'
91 91
 
92 92
 # Add an unprivileged user to be used for tests which need it
93 93
 RUN adduser unprivilegeduser
94
+RUN groupadd docker
95
+RUN gpasswd -a unprivilegeduser docker
94 96
 
95 97
 VOLUME	/var/lib/docker
96 98
 WORKDIR	/go/src/github.com/dotcloud/docker
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"fmt"
5 5
 	"io/ioutil"
6 6
 	"os"
7
+	"os/exec"
7 8
 	"path/filepath"
8 9
 	"testing"
9 10
 )
... ...
@@ -206,3 +207,39 @@ func TestCpAbsolutePath(t *testing.T) {
206 206
 
207 207
 	logDone("cp - absolute paths relative to container's rootfs")
208 208
 }
209
+
210
+// Check that cp with unprivileged user doesn't return any error
211
+func TestCpUnprivilegedUser(t *testing.T) {
212
+	out, exitCode, err := cmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
213
+	if err != nil || exitCode != 0 {
214
+		t.Fatal("failed to create a container", out, err)
215
+	}
216
+
217
+	cleanedContainerID := stripTrailingCharacters(out)
218
+	defer deleteContainer(cleanedContainerID)
219
+
220
+	out, _, err = cmd(t, "wait", cleanedContainerID)
221
+	if err != nil || stripTrailingCharacters(out) != "0" {
222
+		t.Fatal("failed to set up container", out, err)
223
+	}
224
+
225
+	tmpdir, err := ioutil.TempDir("", "docker-integration")
226
+	if err != nil {
227
+		t.Fatal(err)
228
+	}
229
+
230
+	defer os.RemoveAll(tmpdir)
231
+
232
+	if err = os.Chmod(tmpdir, 0777); err != nil {
233
+		t.Fatal(err)
234
+	}
235
+
236
+	path := cpTestName
237
+
238
+	_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
239
+	if err != nil {
240
+		t.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
241
+	}
242
+
243
+	logDone("cp - unprivileged user")
244
+}