Skip to content

Commit 8fd51e7

Browse files
Robert VincentGabrielNagy
authored andcommitted
(MODULES-9578) Add test for target attribute.
1 parent d01b4e3 commit 8fd51e7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

spec/acceptance/tests/resource/ssh_authorized_key/create_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55

66
let(:auth_keys) { '~/.ssh/authorized_keys' }
77
let(:name) { "pl#{rand(999_999).to_i}" }
8+
let(:custom_key_directory) { "/etc/ssh_authorized_keys_#{name}" }
9+
let(:custom_key) { "#{custom_key_directory}/authorized_keys_#{name}" }
10+
let(:custom_name) { "custom_#{name}" }
811

912
before(:each) do
1013
posix_agents.each do |agent|
1114
on(agent, "cp #{auth_keys} /tmp/auth_keys", acceptable_exit_codes: [0, 1])
12-
on(agent, "rm -f $LOGNAME #{auth_keys}")
15+
on(agent, "rm -f #{auth_keys}")
16+
on(agent, "mkdir #{custom_key_directory}")
1317
end
1418
end
1519

1620
after(:each) do
1721
posix_agents.each do |agent|
1822
# (teardown) restore the #{auth_keys} file
1923
on(agent, "mv /tmp/auth_keys #{auth_keys}", acceptable_exit_codes: [0, 1])
24+
on(agent, "rm -rf #{custom_key_directory}")
2025
end
2126
end
2227

@@ -32,5 +37,18 @@
3237
fail_test "didn't find the ssh_authorized_key for #{name}" unless stdout.include? name.to_s
3338
end
3439
end
40+
it "#{agent} should create an entry for an SSH authorized key in a custom location" do
41+
custom_args = ['ensure=present',
42+
'user=$LOGNAME',
43+
"type='rsa'",
44+
"key='mykey'",
45+
"target='#{custom_key}'"]
46+
47+
on(agent, puppet_resource('ssh_authorized_key', custom_name.to_s, custom_args))
48+
49+
on(agent, "cat #{custom_key}") do |_res|
50+
fail_test "didn't find the ssh_authorized_key for #{custom_name}" unless stdout.include? name.to_s
51+
end
52+
end
3553
end
3654
end

0 commit comments

Comments
 (0)