|
@@ -216,190 +216,6 @@ func TestRestartStdin(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestUser(t *testing.T) {
|
|
|
- daemon := mkDaemon(t)
|
|
|
- defer nuke(daemon)
|
|
|
-
|
|
|
- // Default user must be root
|
|
|
- container, _, err := daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err := container.Output()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if !strings.Contains(string(output), "uid=0(root) gid=0(root)") {
|
|
|
- t.Error(string(output))
|
|
|
- }
|
|
|
-
|
|
|
- // Set a username
|
|
|
- container, _, err = daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
-
|
|
|
- User: "root",
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err = container.Output()
|
|
|
- if code := container.State.GetExitCode(); err != nil || code != 0 {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if !strings.Contains(string(output), "uid=0(root) gid=0(root)") {
|
|
|
- t.Error(string(output))
|
|
|
- }
|
|
|
-
|
|
|
- // Set a UID
|
|
|
- container, _, err = daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
-
|
|
|
- User: "0",
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if code := container.State.GetExitCode(); err != nil || code != 0 {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err = container.Output()
|
|
|
- if code := container.State.GetExitCode(); err != nil || code != 0 {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if !strings.Contains(string(output), "uid=0(root) gid=0(root)") {
|
|
|
- t.Error(string(output))
|
|
|
- }
|
|
|
-
|
|
|
- // Set a different user by uid
|
|
|
- container, _, err = daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
-
|
|
|
- User: "1",
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err = container.Output()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- } else if code := container.State.GetExitCode(); code != 0 {
|
|
|
- t.Fatalf("Container exit code is invalid: %d\nOutput:\n%s\n", code, output)
|
|
|
- }
|
|
|
- if !strings.Contains(string(output), "uid=1(daemon) gid=1(daemon)") {
|
|
|
- t.Error(string(output))
|
|
|
- }
|
|
|
-
|
|
|
- // Set a different user by username
|
|
|
- container, _, err = daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
-
|
|
|
- User: "daemon",
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err = container.Output()
|
|
|
- if code := container.State.GetExitCode(); err != nil || code != 0 {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if !strings.Contains(string(output), "uid=1(daemon) gid=1(daemon)") {
|
|
|
- t.Error(string(output))
|
|
|
- }
|
|
|
-
|
|
|
- // Test an wrong username
|
|
|
- container, _, err = daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"id"},
|
|
|
-
|
|
|
- User: "unknownuser",
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container)
|
|
|
- output, err = container.Output()
|
|
|
- if container.State.GetExitCode() == 0 {
|
|
|
- t.Fatal("Starting container with wrong uid should fail but it passed.")
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestMultipleContainers(t *testing.T) {
|
|
|
- daemon := mkDaemon(t)
|
|
|
- defer nuke(daemon)
|
|
|
-
|
|
|
- container1, _, err := daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"sleep", "2"},
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container1)
|
|
|
-
|
|
|
- container2, _, err := daemon.Create(&runconfig.Config{
|
|
|
- Image: GetTestImage(daemon).ID,
|
|
|
- Cmd: []string{"sleep", "2"},
|
|
|
- },
|
|
|
- "",
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- defer daemon.Destroy(container2)
|
|
|
-
|
|
|
- // Start both containers
|
|
|
- if err := container1.Start(); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if err := container2.Start(); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- // Make sure they are running before trying to kill them
|
|
|
- container1.WaitTimeout(250 * time.Millisecond)
|
|
|
- container2.WaitTimeout(250 * time.Millisecond)
|
|
|
-
|
|
|
- // If we are here, both containers should be running
|
|
|
- if !container1.State.IsRunning() {
|
|
|
- t.Fatal("Container not running")
|
|
|
- }
|
|
|
- if !container2.State.IsRunning() {
|
|
|
- t.Fatal("Container not running")
|
|
|
- }
|
|
|
-
|
|
|
- // Kill them
|
|
|
- if err := container1.Kill(); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- if err := container2.Kill(); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func TestStdin(t *testing.T) {
|
|
|
daemon := mkDaemon(t)
|
|
|
defer nuke(daemon)
|