|
3 | 3 | require 'puppet_spec/puppetserver'
|
4 | 4 | require 'puppet_spec/compiler'
|
5 | 5 | require 'puppet_spec/https'
|
| 6 | +require 'puppet/application/agent' |
6 | 7 |
|
7 | 8 | describe "puppet agent", unless: Puppet::Util::Platform.jruby? do
|
8 | 9 | include PuppetSpec::Files
|
@@ -737,4 +738,112 @@ def with_another_agent_running(&block)
|
737 | 738 | end
|
738 | 739 | end
|
739 | 740 | end
|
| 741 | + |
| 742 | + context "ssl" do |
| 743 | + context "bootstrapping" do |
| 744 | + before :each do |
| 745 | + # reconfigure ssl to non-existent dir and files to force bootstrapping |
| 746 | + dir = tmpdir('ssl') |
| 747 | + Puppet[:ssldir] = dir |
| 748 | + Puppet[:localcacert] = File.join(dir, 'ca.pem') |
| 749 | + Puppet[:hostcrl] = File.join(dir, 'crl.pem') |
| 750 | + Puppet[:hostprivkey] = File.join(dir, 'cert.pem') |
| 751 | + Puppet[:hostcert] = File.join(dir, 'key.pem') |
| 752 | + |
| 753 | + Puppet[:daemonize] = false |
| 754 | + Puppet[:logdest] = 'console' |
| 755 | + Puppet[:log_level] = 'info' |
| 756 | + end |
| 757 | + |
| 758 | + it "exits if the agent is not allowed to wait" do |
| 759 | + Puppet[:waitforcert] = 0 |
| 760 | + |
| 761 | + server.start_server do |port| |
| 762 | + Puppet[:serverport] = port |
| 763 | + expect { |
| 764 | + agent.run |
| 765 | + }.to exit_with(1) |
| 766 | + .and output(%r{Exiting now because the waitforcert setting is set to 0}).to_stdout |
| 767 | + .and output(%r{Failed to submit the CSR, HTTP response was 404}).to_stderr |
| 768 | + end |
| 769 | + end |
| 770 | + |
| 771 | + it "exits if the maxwaitforcert time is exceeded" do |
| 772 | + Puppet[:waitforcert] = 1 |
| 773 | + Puppet[:maxwaitforcert] = 1 |
| 774 | + |
| 775 | + server.start_server do |port| |
| 776 | + Puppet[:serverport] = port |
| 777 | + expect { |
| 778 | + agent.run |
| 779 | + }.to exit_with(1) |
| 780 | + .and output(%r{Couldn't fetch certificate from CA server; you might still need to sign this agent's certificate \(127.0.0.1\). Exiting now because the maxwaitforcert timeout has been exceeded.}).to_stdout |
| 781 | + .and output(%r{Failed to submit the CSR, HTTP response was 404}).to_stderr |
| 782 | + end |
| 783 | + end |
| 784 | + end |
| 785 | + |
| 786 | + def copy_fixtures(sources, dest) |
| 787 | + ssldir = File.join(PuppetSpec::FIXTURE_DIR, 'ssl') |
| 788 | + File.open(dest, 'w') do |f| |
| 789 | + sources.each do |s| |
| 790 | + f.write(File.read(File.join(ssldir, s))) |
| 791 | + end |
| 792 | + end |
| 793 | + end |
| 794 | + |
| 795 | + it "reloads the CRL between runs" do |
| 796 | + Puppet[:localcacert] = ca = tmpfile('ca') |
| 797 | + Puppet[:hostcrl] = crl = tmpfile('crl') |
| 798 | + Puppet[:hostcert] = cert = tmpfile('cert') |
| 799 | + Puppet[:hostprivkey] = key = tmpfile('key') |
| 800 | + |
| 801 | + copy_fixtures(%w[ca.pem intermediate.pem], ca) |
| 802 | + copy_fixtures(%w[crl.pem intermediate-crl.pem], crl) |
| 803 | + copy_fixtures(%w[127.0.0.1.pem], cert) |
| 804 | + copy_fixtures(%w[127.0.0.1-key.pem], key) |
| 805 | + |
| 806 | + revoked = cert_fixture('revoked.pem') |
| 807 | + revoked_key = key_fixture('revoked-key.pem') |
| 808 | + |
| 809 | + mounts = {} |
| 810 | + mounts[:catalog] = -> (req, res) { |
| 811 | + catalog = compile_to_catalog(<<~MANIFEST, node) |
| 812 | + file { '#{cert}': |
| 813 | + ensure => file, |
| 814 | + content => '#{revoked}' |
| 815 | + } |
| 816 | + file { '#{key}': |
| 817 | + ensure => file, |
| 818 | + content => '#{revoked_key}' |
| 819 | + } |
| 820 | + MANIFEST |
| 821 | + |
| 822 | + res.body = formatter.render(catalog) |
| 823 | + res['Content-Type'] = formatter.mime |
| 824 | + } |
| 825 | + |
| 826 | + server.start_server(mounts: mounts) do |port| |
| 827 | + Puppet[:serverport] = port |
| 828 | + Puppet[:daemonize] = false |
| 829 | + Puppet[:runinterval] = 1 |
| 830 | + Puppet[:waitforcert] = 1 |
| 831 | + Puppet[:maxwaitforcert] = 1 |
| 832 | + |
| 833 | + # simulate two runs of the agent, then return so we don't infinite loop |
| 834 | + allow_any_instance_of(Puppet::Daemon).to receive(:run_event_loop) do |instance| |
| 835 | + instance.agent.run(splay: false) |
| 836 | + instance.agent.run(splay: false) |
| 837 | + end |
| 838 | + |
| 839 | + pending("PUP-11428: the second run should fail due to the revoked client cert") |
| 840 | + agent.command_line.args << '--verbose' |
| 841 | + expect { |
| 842 | + agent.run |
| 843 | + }.to exit_with(1) |
| 844 | + .and output(%r{Exiting now because the maxwaitforcert timeout has been exceeded}).to_stdout |
| 845 | + .and output(%r{Certificate 'CN=revoked' is revoked}).to_stderr |
| 846 | + end |
| 847 | + end |
| 848 | + end |
740 | 849 | end
|
0 commit comments