فهرست منبع

Add unit test to check wrong uid case

Guillaume J. Charmes 12 سال پیش
والد
کامیت
e41507bde2
2فایلهای تغییر یافته به همراه20 افزوده شده و 0 حذف شده
  1. 17 0
      container_test.go
  2. 3 0
      utils/utils.go

+ 17 - 0
container_test.go

@@ -849,6 +849,23 @@ func TestUser(t *testing.T) {
 	if !strings.Contains(string(output), "uid=1(daemon) gid=1(daemon)") {
 	if !strings.Contains(string(output), "uid=1(daemon) gid=1(daemon)") {
 		t.Error(string(output))
 		t.Error(string(output))
 	}
 	}
+
+	// Test an wrong username
+	container, err = builder.Create(&Config{
+		Image: GetTestImage(runtime).ID,
+		Cmd:   []string{"id"},
+
+		User: "unkownuser",
+	},
+	)
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer runtime.Destroy(container)
+	output, err = container.Output()
+	if container.State.ExitCode == 0 {
+		t.Fatal("Starting container with wrong uid should fail but it passed.")
+	}
 }
 }
 
 
 func TestMultipleContainers(t *testing.T) {
 func TestMultipleContainers(t *testing.T) {

+ 3 - 0
utils/utils.go

@@ -702,6 +702,9 @@ func ParseRepositoryTag(repos string) (string, string) {
 	return repos, ""
 	return repos, ""
 }
 }
 
 
+// UserLookup check if the given username or uid is present in /etc/passwd
+// and returns the user struct.
+// If the username is not found, an error is returned.
 func UserLookup(uid string) (*user.User, error) {
 func UserLookup(uid string) (*user.User, error) {
 	file, err := ioutil.ReadFile("/etc/passwd")
 	file, err := ioutil.ReadFile("/etc/passwd")
 	if err != nil {
 	if err != nil {