diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb index 69f23f3c2..a9448fe6c 100755 --- a/test/network/server/webrick.rb +++ b/test/network/server/webrick.rb @@ -1,146 +1,147 @@ #!/usr/bin/env ruby $:.unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppettest' require 'puppet/network/server/webrick' require 'mocha' class TestWebrickServer < Test::Unit::TestCase include PuppetTest::ServerTest def setup Puppet::Util::SUIDManager.stubs(:asuser).yields super end # Make sure we can create a server, and that it knows how to create its # certs by default. def test_basics server = nil assert_raise(Puppet::Error, "server succeeded with no cert") do server = Puppet::Network::Server::WEBrick.new( :Port => @@port, :Handlers => { :Status => nil } ) end assert_nothing_raised("Could not create simple server") do server = Puppet::Network::Server::WEBrick.new( :Port => @@port, :Handlers => { :CA => {}, # so that certs autogenerate :Status => nil } ) end assert(server, "did not create server") assert(server.cert, "did not retrieve cert") end # test that we can connect to the server # we have to use fork here, because we apparently can't use threads # to talk to other threads def test_connect_with_fork Puppet[:autosign] = true serverpid, server = mk_status_server # create a status client, and verify it can talk client = mk_status_client assert(client.cert, "did not get cert for client") retval = nil assert_nothing_raised("Could not connect to server") { retval = client.status } assert_equal(1, retval) end # Test that a client whose cert has been revoked really can't connect def test_certificate_revocation Puppet[:autosign] = true serverpid, server = mk_status_server client = mk_status_client status = nil assert_nothing_raised() { status = client.status } assert_equal(1, status) client.shutdown # Revoke the client's cert ca = Puppet::SSLCertificates::CA.new() ca.revoke(ca.getclientcert(Puppet[:certname])[0].serial) # Restart the server @@port += 1 Puppet[:autosign] = false kill_and_wait(serverpid, server.pidfile) serverpid, server = mk_status_server - client = mk_status_client - # This time the client should be denied - assert_raise(Puppet::Network::XMLRPCClientError) { - client.status + # This time the client should be denied. With keep-alive, + # the client starts its connection immediately, thus throwing + # the error. + assert_raise(OpenSSL::SSL::SSLError) { + client = Puppet::Network::Client.status.new(:Server => "localhost", :Port => @@port) } end def mk_status_client client = nil # Otherwise, the client initalization will trip over itself # since elements created in the last run are still around Puppet::Type::allclear assert_nothing_raised() { client = Puppet::Network::Client.status.new( :Server => "localhost", :Port => @@port ) } client end def mk_status_server server = nil assert_nothing_raised() { server = Puppet::Network::Server::WEBrick.new( :Port => @@port, :Handlers => { :CA => {}, # so that certs autogenerate :Status => nil } ) } pid = fork { Puppet[:name] = "puppetmasterd" assert_nothing_raised() { trap(:INT) { server.shutdown } server.start } } @@tmppids << pid [pid, server] end def kill_and_wait(pid, file) %x{kill -INT #{pid} 2>/dev/null} count = 0 while count < 30 && File::exist?(file) count += 1 sleep(1) end assert(count < 30, "Killing server #{pid} failed") end end # $Id$ diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb index 19db3fe05..383153e45 100755 --- a/test/puppet/defaults.rb +++ b/test/puppet/defaults.rb @@ -1,99 +1,73 @@ #!/usr/bin/env ruby $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppet' require 'puppettest' # $Id$ class TestPuppetDefaults < Test::Unit::TestCase include PuppetTest @@dirs = %w{rrddir confdir vardir logdir statedir} @@files = %w{statefile manifest masterlog} @@normals = %w{puppetport masterport server} @@booleans = %w{rrdgraph noop} def testVersion assert( Puppet.version =~ /^[0-9]+(\.[0-9]+)*/, "got invalid version number %s" % Puppet.version ) end def testStringOrParam [@@dirs,@@files,@@booleans].flatten.each { |param| assert_nothing_raised { Puppet[param] } assert_nothing_raised { Puppet[param.intern] } } end def test_valuesForEach [@@dirs,@@files,@@booleans].flatten.each { |param| param = param.intern assert_nothing_raised { Puppet[param] } } end def testValuesForEach [@@dirs,@@files,@@booleans].flatten.each { |param| assert_nothing_raised { Puppet[param] } } end - if __FILE__ == $0 - def disabled_testContained - confdir = Regexp.new(Puppet[:confdir]) - vardir = Regexp.new(Puppet[:vardir]) - [@@dirs,@@files].flatten.each { |param| - value = Puppet[param] - - unless value =~ confdir or value =~ vardir - assert_nothing_raised { raise "%s is in wrong dir: %s" % - [param,value] } - end - } - end - end - - def testArgumentTypes - assert_raise(ArgumentError) { Puppet[["string"]] } - assert_raise(ArgumentError) { Puppet[[:symbol]] } - end - - def testFailOnBogusArgs - [0, "ashoweklj", ";"].each { |param| - assert_raise(ArgumentError, "No error on %s" % param) { Puppet[param] } - } - end - # we don't want user defaults in /, or root defaults in ~ def testDefaultsInCorrectRoots notval = nil if Puppet::Util::SUIDManager.uid == 0 notval = Regexp.new(File.expand_path("~")) else notval = /^\/var|^\/etc/ end [@@dirs,@@files].flatten.each { |param| value = Puppet[param] unless value !~ notval assert_nothing_raised { raise "%s is incorrectly set to %s" % [param,value] } end } end def test_settingdefaults testvals = { :fakeparam => "$confdir/yaytest", :anotherparam => "$vardir/goodtest", :string => "a yay string", :boolean => true } testvals.each { |param, default| assert_nothing_raised { Puppet.setdefaults("testing", param => [default, "a value"]) } } end end diff --git a/test/rails/collection.rb b/test/rails/collection.rb index 18de3c77b..31aa02928 100755 --- a/test/rails/collection.rb +++ b/test/rails/collection.rb @@ -1,239 +1,239 @@ #!/usr/bin/env ruby $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppet' require 'puppet/rails' require 'puppettest' require 'puppettest/railstesting' require 'puppettest/resourcetesting' # A separate class for testing rails integration class TestRailsCollection < PuppetTest::TestCase confine "Missing rails support" => Puppet.features.rails? include PuppetTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting include PuppetTest::RailsTesting Parser = Puppet::Parser AST = Parser::AST def setup super Puppet[:trace] = false @scope = mkscope end def test_collect_exported railsinit # make an exported resource exported = mkresource(:type => "file", :title => "/tmp/exported", :exported => true, :params => {:owner => "root"}) @scope.setresource exported assert(exported.exported?, "Object was not marked exported") assert(exported.virtual?, "Object was not marked virtual") # And a non-exported real = mkresource(:type => "file", :title => "/tmp/real", :params => {:owner => "root"}) @scope.setresource real # Now make a collector coll = nil assert_nothing_raised do coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :exported) end # Set it in our scope - @scope.configuration.add_collection(coll) + @scope.compile.add_collection(coll) # Make sure it's in the collections - assert_equal([coll], @scope.configuration.collections) + assert_equal([coll], @scope.compile.collections) # And try to collect the virtual resources. ret = nil assert_nothing_raised do ret = coll.collect_exported end assert_equal([exported], ret) # Now make sure evaluate does the right thing. assert_nothing_raised do ret = coll.evaluate end # Make sure that the collection does not find the resource on the # next run. ret = nil assert_nothing_raised do ret = coll.collect_exported end assert(ret.empty?, "Exported resource was collected on the second run") # And make sure our exported object is no longer exported assert(! exported.virtual?, "Virtual object did not get realized") # But it should still be marked exported. assert(exported.exported?, "Resource got un-exported") # Now make a new collector of a different type and make sure it # finds nothing. assert_nothing_raised do coll = Puppet::Parser::Collector.new(@scope, "exec", nil, nil, :exported) end # Remark this as virtual exported.virtual = true assert_nothing_raised do ret = coll.evaluate end assert(! ret, "got resources back") # Now create a whole new scope and make sure we can actually retrieve # the resource from the database, not just from the scope. # First create a host object and store our resource in it. # Now collect our facts facts = {} Facter.each do |fact, value| facts[fact] = value end # Now try storing our crap # Remark this as exported exported.exported = true exported.scope.stubs(:tags).returns([]) node = mknode(facts["hostname"]) node.parameters = facts host = Puppet::Rails::Host.store(node, [exported]) assert(host, "did not get rails host") host.save # And make sure it's in there newres = host.resources.find_by_restype_and_title_and_exported("file", "/tmp/exported", true) assert(newres, "Did not find resource in db") assert(newres.exported?, "Resource was not exported") # Make a new set with a different node name node = mknode("other") - config = Puppet::Parser::Configuration.new(node, mkparser) + config = Puppet::Parser::Compile.new(node, mkparser) config.topscope.source = mock("source") # It's important that it's a different name, since same-name resources are ignored. assert_equal("other", config.node.name, "Did not get correct node name") # Now make a collector coll = nil assert_nothing_raised do coll = Puppet::Parser::Collector.new(config.topscope, "file", nil, nil, :exported) end # And try to collect the virtual resources. ret = nil assert_nothing_raised("Could not collect exported resources") do ret = coll.collect_exported end assert_equal(["/tmp/exported"], ret.collect { |f| f.title }, "Did not find resource in collction") # Make sure we can evaluate the same collection multiple times and # that later collections do nothing assert_nothing_raised("Collection found same resource twice") do ret = coll.evaluate end end def test_collection_conflicts railsinit # First make a railshost we can conflict with host = Puppet::Rails::Host.new(:name => "myhost") host.resources.build(:title => "/tmp/conflicttest", :restype => "file", :exported => true) host.save # Now make a normal resource normal = mkresource(:type => "file", :title => "/tmp/conflicttest", :params => {:owner => "root"}) @scope.setresource normal # Now make a collector coll = nil assert_nothing_raised do coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :exported) end # And try to collect the virtual resources. assert_raise(Puppet::ParseError) do ret = coll.collect_exported end end # Make sure we do not collect resources from the host we're on def test_no_resources_from_me railsinit # Make our configuration host = Puppet::Rails::Host.new(:name => @scope.host) host.resources.build(:title => "/tmp/hosttest", :restype => "file", :exported => true) host.save # Now make a collector coll = nil assert_nothing_raised do coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :exported) end # And make sure we get nada back ret = nil assert_nothing_raised do ret = coll.collect_exported end assert(ret.empty?, "Found exports from our own host") end # #731 -- we're collecting all resources, not just exported resources. def test_only_collecting_exported_resources railsinit # Make our configuration host = Puppet::Rails::Host.new(:name => "myhost") host.resources.build(:title => "/tmp/exporttest1", :restype => "file", :exported => true) host.resources.build(:title => "/tmp/exporttest2", :restype => "file", :exported => false) host.save # Now make a collector coll = nil assert_nothing_raised do coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :exported) end # And make sure we get nada back ret = nil assert_nothing_raised do ret = coll.collect_exported end names = ret.collect { |res| res.title } assert_equal(%w{/tmp/exporttest1}, names, "Collected incorrect resource list") end end # $Id$