summaryrefslogtreecommitdiffstats
path: root/test/client
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-09 22:47:32 +0000
committerLuke Kanies <luke@madstop.com>2005-08-09 22:47:32 +0000
commitbb4b5a544e85e5a56065ebb5dd175fbdea7280d2 (patch)
treec26ed941fe70d4674a6bea700135dd76f58a8d8c /test/client
parente2e247428faa15c299a5dc7bc802afa4a2dbc74a (diff)
downloadpuppet-bb4b5a544e85e5a56065ebb5dd175fbdea7280d2.tar.gz
puppet-bb4b5a544e85e5a56065ebb5dd175fbdea7280d2.tar.xz
puppet-bb4b5a544e85e5a56065ebb5dd175fbdea7280d2.zip
done a lot of work on certificates; all tests except one puppetca test pass
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@523 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/client')
-rw-r--r--test/client/tc_client.rb123
1 files changed, 98 insertions, 25 deletions
diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb
index 33f40dcf0..2ddf53c98 100644
--- a/test/client/tc_client.rb
+++ b/test/client/tc_client.rb
@@ -7,36 +7,109 @@ end
require 'puppet'
require 'puppet/client'
-#require 'puppet/server'
-require 'puppet/fact'
+require 'puppet/server'
require 'test/unit'
require 'puppettest.rb'
# $Id$
class TestClient < Test::Unit::TestCase
-# def test_local
-# client = nil
-# server = nil
-# assert_nothing_raised() {
-# server = Puppet::Master.new(
-# :File => file,
-# :Local => true
-# )
-# }
-# assert_nothing_raised() {
-# client = Puppet::Client.new(:Server => server)
-# }
-#
-# facts = %w{operatingsystem operatingsystemrelease}
-# facts.each { |fact|
-# assert_equal(
-# Puppet::Fact[fact],
-# client.callfunc("fact",fact)
-# )
-# }
-# end
-
- def test_files
+ def setup
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ @@tmpfiles = []
+ end
+
+ def teardown
+ Puppet::Type.allclear
+ @@tmpfiles.each { |f|
+ if FileTest.exists?(f)
+ system("rm -rf %s" % f)
+ end
+ }
+ end
+
+ def test_sslInitWithAutosigningLocalServer
+ Puppet[:autosign] = true
+ Puppet[:ssldir] = "/tmp/puppetclientcertests"
+ @@tmpfiles.push Puppet[:ssldir]
+
+ file = File.join($puppetbase, "examples", "code", "head")
+
+ server = nil
+ assert_nothing_raised {
+ server = Puppet::Master.new(
+ :File => file,
+ :Local => true,
+ :CA => true
+ )
+ }
+ client = nil
+ assert_nothing_raised {
+ client = Puppet::Client.new(:Server => server)
+ }
+ assert_nothing_raised {
+ client.initcerts
+ }
+
+ certfile = File.join(Puppet[:certdir], [client.fqdn, "pem"].join("."))
+ keyfile = File.join(Puppet[:privatekeydir], [client.fqdn, "pem"].join("."))
+ publickeyfile = File.join(Puppet[:publickeydir], [client.fqdn, "pem"].join("."))
+
+ assert(File.exists?(keyfile))
+ assert(File.exists?(certfile))
+ assert(File.exists?(publickeyfile))
+ end
+
+ def test_sslInitWithNonsigningLocalServer
+ Puppet[:autosign] = false
+ Puppet[:ssldir] = "/tmp/puppetclientcertests"
+ @@tmpfiles.push Puppet[:ssldir]
+
+ file = File.join($puppetbase, "examples", "code", "head")
+
+ server = nil
+ assert_nothing_raised {
+ server = Puppet::Master.new(
+ :File => file,
+ :Local => true,
+ :CA => true
+ )
+ }
+ client = nil
+ assert_nothing_raised {
+ client = Puppet::Client.new(:Server => server)
+ }
+ certfile = File.join(Puppet[:certdir], [client.fqdn, "pem"].join("."))
+ assert_raise(Puppet::Error) {
+ client.initcerts
+ }
+ assert(! File.exists?(certfile))
+
+ ca = nil
+ assert_nothing_raised {
+ ca = Puppet::SSLCertificates::CA.new()
+ }
+
+
+ csr = nil
+ assert_nothing_raised {
+ csr = ca.getclientcsr(client.fqdn)
+ }
+
+ assert(csr)
+
+ cert = nil
+ assert_nothing_raised {
+ cert = ca.sign(csr)
+ File.open(certfile, "w") { |f| f.print cert.to_pem }
+ }
+
+ # this time it should get the cert correctly
+ assert_nothing_raised {
+ client.initcerts
+ }
+
+ # this isn't a very good test, since i just wrote the file out
+ assert(File.exists?(certfile))
end
end