|
| 1 | +require 'spec_helper_acceptance' |
| 2 | + |
| 3 | +RSpec.context 'sshkeys: Modify' do |
| 4 | + let(:keyname) { "pl#{rand(999_999).to_i}" } |
| 5 | + |
| 6 | + # FIXME: This is bletcherous |
| 7 | + let(:ssh_known_hosts) { '/etc/ssh/ssh_known_hosts' } |
| 8 | + |
| 9 | + before(:each) do |
| 10 | + posix_agents.agents.each do |agent| |
| 11 | + # The 'cp' might fail because the source file doesn't exist |
| 12 | + on( |
| 13 | + agent, |
| 14 | + "cp -fv #{ssh_known_hosts} /tmp/ssh_known_hosts", |
| 15 | + acceptable_exit_codes: [0, 1], |
| 16 | + ) |
| 17 | + cmd = <<-CMD |
| 18 | +echo '' > #{ssh_known_hosts} |
| 19 | +echo '#{keyname} ssh-rsa how_about_the_initial_rsa_key_of_c' >> #{ssh_known_hosts} |
| 20 | +echo '#{keyname} ssh-dss how_about_the_initial_dss_key_of_c' >> #{ssh_known_hosts} |
| 21 | +CMD |
| 22 | + on(agent, cmd) |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + after(:each) do |
| 27 | + posix_agents.each do |agent| |
| 28 | + # Is it present? |
| 29 | + rc = on( |
| 30 | + agent, |
| 31 | + '[ -e /tmp/ssh_known_hosts ]', |
| 32 | + accept_all_exit_codes: true, |
| 33 | + ) |
| 34 | + if rc.exit_code == 0 |
| 35 | + # It's present, so restore the original |
| 36 | + on( |
| 37 | + agent, |
| 38 | + "mv -fv /tmp/ssh_known_hosts #{ssh_known_hosts}", |
| 39 | + accept_all_exit_codes: true, |
| 40 | + ) |
| 41 | + else |
| 42 | + # It's missing, which means there wasn't one to backup; just |
| 43 | + # delete the one we laid down |
| 44 | + on( |
| 45 | + agent, |
| 46 | + "rm -fv #{ssh_known_hosts}", |
| 47 | + accept_all_exit_codes: true, |
| 48 | + ) |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + posix_agents.each do |agent| |
| 54 | + it "#{agent} should update an rsa entry for an SSH known host key" do |
| 55 | + args = ['ensure=present', |
| 56 | + "type='rsa'", |
| 57 | + "key='how_about_the_updated_rsa_key_of_c'"] |
| 58 | + on(agent, puppet_resource('sshkey', keyname.to_s, args)) |
| 59 | + |
| 60 | + on(agent, "cat #{ssh_known_hosts}") do |_res| |
| 61 | + expect(stdout).to include('how_about_the_updated_rsa_key_of_c') |
| 62 | + expect(stdout).not_to include('how_about_the_initial_rsa_key_of_c') |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + it "#{agent} should update an dss entry for an SSH known host key" do |
| 67 | + args = ['ensure=present', |
| 68 | + "type='ssh-dss'", |
| 69 | + "key='how_about_the_updated_dss_key_of_c'"] |
| 70 | + on(agent, puppet_resource('sshkey', keyname.to_s, args)) |
| 71 | + |
| 72 | + on(agent, "cat #{ssh_known_hosts}") do |_res| |
| 73 | + expect(stdout).to include('how_about_the_updated_dss_key_of_c') |
| 74 | + expect(stdout).not_to include('how_about_the_initial_dss_key_of_c') |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments