Skip to content

Commit

Permalink
Updated tests for default shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Adithya-Rajendran committed Jul 1, 2024
1 parent 1902124 commit 4f84f6d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/core/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ def test_adduser_with_groups(self, log, check_call, getpwnam, getgrnam):
@patch.object(host, 'log')
def test_adds_a_systemuser(self, log, check_call, getpwnam):
username = 'johndoe'
shell = '/usr/sbin/nologin'
existing_user_pwnam = KeyError('user not found')
new_user_pwnam = 'some user pwnam'

Expand All @@ -766,6 +767,7 @@ def test_adds_a_systemuser(self, log, check_call, getpwnam):
check_call.assert_called_with([
'useradd',
'--system',
'--shell', shell,
username
])
getpwnam.assert_called_with(username)
Expand All @@ -775,6 +777,7 @@ def test_adds_a_systemuser(self, log, check_call, getpwnam):
@patch.object(host, 'log')
def test_adds_a_systemuser_with_home_dir(self, log, check_call, getpwnam):
username = 'johndoe'
shell = '/usr/sbin/nologin'
existing_user_pwnam = KeyError('user not found')
new_user_pwnam = 'some user pwnam'

Expand All @@ -789,6 +792,7 @@ def test_adds_a_systemuser_with_home_dir(self, log, check_call, getpwnam):
'--home',
'/var/lib/johndoe',
'--system',
'--shell', shell,
username
])
getpwnam.assert_called_with(username)
Expand All @@ -798,7 +802,7 @@ def test_adds_a_systemuser_with_home_dir(self, log, check_call, getpwnam):
@patch.object(host, 'log')
def test_adds_a_systemuser_with_different_shell(self, log, check_call, getpwnam):
username = 'johndoe'
shell = '/usr/sbin/nologin'
shell = '/bin/bash'
existing_user_pwnam = KeyError('user not found')
new_user_pwnam = 'some user pwnam'

Expand All @@ -823,6 +827,7 @@ def test_adds_a_systemuser_with_different_shell(self, log, check_call, getpwnam)
def test_add_user_uid(self, log, check_call, getgrnam, getpwuid, getpwnam):
user_name = 'james'
user_id = 1111
shell = '/usr/sbin/nologin'
uid_key_error = KeyError('user not found')
getpwuid.side_effect = uid_key_error
host.adduser(user_name, uid=user_id)
Expand All @@ -832,6 +837,7 @@ def test_add_user_uid(self, log, check_call, getgrnam, getpwuid, getpwnam):
'--uid',
str(user_id),
'--system',
'--shell', shell,
'-g',
user_name,
user_name
Expand Down

0 comments on commit 4f84f6d

Please sign in to comment.