diff --git a/acceptance/tests/resource/user/should_create.rb b/acceptance/tests/resource/user/should_create.rb index 0b2b0c65f..4889c062f 100755 --- a/acceptance/tests/resource/user/should_create.rb +++ b/acceptance/tests/resource/user/should_create.rb @@ -1,24 +1,26 @@ -test_name "should create a user, and the default matching group" +test_name "should create a user" name = "pl#{rand(999999).to_i}" -step "ensure that the user and group #{name} do not exist" -on agents, "if getent passwd #{name}; then userdel #{name}; fi" -on agents, "if getent group #{name}; then groupdel #{name}; fi" +agents.each do |agent| + step "ensure the user and group do not exist" + agent.user_absent(name) + agent.group_absent(name) -step "ask puppet to create the user" -on(agents, puppet_resource('user', name, 'ensure=present')) + step "create the user" + on agent, puppet_resource('user', name, 'ensure=present') -step "verify that the user and group now exist" -agents.each do |agent| - if agent['platform'].include? 'sles' or agent['platform'].include? 'solaris' # no private user groups by default - on agent, "getent passwd #{name}" + step "verify the user exists" + agent.user_get(name) + + case agent['platform'] + when /sles/, /solaris/, /windows/ + # no private user groups by default else - on agent, "getent passwd #{name} && getent group #{name}" + agent.group_get(name) end -end - -step "ensure that the user and group #{name} do not exist" -on agents, "if getent passwd #{name}; then userdel #{name}; fi" -on agents, "if getent group #{name}; then groupdel #{name}; fi" + step "delete the user, and group, if any" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_create_with_gid.rb b/acceptance/tests/resource/user/should_create_with_gid.rb index c92d5c95d..0b9f00d64 100755 --- a/acceptance/tests/resource/user/should_create_with_gid.rb +++ b/acceptance/tests/resource/user/should_create_with_gid.rb @@ -1,30 +1,34 @@ test_name "verifies that puppet resource creates a user and assigns the correct group" user = "pl#{rand(999999).to_i}" group = "gp#{rand(999999).to_i}" agents.each do |host| + if host['platform'].include?('windows') + skip_test "Test not supported on this platform" + else step "user should not exist" on host, "if getent passwd #{user}; then userdel #{user}; fi" step "group should exist" on host, "getent group #{group} || groupadd #{group}" step "create user with group" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) step "verify the group exists and find the gid" on(host, "getent group #{group}") do gid = stdout.split(':')[2] step "verify that the user has that as their gid" on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "wanted gid #{gid} but found #{got}" unless gid == got end end step "clean up after the test is done" on(host, puppet_resource('user', user, 'ensure=absent')) on(host, puppet_resource('group', group, 'ensure=absent')) + end end diff --git a/acceptance/tests/resource/user/should_destroy.rb b/acceptance/tests/resource/user/should_destroy.rb index 655501231..73d73dbb7 100755 --- a/acceptance/tests/resource/user/should_destroy.rb +++ b/acceptance/tests/resource/user/should_destroy.rb @@ -1,19 +1,14 @@ -test_name "verify that puppet resource correctly destroys users" +test_name "should delete a user" -user = "pl#{rand(999999).to_i}" -group = user +name = "pl#{rand(999999).to_i}" -step "ensure that the user and associated group exist" -on(agents, puppet_resource('group', group, 'ensure=present')) -on(agents, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) +agents.each do |agent| + step "ensure the user is present" + agent.user_present(name) -step "try and delete the user" -on(agents, puppet_resource('user', user, 'ensure=absent')) + step "delete the user" + on agent, puppet_resource('user', name, 'ensure=absent') -step "verify that the user is no longer present" -on(agents, "getent passwd #{user}", :acceptable_exit_codes => [2]) do - fail_test "found the user in the output" if stdout.include? "#{user}:" + step "verify the user was deleted" + agent.user_absent(name) end - -step "remove the group as well..." -on(agents, puppet_resource('group', group, 'ensure=absent')) diff --git a/acceptance/tests/resource/user/should_modify.rb b/acceptance/tests/resource/user/should_modify.rb new file mode 100644 index 000000000..24e901659 --- /dev/null +++ b/acceptance/tests/resource/user/should_modify.rb @@ -0,0 +1,20 @@ +test_name "should modify a user" + +name = "pl#{rand(999999).to_i}" + +agents.each do |agent| + step "ensure the user is present" + agent.user_present(name) + + step "modify the user" + on agent, puppet_resource('user', name, ["ensure=present", "comment=comment#{name}"]) + + step "verify the user was modified" + agent.user_get(name) do |result| + fail_test "didn't modify the user #{name}" unless result.stdout.include? "comment#{name}" + end + + step "delete the user" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_modify_gid.rb b/acceptance/tests/resource/user/should_modify_gid.rb index d8bc60fc1..4c13dc40e 100755 --- a/acceptance/tests/resource/user/should_modify_gid.rb +++ b/acceptance/tests/resource/user/should_modify_gid.rb @@ -1,41 +1,45 @@ test_name "verify that we can modify the gid" user = "pl#{rand(99999).to_i}" group1 = "#{user}old" group2 = "#{user}new" agents.each do |host| + if host['platform'].include?('windows') + skip_test "Test not supported on this platform" + else step "ensure that the groups both exist" on(host, puppet_resource('group', group1, 'ensure=present')) on(host, puppet_resource('group', group2, 'ensure=present')) step "ensure the user exists and has the old group" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group1}")) step "verify that the user has the correct gid" on(host, "getent group #{group1}") do gid = stdout.split(':')[2] on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "didn't have the expected old GID, but #{got}" unless got == gid end end step "modify the GID of the user" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group2}")) step "verify that the user has the updated gid" on(host, "getent group #{group2}") do gid = stdout.split(':')[2] on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "didn't have the expected old GID, but #{got}" unless got == gid end end step "ensure that we remove the things we made" on(host, puppet_resource('user', user, 'ensure=absent')) on(host, puppet_resource('group', group1, 'ensure=absent')) on(host, puppet_resource('group', group2, 'ensure=absent')) + end end diff --git a/acceptance/tests/resource/user/should_not_create_existing.rb b/acceptance/tests/resource/user/should_not_create_existing.rb index 2f33a94df..994832284 100755 --- a/acceptance/tests/resource/user/should_not_create_existing.rb +++ b/acceptance/tests/resource/user/should_not_create_existing.rb @@ -1,6 +1,8 @@ test_name "tests that user resource will not add users that already exist." step "verify that we don't try to create a user account that already exists" -on(agents, puppet_resource('user', 'root', 'ensure=present')) do - fail_test "tried to create 'root' user" if stdout.include? 'created' +agents.each do |agent| + on(agent, puppet_resource('user', agent['user'], 'ensure=present')) do + fail_test "tried to create '#{agent['user']}' user" if stdout.include? 'created' + end end diff --git a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb index 133d51395..5e6bcd2fa 100755 --- a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb +++ b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb @@ -1,11 +1,13 @@ test_name "ensure that puppet does not report removing a user that does not exist" name = "pl#{rand(999999).to_i}" step "verify that user #{name} does not exist" -on agents, "getent passwd #{name}", :acceptable_exit_codes => [2] +agents.each do |agent| + agent.user_absent(name) +end step "ensure absent doesn't try and do anything" on(agents, puppet_resource('user', name, 'ensure=absent')) do - fail_test "tried to remove the user, apparently" if stdout.include? 'removed' + fail_test "tried to remove the user, apparently" if stdout.include? 'removed' end diff --git a/acceptance/tests/resource/user/should_query.rb b/acceptance/tests/resource/user/should_query.rb index c976c878f..de9425b8a 100755 --- a/acceptance/tests/resource/user/should_query.rb +++ b/acceptance/tests/resource/user/should_query.rb @@ -1,15 +1,17 @@ test_name "test that we can query and find a user that exists." name = "pl#{rand(999999).to_i}" -step "ensure that our test user exists" -on(agents, puppet_resource('user', name, 'ensure=present')) +agents.each do |agent| + step "ensure that our test user exists" + agent.user_present(name) -step "query for the resource and verify it was found" -on(agents, puppet_resource('user', name)) do + step "query for the resource and verify it was found" + on(agent, puppet_resource('user', name)) do fail_test "didn't find the user #{name}" unless stdout.include? 'present' -end + end -step "clean up the user and group we added" -on(agents, puppet_resource('user', name, 'ensure=absent')) -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the user and group we added" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_query_all.rb b/acceptance/tests/resource/user/should_query_all.rb index 00d7b25c4..db7037cdd 100755 --- a/acceptance/tests/resource/user/should_query_all.rb +++ b/acceptance/tests/resource/user/should_query_all.rb @@ -1,30 +1,23 @@ -test_name "ensure that puppet queries the correct number of users" +test_name "should query all users" -agents.each do |host| - users = [] +agents.each do |agent| + step "query natively" + users = agent.user_list - step "collect the list of known users via getent" - on(host, "getent passwd") do - stdout.each_line do |line| - users << line.split(':')[0] - end - end + fail_test("No users found") unless users - step "collect the list of known users via puppet" - on(host, puppet_resource('user')) do - stdout.each_line do |line| - name = ( line.match(/^user \{ '([^']+)'/) or next )[1] + step "query with puppet" + on(agent, puppet_resource('user')) do + stdout.each_line do |line| + name = ( line.match(/^user \{ '([^']+)'/) or next )[1] - # OK: Was this name found in the list of users? - if users.member? name then - users.delete name - else - fail_test "user #{name} found by puppet, not by getent" - end - end + unless users.delete(name) + fail_test "user #{name} found by puppet, not natively" + end end + end - if users.length > 0 then - fail_test "#{users.length} users found with getent, not puppet: #{users.join(', ')}" - end + if users.length > 0 then + fail_test "#{users.length} users found natively, not puppet: #{users.join(', ')}" + end end