Skip to content

Commit

Permalink
distro(freebsd): add_user: respect homedir
Browse files Browse the repository at this point in the history
reportedly, passing `homedir` to a user struct doesn't actually change
the homedir to the desired value. This is because we hard-code the path.
Respect the value we are passed, and only make up a default when we
don't get a `homedir`. Amend tests to verify;

Sponsored by: The FreeBSD Foundation
  • Loading branch information
igalic committed Mar 14, 2024
1 parent f7c1c76 commit 70de3fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cloudinit/distros/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ def add_user(self, name, **kwargs):
pw_useradd_cmd.append("-d/nonexistent")
log_pw_useradd_cmd.append("-d/nonexistent")
else:
home_dir = "{home_dir}/{name}".format(home_dir=self.home_dir, name=name)
if "homedir" in kwargs:
home_dir = kwargs["homedir"]
pw_useradd_cmd.append(
"-d{home_dir}/{name}".format(home_dir=self.home_dir, name=name)
"-d{home_dir}".format(home_dir=home_dir)
)
pw_useradd_cmd.append("-m")
log_pw_useradd_cmd.append(
"-d{home_dir}/{name}".format(home_dir=self.home_dir, name=name)
"-d{home_dir}".format(home_dir=home_dir)
)

log_pw_useradd_cmd.append("-m")
Expand Down
3 changes: 3 additions & 0 deletions tests/unittests/config/test_cc_users_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_handle_users_in_cfg_calls_create_users_on_bsd(
"lock_passwd": True,
"groups": ["wheel"],
"shell": "/bin/tcsh",
"homedir": "/home/freebsd",
}
}
metadata = {}
Expand All @@ -116,6 +117,7 @@ def test_handle_users_in_cfg_calls_create_users_on_bsd(
groups="wheel",
lock_passwd=True,
shell="/bin/tcsh",
homedir="/home/freebsd",
),
mock.call("me2", uid=1234, default=False),
],
Expand All @@ -124,6 +126,7 @@ def test_handle_users_in_cfg_calls_create_users_on_bsd(
m_linux_group.assert_not_called()
m_linux_user.assert_not_called()


def test_users_with_ssh_redirect_user_passes_keys(self, m_user, m_group):
"""When ssh_redirect_user is True pass default user and cloud keys."""
cfg = {
Expand Down

0 comments on commit 70de3fd

Please sign in to comment.