initilize group to 0

This commit is contained in:
Tejal Desai 2020-02-03 15:23:16 -08:00
parent 56125ff464
commit 31f626cb22
2 changed files with 5 additions and 5 deletions

View File

@ -377,7 +377,7 @@ func GetUserFromUsername(userStr string, groupStr string, fallbackToUID bool) (s
} }
uid := userObj.Uid uid := userObj.Uid
gid := "" gid := "0"
if fallbackToUID { if fallbackToUID {
gid = userObj.Gid gid = userObj.Gid
} }

View File

@ -551,12 +551,12 @@ func Test_GetUIDAndGIDFromString(t *testing.T) {
fmt.Sprintf("%s:%s", currentUser.Uid, primaryGroup), fmt.Sprintf("%s:%s", currentUser.Uid, primaryGroup),
fmt.Sprintf("%s:%s", currentUser.Username, primaryGroup), fmt.Sprintf("%s:%s", currentUser.Username, primaryGroup),
} }
expectedUid, _ := strconv.ParseUint(currentUser.Uid, 10, 32) expectedU, _ := strconv.ParseUint(currentUser.Uid, 10, 32)
expectedGid, _ := strconv.ParseUint(currentUser.Gid, 10, 32) expectedG, _ := strconv.ParseUint(currentUser.Gid, 10, 32)
for _, tt := range testCases { for _, tt := range testCases {
uid, gid, err := GetUIDAndGIDFromString(tt, false) uid, gid, err := GetUIDAndGIDFromString(tt, false)
if uid != uint32(expectedUid) || gid != uint32(expectedGid) || err != nil { if uid != uint32(expectedU) || gid != uint32(expectedG) || err != nil {
t.Errorf("Could not correctly decode %s to uid/gid %d:%d. Result: %d:%d", tt, expectedUid, expectedGid, t.Errorf("Could not correctly decode %s to uid/gid %d:%d. Result: %d:%d", tt, expectedU, expectedG,
uid, gid) uid, gid)
} }
} }