diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-30 23:17:40 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-30 23:17:40 +0000 |
| commit | 4615e3a70cf53ba62a00d5d8f01a6d0ec9dffc26 (patch) | |
| tree | 87245a7401376531048c90e6b8afcddf1b1a452a | |
| parent | ca5d0682705a3b5ee175e25b6cb5fca939a85443 (diff) | |
| download | puppet-4615e3a70cf53ba62a00d5d8f01a6d0ec9dffc26.tar.gz puppet-4615e3a70cf53ba62a00d5d8f01a6d0ec9dffc26.tar.xz puppet-4615e3a70cf53ba62a00d5d8f01a6d0ec9dffc26.zip | |
Fixing Client.read_cert so that it automatically adds the certificate information to the driver when the certificate is correctly read. This makes sure the Net::Http instance has the cert all set up.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2375 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | bin/puppetd | 4 | ||||
| -rw-r--r-- | lib/puppet/network/client.rb | 12 | ||||
| -rwxr-xr-x | test/network/client/client.rb | 47 |
3 files changed, 56 insertions, 7 deletions
diff --git a/bin/puppetd b/bin/puppetd index 981e2c1ae..35d053b4e 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -346,7 +346,9 @@ unless client.read_cert end # Now read the new cert in. - unless client.read_cert + if client.read_cert + Puppet.notice "Got signed certificate" + else Puppet.err "Could not read certificates after retrieving them" exit(34) end diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb index 13f1878fd..5603aeb43 100644 --- a/lib/puppet/network/client.rb +++ b/lib/puppet/network/client.rb @@ -36,6 +36,8 @@ class Puppet::Network::Client attr_accessor :schedule, :lastrun, :local, :stopping + attr_reader :driver + # Set up subclass loading handle_subclasses :client, "puppet/network/client" @@ -109,6 +111,16 @@ class Puppet::Network::Client end end + # Make sure we set the driver up when we read the cert in. + def read_cert + if super + @driver.cert_setup(self) if @driver.respond_to?(:cert_setup) + return true + else + return false + end + end + # A wrapper method to run and then store the last run time def runnow if self.stopping diff --git a/test/network/client/client.rb b/test/network/client/client.rb index 91f2f25af..75f36c81b 100755 --- a/test/network/client/client.rb +++ b/test/network/client/client.rb @@ -3,10 +3,18 @@ $:.unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppettest' +require 'mocha' require 'puppet/network/client' class TestClient < Test::Unit::TestCase include PuppetTest::ServerTest + class FakeClient < Puppet::Network::Client + @drivername = :Test + end + + class FakeDriver + end + # a single run through of connect, auth, etc. def disabled_test_sslInitWithAutosigningLocalServer # autosign everything, for simplicity @@ -180,10 +188,10 @@ class TestClient < Test::Unit::TestCase libdir = File.join([dir, %w{puppet network client}].flatten) FileUtils.mkdir_p(libdir) - file = File.join(libdir, "fake.rb") + file = File.join(libdir, "faker.rb") File.open(file, "w") do |f| f.puts %{class Puppet::Network::Client - class Fake < Client + class Faker < Client end end } @@ -194,16 +202,16 @@ class TestClient < Test::Unit::TestCase client = nil assert_nothing_raised do - client = Puppet::Network::Client.client(:fake) + client = Puppet::Network::Client.client(:faker) end + assert(client, "did not load client") assert_nothing_raised do - assert_equal(client, Puppet::Network::Client.fake, + assert_equal(client, Puppet::Network::Client.faker, "Did not get client back from client method") end - assert(client, "did not load client") # Now make sure the client behaves correctly - assert_equal(:Fake, client.name, "name was not calculated correctly") + assert_equal(:Faker, client.name, "name was not calculated correctly") end # Make sure we get a client class for each handler type. @@ -219,6 +227,33 @@ class TestClient < Test::Unit::TestCase end end end + + # Make sure that reading the cert in also sets up the cert stuff for the driver + def test_read_cert + ca = Puppet::Network::Handler.ca.new + caclient = Puppet::Network::Client.ca.new :CA => ca + + caclient.request_cert + + # First make sure it doesn't get called when the driver doesn't support :cert_setup + client = FakeClient.new :Test => FakeDriver.new + driver = client.driver + + assert_nothing_raised("Could not read cert") do + client.read_cert + end + + # And then that it does when the driver supports it + client = FakeClient.new :Test => FakeDriver.new + + driver = client.driver + driver.meta_def(:cert_setup) { |c| } + driver.expects(:cert_setup).with(client) + + assert_nothing_raised("Could not read cert") do + client.read_cert + end + end end # $Id$ |
