Skip to content

Commit

Permalink
Fix test usage of user.Name when user has full name set
Browse files Browse the repository at this point in the history
When a Linux user has a full name set, the Go user.Name field returns
the full name, rather than the username. The audit_test uses this
value for the output.file.user config, which causes the test to fail
with an unexpected "Could not find uid for user" error returned by
createFileOutput(). This patch fixes the test to use the Username field
instead of the Name field.
  • Loading branch information
David Ramos committed Jan 5, 2017
1 parent cb7943e commit fa66623
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ func Test_createFileOutput(t *testing.T) {
g, _ := user.LookupGroupId(strconv.Itoa(gid))

// travis-ci is silly
if u.Name == "" {
u.Name = g.Name
if u.Username == "" {
u.Username = g.Name
}

// gid error
c = viper.New()
c.Set("output.file.attempts", 1)
c.Set("output.file.path", path.Join(os.TempDir(), "go-audit.test.log"))
c.Set("output.file.mode", 0644)
c.Set("output.file.user", u.Name)
c.Set("output.file.user", u.Username)
w, err = createFileOutput(c)
assert.EqualError(t, err, "Could not find gid for group . Error: group: unknown group ")
assert.Nil(t, w)
Expand All @@ -165,7 +165,7 @@ func Test_createFileOutput(t *testing.T) {
c.Set("output.file.attempts", 1)
c.Set("output.file.path", path.Join(os.TempDir(), "go-audit.test.log"))
c.Set("output.file.mode", 0644)
c.Set("output.file.user", u.Name)
c.Set("output.file.user", u.Username)
c.Set("output.file.group", g.Name)
w, err = createFileOutput(c)
assert.Nil(t, err)
Expand Down Expand Up @@ -238,8 +238,8 @@ func Test_createOutput(t *testing.T) {
g, _ := user.LookupGroupId(strconv.Itoa(gid))

// travis-ci is silly
if u.Name == "" {
u.Name = g.Name
if u.Username == "" {
u.Username = g.Name
}

l, err := net.Listen("tcp", ":0")
Expand All @@ -259,7 +259,7 @@ func Test_createOutput(t *testing.T) {
c.Set("output.file.attempts", 1)
c.Set("output.file.path", path.Join(os.TempDir(), "go-audit.test.log"))
c.Set("output.file.mode", 0644)
c.Set("output.file.user", u.Name)
c.Set("output.file.user", u.Username)
c.Set("output.file.group", g.Name)

w, err = createOutput(c)
Expand Down Expand Up @@ -306,7 +306,7 @@ func Test_createOutput(t *testing.T) {
c.Set("output.file.attempts", 1)
c.Set("output.file.path", path.Join(os.TempDir(), "go-audit.test.log"))
c.Set("output.file.mode", 0644)
c.Set("output.file.user", u.Name)
c.Set("output.file.user", u.Username)
c.Set("output.file.group", g.Name)
w, err = createOutput(c)
assert.Nil(t, err)
Expand Down

0 comments on commit fa66623

Please sign in to comment.