|
5 | 5 |
|
6 | 6 | let(:auth_keys) { '~/.ssh/authorized_keys' }
|
7 | 7 | 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}" } |
8 | 11 |
|
9 | 12 | before(:each) do
|
10 | 13 | posix_agents.each do |agent|
|
11 | 14 | 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}") |
13 | 17 | end
|
14 | 18 | end
|
15 | 19 |
|
16 | 20 | after(:each) do
|
17 | 21 | posix_agents.each do |agent|
|
18 | 22 | # (teardown) restore the #{auth_keys} file
|
19 | 23 | on(agent, "mv /tmp/auth_keys #{auth_keys}", acceptable_exit_codes: [0, 1])
|
| 24 | + on(agent, "rm -rf #{custom_key_directory}") |
20 | 25 | end
|
21 | 26 | end
|
22 | 27 |
|
|
32 | 37 | fail_test "didn't find the ssh_authorized_key for #{name}" unless stdout.include? name.to_s
|
33 | 38 | end
|
34 | 39 | 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 |
35 | 53 | end
|
36 | 54 | end
|
0 commit comments