Skip to content

Commit

Permalink
Add unit test to check wrong uid case
Browse files Browse the repository at this point in the history
  • Loading branch information
creack committed Jul 15, 2013
1 parent eb38750 commit e41507b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions container_test.go
Expand Up @@ -849,6 +849,23 @@ func TestUser(t *testing.T) {
if !strings.Contains(string(output), "uid=1(daemon) gid=1(daemon)") {
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) {
Expand Down
3 changes: 3 additions & 0 deletions utils/utils.go
Expand Up @@ -702,6 +702,9 @@ func ParseRepositoryTag(repos string) (string, string) {
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) {
file, err := ioutil.ReadFile("/etc/passwd")
if err != nil {
Expand Down

0 comments on commit e41507b

Please sign in to comment.