fix the issue now

This commit is contained in:
Tejal Desai
2019-11-07 15:29:56 -08:00
parent f36dd4013c
commit b04d15db82
2 changed files with 14 additions and 11 deletions
+7 -4
View File
@@ -138,14 +138,17 @@ func addDefaultHOME(u string, envs []string) []string {
// If user is set to username, set value of HOME to /home/${user}
// Otherwise the user is set to uid and HOME is /
home := fmt.Sprintf("%s=/", constants.HOME)
home := "/"
userObj, err := userLookup(u)
if err == nil {
u = userObj.Username
home = fmt.Sprintf("%s=/home/%s", constants.HOME, u)
if userObj.HomeDir != "" {
home = userObj.HomeDir
} else {
home = fmt.Sprintf("/home/%s", userObj.Username)
}
}
return append(envs, home)
return append(envs, fmt.Sprintf("%s=%s", constants.HOME, home))
}
// String returns some information about the command for the image config
+7 -7
View File
@@ -43,7 +43,7 @@ func Test_addDefaultHOME(t *testing.T) {
},
},
{
name: "HOME not set, user not set",
name: "HOME not set and user not set",
user: "",
initial: []string{
"PATH=/something/else",
@@ -54,22 +54,22 @@ func Test_addDefaultHOME(t *testing.T) {
},
},
{
name: "HOME not set, user and homedir for the user set",
name: "HOME not set and user and homedir for the user set",
user: "www-add",
mockUser: &user.User{
Username: "www-add",
HomeDir: "some-other",
HomeDir: "/home/some-other",
},
initial: []string{
"PATH=/something/else",
},
expected: []string{
"PATH=/something/else",
"HOME=/home/www-add",
"HOME=/home/some-other",
},
},
{
name: "HOME not set, user set",
name: "HOME not set and user set",
user: "www-add",
mockUser: &user.User{
Username: "www-add",
@@ -83,7 +83,7 @@ func Test_addDefaultHOME(t *testing.T) {
},
},
{
name: "HOME not set, user is set",
name: "HOME not set and user is set",
user: "newuser",
mockUser: &user.User{
Username: "newuser",
@@ -97,7 +97,7 @@ func Test_addDefaultHOME(t *testing.T) {
},
},
{
name: "HOME not set, user is set to root",
name: "HOME not set and user is set to root",
user: "root",
mockUser: &user.User{
Username: "root",