diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-06-30 15:44:14 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-07-07 08:34:31 -0400 |
commit | 6c6670f12a3e6b91c1ebb09e7d9e4f49f89dccc0 (patch) | |
tree | 466d433075c1e746d459184fb28fee1d96546e62 /libpod/container_internal_linux_test.go | |
parent | 1a93857acc4ee1e5a9213e2c22f12802d84cd277 (diff) | |
download | podman-6c6670f12a3e6b91c1ebb09e7d9e4f49f89dccc0.tar.gz podman-6c6670f12a3e6b91c1ebb09e7d9e4f49f89dccc0.tar.bz2 podman-6c6670f12a3e6b91c1ebb09e7d9e4f49f89dccc0.zip |
Add username to /etc/passwd inside of container if --userns keep-id
If I enter a continer with --userns keep-id, my UID will be present
inside of the container, but most likely my user will not be defined.
This patch will take information about the user and stick it into the
container.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/container_internal_linux_test.go')
-rw-r--r-- | libpod/container_internal_linux_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libpod/container_internal_linux_test.go b/libpod/container_internal_linux_test.go new file mode 100644 index 000000000..078cc53a7 --- /dev/null +++ b/libpod/container_internal_linux_test.go @@ -0,0 +1,42 @@ +// +build linux + +package libpod + +import ( + "io/ioutil" + "os" + "testing" + + spec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/stretchr/testify/assert" +) + +func TestGenerateUserPasswdEntry(t *testing.T) { + dir, err := ioutil.TempDir("", "libpod_test_") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + c := Container{ + config: &ContainerConfig{ + User: "123:456", + Spec: &spec.Spec{}, + }, + state: &ContainerState{ + Mountpoint: "/does/not/exist/tmp/", + }, + } + user, err := c.generateUserPasswdEntry() + if err != nil { + t.Fatal(err) + } + assert.Equal(t, user, "123:x:123:456:container user:/:/bin/sh\n") + + c.config.User = "567" + user, err = c.generateUserPasswdEntry() + if err != nil { + t.Fatal(err) + } + assert.Equal(t, user, "567:x:567:0:container user:/:/bin/sh\n") +} |