diff options
Diffstat (limited to 'spec')
44 files changed, 668 insertions, 200 deletions
diff --git a/spec/integration/bin/puppetmasterd.rb b/spec/integration/bin/puppetmasterd.rb index 2dcd593d3..579a42d88 100755 --- a/spec/integration/bin/puppetmasterd.rb +++ b/spec/integration/bin/puppetmasterd.rb @@ -51,7 +51,8 @@ describe "puppetmasterd" do args = arguments + addl_args bin = File.join(File.dirname(__FILE__), "..", "..", "..", "sbin", "puppetmasterd") - output = %x{#{bin} #{args}}.chomp + lib = File.join(File.dirname(__FILE__), "..", "..", "..", "lib") + output = %x{/usr/bin/env ruby -I #{lib} #{bin} #{args}}.chomp end def stop @@ -72,7 +73,7 @@ describe "puppetmasterd" do it "should be serving status information over xmlrpc" do start - sleep 0.5 + sleep 5 client = Puppet::Network::Client.status.new(:Server => "localhost", :Port => @@port) diff --git a/spec/integration/file_serving/metadata.rb b/spec/integration/file_serving/metadata.rb index 10c884f47..bd105e412 100755 --- a/spec/integration/file_serving/metadata.rb +++ b/spec/integration/file_serving/metadata.rb @@ -7,6 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/metadata' require 'shared_behaviours/file_serving' +require 'puppet/indirector/file_metadata/file_server' describe Puppet::FileServing::Metadata, " when finding files" do it_should_behave_like "Puppet::FileServing::Files" diff --git a/spec/integration/indirector/file_content/file_server.rb b/spec/integration/indirector/file_content/file_server.rb index ea892302e..e8f777ef8 100755 --- a/spec/integration/indirector/file_content/file_server.rb +++ b/spec/integration/indirector/file_content/file_server.rb @@ -29,9 +29,10 @@ describe Puppet::Indirector::FileContent::FileServer, " when finding files" do file = File.join(modpath, "lib", "file.rb") File.open(file, "w") { |f| f.puts "1" } + Puppet.settings[:modulepath] = "/no/such/file" + env = Puppet::Node::Environment.new("foo") env.stubs(:modulepath).returns [path] - Puppet.settings[:modulepath] = "/no/such/file" result = Puppet::FileServing::Content.search("plugins", :environment => "foo", :recurse => true) diff --git a/spec/integration/ssl/certificate_request.rb b/spec/integration/ssl/certificate_request.rb index 3be018b82..1a7241fa5 100755 --- a/spec/integration/ssl/certificate_request.rb +++ b/spec/integration/ssl/certificate_request.rb @@ -22,6 +22,8 @@ describe Puppet::SSL::CertificateRequest do Puppet.settings[:confdir] = @dir Puppet.settings[:vardir] = @dir + Puppet::SSL::Host.ca_location = :none + @csr = Puppet::SSL::CertificateRequest.new("luke.madstop.com") @key = OpenSSL::PKey::RSA.new(512) diff --git a/spec/shared_behaviours/file_serving.rb b/spec/shared_behaviours/file_serving.rb index 8aad8885a..876889475 100644 --- a/spec/shared_behaviours/file_serving.rb +++ b/spec/shared_behaviours/file_serving.rb @@ -26,7 +26,7 @@ describe "Puppet::FileServing::Files", :shared => true do it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'puppet'" do uri = "puppet:///fakemod/my/file" - Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil)) + Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => [])) Puppet.settings.stubs(:value).returns "" Puppet.settings.stubs(:value).with(:name).returns("puppet") Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever") diff --git a/spec/unit/application/puppet.rb b/spec/unit/application/puppet.rb index 8fb364cdd..be200bb89 100755 --- a/spec/unit/application/puppet.rb +++ b/spec/unit/application/puppet.rb @@ -317,70 +317,51 @@ describe "Puppet" do end describe "the 'apply' command" do - confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson? - - before do - #Puppet::Resource::Catalog.stubs(:pson_create).returns Puppet::Resource::Catalog.new - PSON.stubs(:parse).returns Puppet::Resource::Catalog.new - end - it "should read the catalog in from disk if a file name is provided" do @puppet.options[:catalog] = "/my/catalog.pson" - File.expects(:read).with("/my/catalog.pson").returns "something" - + Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new @puppet.apply end it "should read the catalog in from stdin if '-' is provided" do @puppet.options[:catalog] = "-" - $stdin.expects(:read).returns "something" - + Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new @puppet.apply end - it "should deserialize the catalog from pson" do + it "should deserialize the catalog from the default format" do @puppet.options[:catalog] = "/my/catalog.pson" - - File.expects(:read).returns "something" - PSON.expects(:parse).with("something").returns Puppet::Resource::Catalog.new - + File.stubs(:read).with("/my/catalog.pson").returns "something" + Puppet::Resource::Catalog.stubs(:default_format).returns :rot13_piglatin + Puppet::Resource::Catalog.stubs(:convert_from).with(:rot13_piglatin,'something').returns Puppet::Resource::Catalog.new @puppet.apply end it "should fail helpfully if deserializing fails" do @puppet.options[:catalog] = "/my/catalog.pson" - - File.expects(:read).returns "something" - PSON.expects(:parse).raises ArgumentError - + File.stubs(:read).with("/my/catalog.pson").returns "something syntacically invalid" lambda { @puppet.apply }.should raise_error(Puppet::Error) end it "should convert plain data structures into a catalog if deserialization does not do so" do @puppet.options[:catalog] = "/my/catalog.pson" - - File.expects(:read).returns "something" - PSON.expects(:parse).with("something").returns({:foo => "bar"}) + File.stubs(:read).with("/my/catalog.pson").returns "something" + Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,"something").returns({:foo => "bar"}) Puppet::Resource::Catalog.expects(:pson_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new) - @puppet.apply end it "should convert the catalog to a RAL catalog and use a Configurer instance to apply it" do @puppet.options[:catalog] = "/my/catalog.pson" - - File.expects(:read).returns "something" - + File.stubs(:read).with("/my/catalog.pson").returns "something" catalog = Puppet::Resource::Catalog.new - PSON.expects(:parse).returns catalog - + Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns catalog catalog.expects(:to_ral).returns "mycatalog" configurer = stub 'configurer' Puppet::Configurer.expects(:new).returns configurer - configurer.expects(:run).with(:catalog => "mycatalog") @puppet.apply diff --git a/spec/unit/application/puppetd.rb b/spec/unit/application/puppetd.rb index 04c6daf32..9b8d1bea3 100755 --- a/spec/unit/application/puppetd.rb +++ b/spec/unit/application/puppetd.rb @@ -173,6 +173,7 @@ describe "puppetd" do Puppet.stubs(:info) FileTest.stubs(:exists?).returns(true) Puppet.stubs(:[]) + Puppet.stubs(:[]).with(:libdir).returns("/dev/null/lib") Puppet.settings.stubs(:print_config?) Puppet.settings.stubs(:print_config) Puppet::SSL::Host.stubs(:ca_location=) diff --git a/spec/unit/application/puppetdoc.rb b/spec/unit/application/puppetdoc.rb index cb60581a4..413fa1186 100755 --- a/spec/unit/application/puppetdoc.rb +++ b/spec/unit/application/puppetdoc.rb @@ -293,7 +293,7 @@ describe "puppetdoc" do @env = stub 'env' Puppet::Node::Environment.stubs(:new).returns(@env) @env.stubs(:modulepath).returns(['modules']) - @env.stubs(:manifestdir).returns(['manifests']) + @env.stubs(:[]).with(:manifest).returns('manifests/site.pp') @puppetdoc.options.stubs(:[]).with(:all).returns(false) @puppetdoc.options.stubs(:[]).with(:outputdir).returns('doc') Puppet.settings.stubs(:[]=).with(:document_all, false) @@ -334,9 +334,9 @@ describe "puppetdoc" do it "should get modulepath and manifestdir values from the environment" do @env.expects(:modulepath).returns(['envmodules1','envmodules2']) - @env.expects(:manifestdir).returns(['envmanifests1','envmanifests2']) + @env.expects(:[]).with(:manifest).returns('envmanifests/site.pp') - Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests1','envmanifests2']) + Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests']) @puppetdoc.rdoc end diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/puppetmasterd.rb index 980138782..f522fccc1 100644 --- a/spec/unit/application/puppetmasterd.rb +++ b/spec/unit/application/puppetmasterd.rb @@ -237,6 +237,7 @@ describe "PuppetMaster" do it "should dispatch to parseonly if parseonly is set" do Puppet.stubs(:[]).with(:parseonly).returns(true) + @puppetmasterd.options[:node] = nil @puppetmasterd.get_command.should == :parseonly end diff --git a/spec/unit/application/puppetrun.rb b/spec/unit/application/puppetrun.rb index d44b406e9..26811f0db 100755 --- a/spec/unit/application/puppetrun.rb +++ b/spec/unit/application/puppetrun.rb @@ -144,11 +144,21 @@ describe "puppetrun" do Puppet.stubs(:[]).with(:node_terminus).returns("ldap") end + it "should pass the fqdn option to search" do + @puppetrun.options.stubs(:[]).with(:fqdn).returns(:something) + @puppetrun.options.stubs(:[]).with(:all).returns(true) + @puppetrun.stubs(:puts) + + Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([]) + + @puppetrun.run_setup + end + it "should search for all nodes if --all" do @puppetrun.options.stubs(:[]).with(:all).returns(true) @puppetrun.stubs(:puts) - Puppet::Node.expects(:search).with("whatever").returns([]) + Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([]) @puppetrun.run_setup end @@ -158,7 +168,7 @@ describe "puppetrun" do @puppetrun.stubs(:puts) @puppetrun.classes = ['class'] - Puppet::Node.expects(:search).with("whatever", :class => "class").returns([]) + Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([]) @puppetrun.run_setup end diff --git a/spec/unit/application/ralsh.rb b/spec/unit/application/ralsh.rb index dbc196cdf..b0fa3bdc2 100755 --- a/spec/unit/application/ralsh.rb +++ b/spec/unit/application/ralsh.rb @@ -132,17 +132,34 @@ describe "ralsh" do describe "when running" do + def set_args(args) + (ARGV.clear << args).flatten! + end + + def push_args(*args) + @args_stack ||= [] + @args_stack << ARGV.dup + set_args(args) + end + + def pop_args + set_args(@args_stack.pop) + end + before :each do @type = stub_everything 'type', :properties => [] - ARGV.stubs(:shift).returns("type") - ARGV.stubs(:length).returns(1).then.returns(0) + push_args('type') Puppet::Type.stubs(:type).returns(@type) end - it "should raise an error if no type is given" do - ARGV.stubs(:length).returns(0) + after :each do + pop_args + end + it "should raise an error if no type is given" do + push_args lambda { @ralsh.main }.should raise_error + pop_args end it "should raise an error when editing a remote host" do @@ -186,11 +203,10 @@ describe "ralsh" do end it "should describe the given resource" do - ARGV.stubs(:shift).returns("type").then.returns('name') - ARGV.stubs(:length).returns(1).then.returns(1).then.returns(0) + push_args('type','name') @client.expects(:describe).returns(stub_everything) - @ralsh.main + pop_args end end @@ -208,30 +224,31 @@ describe "ralsh" do describe 'but with a given name' do before :each do - ARGV.stubs(:shift).returns("type").then.returns('name') - ARGV.stubs(:length).returns(1).then.returns(1).then.returns(0) - @object = stub_everything 'object', :to_trans => stub_everything('transportable') - @type.stubs(:new).returns(@object) - @object.stubs(:retrieve) + push_args('type','name') + @type.stubs(:new).returns(:bob) end - it "should retrieve a specific instance" do - @type.expects(:new).returns(@object) - @object.expects(:retrieve) + after :each do + pop_args + end - @ralsh.main + it "should retrieve a specific instance if it exists" do + pending end - it "should add given parameters to object" do - ARGV.stubs(:each).yields('param=temp') - ARGV.stubs(:length).returns(1).then.returns(1).then.returns(1) - Puppet::Resource::Catalog.stubs(:new).returns(stub_everything) - @object.expects(:[]=).with('param','temp') + it "should create a stub instance if it doesn't exist" do + pending + end + + it "should add given parameters to the object" do + push_args('type','name','param=temp') + pending + @object.expects(:[]=).with('param','temp') @ralsh.main + pop_args end end end - end end diff --git a/spec/unit/configurer/fact_handler.rb b/spec/unit/configurer/fact_handler.rb index ec60c6dcd..290f1acfc 100755 --- a/spec/unit/configurer/fact_handler.rb +++ b/spec/unit/configurer/fact_handler.rb @@ -97,6 +97,7 @@ describe Puppet::Configurer::FactHandler do # I couldn't get marshal to work for this, only yaml, so we hard-code yaml. it "should serialize and CGI escape the fact values for uploading" do facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true facts.expects(:render).returns "my text" text = CGI.escape("my text") @@ -107,6 +108,7 @@ describe Puppet::Configurer::FactHandler do it "should properly accept facts containing a '+'" do facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true facts.expects(:render).returns "my+text" text = "my%2Btext" @@ -115,8 +117,9 @@ describe Puppet::Configurer::FactHandler do @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text} end - it "should hard-code yaml as the serialization" do + it "use compressed yaml as the serialization if zlib is supported" do facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true facts.expects(:render).with(:b64_zlib_yaml).returns "my text" text = CGI.escape("my text") @@ -125,6 +128,17 @@ describe Puppet::Configurer::FactHandler do @facthandler.facts_for_uploading end + it "should use yaml as the serialization if zlib is not supported" do + facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns false + facts.expects(:render).with(:yaml).returns "my text" + text = CGI.escape("my text") + + @facthandler.expects(:find_facts).returns facts + + @facthandler.facts_for_uploading + end + describe "when reloading Facter" do before do Facter.stubs(:clear) diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb index c27efd6bb..22f033d4d 100755 --- a/spec/unit/file_serving/metadata.rb +++ b/spec/unit/file_serving/metadata.rb @@ -86,7 +86,7 @@ describe Puppet::FileServing::Metadata do end it "should pass the checksum in the hash as a nested hash" do - @metadata.to_pson_data_hash['data']['checksum'].should be_is_a Hash + @metadata.to_pson_data_hash['data']['checksum'].should be_is_a(Hash) end it "should pass the checksum_type in the hash verbatum as the checksum's type" do @@ -107,6 +107,10 @@ describe Puppet::FileServing::Metadata, " when finding the file to use for setti # Use a link because it's easier to test -- no checksumming @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "link" + + # Not quite. We don't want to checksum links, but we must because they might be being followed. + @checksum = Digest::MD5.hexdigest("some content\n") # Remove these when :managed links are no longer checksumed. + @metadata.stubs(:md5_file).returns(@checksum) # end it "should accept a base path path to which the file should be relative" do @@ -217,6 +221,9 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do @stat.stubs(:ftype).returns("link") File.expects(:readlink).with("/my/file").returns("/path/to/link") @metadata.collect + + @checksum = Digest::MD5.hexdigest("some content\n") # Remove these when :managed links are no longer checksumed. + @file.stubs(:md5_file).returns(@checksum) # end it "should read links instead of returning their checksums" do @@ -224,29 +231,56 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do end it "should produce tab-separated mode, type, owner, group, and destination for xmlrpc" do - @metadata.attributes_with_tabs.should == "#{0755.to_s}\tlink\t10\t20\t/path/to/link" + pending "We'd like this to be true, but we need to always collect the checksum because in the server/client/server round trip we lose the distintion between manage and follow." + @metadata.attributes_with_tabs.should == "#{0755}\tlink\t10\t20\t/path/to/link" + end + + it "should produce tab-separated mode, type, owner, group, checksum, and destination for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755}\tlink\t10\t20\t{md5}eb9c2bf0eb63f3a7bc0ea37ef18aeba5\t/path/to/link" end end end describe Puppet::FileServing::Metadata, " when pointing to a link" do - it "should store the destination of the link in :destination if links are :manage" do - file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :manage) - - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) - File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" + describe "when links are managed" do + before do + @file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :manage) + File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) + File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" - file.collect - file.destination.should == "/some/other/path" + @checksum = Digest::MD5.hexdigest("some content\n") # Remove these when :managed links are no longer checksumed. + @file.stubs(:md5_file).returns(@checksum) # + end + it "should store the destination of the link in :destination if links are :manage" do + @file.collect + @file.destination.should == "/some/other/path" + end + it "should not collect the checksum if links are :manage" do + pending "We'd like this to be true, but we need to always collect the checksum because in the server/client/server round trip we lose the distintion between manage and follow." + @file.collect + @file.checksum.should be_nil + end + it "should collect the checksum if links are :manage" do # see pending note above + @file.collect + @file.checksum.should == "{md5}#{@checksum}" + end end - it "should not collect the checksum" do - file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :manage) - - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) - File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" - - file.collect - file.checksum.should be_nil + describe "when links are followed" do + before do + @file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :follow) + File.expects(:stat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "file", :mode => 0755) + File.expects(:readlink).with("/base/path/my/file").never + @checksum = Digest::MD5.hexdigest("some content\n") + @file.stubs(:md5_file).returns(@checksum) + end + it "should not store the destination of the link in :destination if links are :follow" do + @file.collect + @file.destination.should be_nil + end + it "should collect the checksum if links are :follow" do + @file.collect + @file.checksum.should == "{md5}#{@checksum}" + end end end diff --git a/spec/unit/file_serving/mount/file.rb b/spec/unit/file_serving/mount/file.rb index 837fe8e62..69660d62f 100755 --- a/spec/unit/file_serving/mount/file.rb +++ b/spec/unit/file_serving/mount/file.rb @@ -107,6 +107,14 @@ describe Puppet::FileServing::Mount::File, "when determining the complete file p @mount.complete_path("/my/path", nil).should be_nil end + it "should write a log message if the file is absent" do + FileTest.stubs(:exist?).returns(false) + + Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path") + + @mount.complete_path("/my/path", nil) + end + it "should return the file path if the file is present" do FileTest.stubs(:exist?).with("/my/path").returns(true) @mount.complete_path("/my/path", nil).should == "/mount/my/path" diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb index 7f0942221..84f5cdc56 100755 --- a/spec/unit/indirector/catalog/compiler.rb +++ b/spec/unit/indirector/catalog/compiler.rb @@ -61,7 +61,7 @@ describe Puppet::Resource::Catalog::Compiler do describe "when finding catalogs" do before do Facter.stubs(:value).returns("whatever") - env = stub 'environment', :name => "yay" + env = stub 'environment', :name => "yay", :modulepath => [] Puppet::Node::Environment.stubs(:new).returns(env) @compiler = Puppet::Resource::Catalog::Compiler.new @@ -111,6 +111,7 @@ describe Puppet::Resource::Catalog::Compiler do end it "should extract and save any facts from the request" do + Puppet::Node.expects(:find).with(@name).returns @node @compiler.expects(:extract_facts_from_request).with(@request) @compiler.interpreter.stubs(:compile) @compiler.find(@request) diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 220aa24fe..ca2a412e3 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -536,7 +536,7 @@ describe Puppet::Indirector::Indirection do @indirection.expire("/my/key") end - it "should log that it is expiring any found instance" do + it "should log when expiring a found instance" do @cache.expects(:find).returns @cached @cache.stubs(:save) @@ -545,33 +545,44 @@ describe Puppet::Indirector::Indirection do @indirection.expire("/my/key") end - it "should set the cached instance's expiration to a time in the past" do - @cache.expects(:find).returns @cached - @cache.stubs(:save) + describe "and the terminus supports removal of cache items with destroy" do + it "should destroy the cached instance" do + @cache.expects(:find).returns @cached + @cache.expects(:destroy).with { |r| r.method == :destroy and r.key == "/my/key" } + @cache.expects(:save).never + @indirection.expire("/my/key") + end + end - @cached.expects(:expiration=).with { |t| t < Time.now } + describe "and the terminus does not support removal of cache items with destroy" do + it "should set the cached instance's expiration to a time in the past" do + @cache.expects(:find).returns @cached + @cache.stubs(:save) - @indirection.expire("/my/key") - end + @cached.expects(:expiration=).with { |t| t < Time.now } - it "should save the now expired instance back into the cache" do - @cache.expects(:find).returns @cached + @indirection.expire("/my/key") + end - @cached.expects(:expiration=).with { |t| t < Time.now } + it "should save the now expired instance back into the cache" do + @cache.expects(:find).returns @cached - @cache.expects(:save) + @cached.expects(:expiration=).with { |t| t < Time.now } - @indirection.expire("/my/key") - end + @cache.expects(:save) - it "should use a request to save the expired resource to the cache" do - @cache.expects(:find).returns @cached + @indirection.expire("/my/key") + end - @cached.expects(:expiration=).with { |t| t < Time.now } + it "should use a request to save the expired resource to the cache" do + @cache.expects(:find).returns @cached - @cache.expects(:save).with { |r| r.is_a?(Puppet::Indirector::Request) and r.instance == @cached and r.method == :save }.returns(@cached) + @cached.expects(:expiration=).with { |t| t < Time.now } - @indirection.expire("/my/key") + @cache.expects(:save).with { |r| r.is_a?(Puppet::Indirector::Request) and r.instance == @cached and r.method == :save }.returns(@cached) + + @indirection.expire("/my/key") + end end end end diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index e25bc36c4..953a8c2b2 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -38,7 +38,7 @@ describe Puppet::Node::Ldap do # This heavily tests our entry2hash method, so we don't have to stub out the stupid entry information any more. describe "when an ldap entry is found" do before do - @entry = stub 'entry', :dn => 'cn=mynode.domain.com,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {} + @entry = stub 'entry', :dn => 'cn=mynode,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {} @searcher.stubs(:ldapsearch).yields @entry end @@ -46,8 +46,12 @@ describe Puppet::Node::Ldap do @searcher.entry2hash(@entry).should be_instance_of(Hash) end - it "should add the entry's common name to the hash" do - @searcher.entry2hash(@entry)[:name].should == "mynode.domain.com" + it "should add the entry's common name to the hash if fqdn if false" do + @searcher.entry2hash(@entry,fqdn = false)[:name].should == "mynode" + end + + it "should add the entry's fqdn name to the hash if fqdn if true" do + @searcher.entry2hash(@entry,fqdn = true)[:name].should == "mynode.madstop.com" end it "should add all of the entry's classes to the hash" do @@ -341,13 +345,13 @@ describe Puppet::Node::Ldap do it "should process each found entry" do # .yields can't be used to yield multiple values :/ @searcher.expects(:ldapsearch).yields("one") - @searcher.expects(:entry2hash).with("one").returns(:name => "foo") + @searcher.expects(:entry2hash).with("one",nil).returns(:name => "foo") @searcher.search @request end it "should return a node for each processed entry with the name from the entry" do @searcher.expects(:ldapsearch).yields("whatever") - @searcher.expects(:entry2hash).with("whatever").returns(:name => "foo") + @searcher.expects(:entry2hash).with("whatever",nil).returns(:name => "foo") result = @searcher.search(@request) result[0].should be_instance_of(Puppet::Node) result[0].name.should == "foo" @@ -358,7 +362,17 @@ describe Puppet::Node::Ldap do Puppet::Node.expects(:new).with("foo").returns node node.expects(:fact_merge) @searcher.stubs(:ldapsearch).yields("one") - @searcher.stubs(:entry2hash).with("one").returns(:name => "foo") + @searcher.stubs(:entry2hash).with("one",nil).returns(:name => "foo") + @searcher.search(@request) + end + + it "should pass the request's fqdn option to entry2hash" do + node = mock 'node' + @options[:fqdn] = :hello + Puppet::Node.stubs(:new).with("foo").returns node + node.stubs(:fact_merge) + @searcher.stubs(:ldapsearch).yields("one") + @searcher.expects(:entry2hash).with("one",:hello).returns(:name => "foo") @searcher.search(@request) end end diff --git a/spec/unit/network/authstore.rb b/spec/unit/network/authstore.rb index 4087b28ed..58eb92693 100644 --- a/spec/unit/network/authstore.rb +++ b/spec/unit/network/authstore.rb @@ -83,6 +83,181 @@ describe Puppet::Network::AuthStore::Declaration do end end + [ + "02001:0000:1234:0000:0000:C1C0:ABCD:0876", + "2001:0000:1234:0000:00001:C1C0:ABCD:0876", + " 2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", + "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", + "3ffe:0b00:0000:0001:0000:0000:000a", + "FF02:0000:0000:0000:0000:0000:0000:0000:0001", + "3ffe:b00::1::a", + "1:2:3::4:5::7:8", + "12345::6:7:8", + "1::5:400.2.3.4", + "1::5:260.2.3.4", + "1::5:256.2.3.4", + "1::5:1.256.3.4", + "1::5:1.2.256.4", + "1::5:1.2.3.256", + "1::5:300.2.3.4", + "1::5:1.300.3.4", + "1::5:1.2.300.4", + "1::5:1.2.3.300", + "1::5:900.2.3.4", + "1::5:1.900.3.4", + "1::5:1.2.900.4", + "1::5:1.2.3.900", + "1::5:300.300.300.300", + "1::5:3000.30.30.30", + "1::400.2.3.4", + "1::260.2.3.4", + "1::256.2.3.4", + "1::1.256.3.4", + "1::1.2.256.4", + "1::1.2.3.256", + "1::300.2.3.4", + "1::1.300.3.4", + "1::1.2.300.4", + "1::1.2.3.300", + "1::900.2.3.4", + "1::1.900.3.4", + "1::1.2.900.4", + "1::1.2.3.900", + "1::300.300.300.300", + "1::3000.30.30.30", + "::400.2.3.4", + "::260.2.3.4", + "::256.2.3.4", + "::1.256.3.4", + "::1.2.256.4", + "::1.2.3.256", + "::300.2.3.4", + "::1.300.3.4", + "::1.2.300.4", + "::1.2.3.300", + "::900.2.3.4", + "::1.900.3.4", + "::1.2.900.4", + "::1.2.3.900", + "::300.300.300.300", + "::3000.30.30.30", + "2001:DB8:0:0:8:800:200C:417A:221", # unicast, full + "FF01::101::2" # multicast, compressed + ].each { |invalid_ip| + describe "when the pattern is an invalid IPv6 address such as #{invalid_ip}" do + it "should raise an exception" do + lambda { Puppet::Network::AuthStore::Declaration.new(:allow,invalid_ip) }.should raise_error + end + end + } + + [ + "1.2.3.4", + "2001:0000:1234:0000:0000:C1C0:ABCD:0876", + "3ffe:0b00:0000:0000:0001:0000:0000:000a", + "FF02:0000:0000:0000:0000:0000:0000:0001", + "0000:0000:0000:0000:0000:0000:0000:0001", + "0000:0000:0000:0000:0000:0000:0000:0000", + "::ffff:192.168.1.26", + "2::10", + "ff02::1", + "fe80::", + "2002::", + "2001:db8::", + "2001:0db8:1234::", + "::ffff:0:0", + "::1", + "::ffff:192.168.1.1", + "1:2:3:4:5:6:7:8", + "1:2:3:4:5:6::8", + "1:2:3:4:5::8", + "1:2:3:4::8", + "1:2:3::8", + "1:2::8", + "1::8", + "1::2:3:4:5:6:7", + "1::2:3:4:5:6", + "1::2:3:4:5", + "1::2:3:4", + "1::2:3", + "1::8", + "::2:3:4:5:6:7:8", + "::2:3:4:5:6:7", + "::2:3:4:5:6", + "::2:3:4:5", + "::2:3:4", + "::2:3", + "::8", + "1:2:3:4:5:6::", + "1:2:3:4:5::", + "1:2:3:4::", + "1:2:3::", + "1:2::", + "1::", + "1:2:3:4:5::7:8", + "1:2:3:4::7:8", + "1:2:3::7:8", + "1:2::7:8", + "1::7:8", + "1:2:3:4:5:6:1.2.3.4", + "1:2:3:4:5::1.2.3.4", + "1:2:3:4::1.2.3.4", + "1:2:3::1.2.3.4", + "1:2::1.2.3.4", + "1::1.2.3.4", + "1:2:3:4::5:1.2.3.4", + "1:2:3::5:1.2.3.4", + "1:2::5:1.2.3.4", + "1::5:1.2.3.4", + "1::5:11.22.33.44", + "fe80::217:f2ff:254.7.237.98", + "fe80::217:f2ff:fe07:ed62", + "2001:DB8:0:0:8:800:200C:417A", # unicast, full + "FF01:0:0:0:0:0:0:101", # multicast, full + "0:0:0:0:0:0:0:1", # loopback, full + "0:0:0:0:0:0:0:0", # unspecified, full + "2001:DB8::8:800:200C:417A", # unicast, compressed + "FF01::101", # multicast, compressed + "::1", # loopback, compressed, non-routable + "::", # unspecified, compressed, non-routable + "0:0:0:0:0:0:13.1.68.3", # IPv4-compatible IPv6 address, full, deprecated + "0:0:0:0:0:FFFF:129.144.52.38", # IPv4-mapped IPv6 address, full + "::13.1.68.3", # IPv4-compatible IPv6 address, compressed, deprecated + "::FFFF:129.144.52.38", # IPv4-mapped IPv6 address, compressed + "2001:0DB8:0000:CD30:0000:0000:0000:0000/60", # full, with prefix + "2001:0DB8::CD30:0:0:0:0/60", # compressed, with prefix + "2001:0DB8:0:CD30::/60", # compressed, with prefix #2 + "::/128", # compressed, unspecified address type, non-routable + "::1/128", # compressed, loopback address type, non-routable + "FF00::/8", # compressed, multicast address type + "FE80::/10", # compressed, link-local unicast, non-routable + "FEC0::/10", # compressed, site-local unicast, deprecated + "127.0.0.1", # standard IPv4, loopback, non-routable + "0.0.0.0", # standard IPv4, unspecified, non-routable + "255.255.255.255", # standard IPv4 + "fe80:0000:0000:0000:0204:61ff:fe9d:f156", + "fe80:0:0:0:204:61ff:fe9d:f156", + "fe80::204:61ff:fe9d:f156", + "fe80:0000:0000:0000:0204:61ff:254.157.241.086", + "fe80:0:0:0:204:61ff:254.157.241.86", + "fe80::204:61ff:254.157.241.86", + "::1", + "fe80::", + "fe80::1" + ].each { |ip| + describe "when the pattern is a valid IP such as #{ip}" do + before :each do + @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,ip) + end + it "should match the specified IP" do + @declaration.should be_match('www.testsite.org',ip) + end + it "should not match other IPs" do + @declaration.should_not be_match('www.testsite.org','200.101.99.98') + end + end unless ip =~ /:.*\./ # Hybrid IPs aren't supported by ruby's ipaddr + } + { 'spirit.mars.nasa.gov' => 'a PQDN', 'ratchet.2ndsiteinc.com' => 'a PQDN with digits', @@ -103,6 +278,28 @@ describe Puppet::Network::AuthStore::Declaration do end } + ['abc.12seps.edu.phisher.biz','www.google.com','slashdot.org'].each { |host| + (1...(host.split('.').length)).each { |n| + describe "when the pattern is #{"*."+host.split('.')[-n,n].join('.')}" do + before :each do + @pattern = "*."+host.split('.')[-n,n].join('.') + @declaration = Puppet::Network::AuthStore::Declaration.new(:allow,@pattern) + end + it "should match #{host}" do + @declaration.should be_match(host,'1.2.3.4') + end + it "should not match www.testsite.gov" do + @declaration.should_not be_match('www.testsite.gov','200.101.99.98') + end + it "should not match hosts that differ in the first non-wildcard segment" do + other = host.split('.') + other[-n].succ! + @declaration.should_not be_match(other.join('.'),'1.2.3.4') + end + end + } + } + describe "when the pattern is a FQDN" do before :each do @host = 'spirit.mars.nasa.gov.' diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb index b1ef9ec53..a241306a2 100755 --- a/spec/unit/network/formats.rb +++ b/spec/unit/network/formats.rb @@ -91,6 +91,9 @@ describe "Puppet Network Format" do end describe "base64 compressed yaml" do + yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml) + confine "We must have zlib" => Puppet.features.zlib? + before do @yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml) end @@ -173,6 +176,34 @@ describe "Puppet Network Format" do it "should fixup incorrect yaml to correct" do @yaml.fixup("&id004 !ruby/object:Puppet::Relationship ?").should == "? &id004 !ruby/object:Puppet::Relationship" end + + describe "when zlib is disabled" do + before do + Puppet[:zlib] = false + end + + it "use_zlib? should return false" do + @yaml.use_zlib?.should == false + end + + it "should refuse to encode" do + lambda{ @yaml.encode("foo") }.should raise_error + end + + it "should refuse to decode" do + lambda{ @yaml.decode("foo") }.should raise_error + end + end + + describe "when zlib is not installed" do + it "use_zlib? should return false" do + Puppet[:zlib] = true + Puppet.features.expects(:zlib?).returns(false) + + @yaml.use_zlib?.should == false + end + end + end it "should include a marshal format" do diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb index 1addb5890..559812159 100755 --- a/spec/unit/network/http/handler.rb +++ b/spec/unit/network/http/handler.rb @@ -230,6 +230,16 @@ describe Puppet::Network::HTTP::Handler do @handler.do_find(@irequest, @request, @response) end + it "should write a log message when no model instance can be found" do + @model_class.stubs(:name).returns "my name" + @model_class.stubs(:find).returns(nil) + + Puppet.expects(:info).with("Could not find my_handler for 'my_result'") + + @handler.do_find(@irequest, @request, @response) + end + + it "should serialize the result in with the appropriate format" do @model_instance = stub('model instance') diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index fca2e075e..b8163fef7 100755 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -15,7 +15,7 @@ end describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do before do - @mock_webrick = stub('webrick', :[] => {}, :listeners => []) + @mock_webrick = stub('webrick', :[] => {}, :listeners => [], :status => :Running) [:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)} WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new @@ -162,7 +162,7 @@ end describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do before do - @mock_webrick = stub('webrick', :[] => {}, :listeners => []) + @mock_webrick = stub('webrick', :[] => {}, :listeners => [], :status => :Running) [:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)} WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new diff --git a/spec/unit/network/rest_authconfig.rb b/spec/unit/network/rest_authconfig.rb index 0da3d9c63..20a51ba87 100755 --- a/spec/unit/network/rest_authconfig.rb +++ b/spec/unit/network/rest_authconfig.rb @@ -84,7 +84,7 @@ describe Puppet::Network::RestAuthConfig do end DEFAULT_ACL.each do |acl| - it "should insert #{acl} if not present" do + it "should insert #{acl[:acl]} if not present" do @authconfig.rights.stubs(:[]).returns(true) @authconfig.rights.stubs(:[]).with(acl[:acl]).returns(nil) @@ -93,7 +93,7 @@ describe Puppet::Network::RestAuthConfig do @authconfig.insert_default_acl end - it "should not insert #{acl} if present" do + it "should not insert #{acl[:acl]} if present" do @authconfig.rights.stubs(:[]).returns(true) @authconfig.rights.stubs(:[]).with(acl).returns(true) diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb index 9b0d5eefa..21c224f23 100755 --- a/spec/unit/node/environment.rb +++ b/spec/unit/node/environment.rb @@ -171,7 +171,7 @@ describe Puppet::Node::Environment do env.expects(:modulepath).returns %w{/a} Dir.expects(:entries).with("/a").returns %w{foo} - env.modules.should be_all{|mod| mod.environment == "testing" } + env.modules.each {|mod| mod.environment.should == env } end it "should cache the module list" do diff --git a/spec/unit/other/selinux.rb b/spec/unit/other/selinux.rb index 3e39afcdd..2287570e7 100644 --- a/spec/unit/other/selinux.rb +++ b/spec/unit/other/selinux.rb @@ -28,7 +28,7 @@ end describe Puppet::Type.type(:selboolean), " when manipulating booleans" do before :each do provider_class = Puppet::Type::Selboolean.provider(Puppet::Type::Selboolean.providers[0]) - Puppet::Type::Selboolean.expects(:defaultprovider).returns provider_class + Puppet::Type::Selboolean.stubs(:defaultprovider).returns provider_class @bool = Puppet::Type::Selboolean.new( :name => "foo", @@ -57,7 +57,7 @@ end describe Puppet::Type.type(:selmodule), " when checking policy modules" do before :each do provider_class = Puppet::Type::Selmodule.provider(Puppet::Type::Selmodule.providers[0]) - Puppet::Type::Selmodule.expects(:defaultprovider).returns provider_class + Puppet::Type::Selmodule.stubs(:defaultprovider).returns provider_class @module = Puppet::Type::Selmodule.new( :name => "foo", diff --git a/spec/unit/parameter.rb b/spec/unit/parameter.rb index 0548346b3..e3eaca6ac 100755 --- a/spec/unit/parameter.rb +++ b/spec/unit/parameter.rb @@ -44,6 +44,14 @@ describe Puppet::Parameter do @parameter.tags.should == %w{one two foo} end + it "should provide source_descriptors" do + @resource.expects(:line).returns 10 + @resource.expects(:file).returns "file" + @resource.expects(:tags).returns %w{one two} + @resource.expects(:version).returns 50 + @parameter.source_descriptors.should == {:tags=>["one", "two", "foo"], :path=>"//foo", :version=>50, :file => "file", :line => 10} + end + describe "when returning the value" do it "should return nil if no value is set" do @parameter.value.should be_nil diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb index 959f36026..a6aebc6fe 100755 --- a/spec/unit/parser/lexer.rb +++ b/spec/unit/parser/lexer.rb @@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/lexer' # This is a special matcher to match easily lexer output -Spec::Matchers.create :be_like do |ary| +Spec::Matchers.define :be_like do |ary| match do |result| r = true result.zip(ary) do |a,b| diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 3f08de958..d41d4f48b 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -101,6 +101,17 @@ describe Puppet::Parser::Resource do end end + describe "when refering to a resource with name canonicalization" do + before do + @arguments = {:type => "file", :title => "/path/", :scope => stub('scope', :source => mock('source'))} + end + + it "should canonicalize its own name" do + res = Puppet::Parser::Resource.new(@arguments) + res.ref.should == "File[/path]" + end + end + describe "when evaluating" do before do @type = Puppet::Parser::Resource diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb index 064c51b20..a09c436c2 100755 --- a/spec/unit/parser/resource/reference.rb +++ b/spec/unit/parser/resource/reference.rb @@ -49,6 +49,13 @@ describe Puppet::Parser::Resource::Reference do ref = @type.new(:type => "file", :title => "/tmp/yay/") ref.to_s.should == "File[/tmp/yay]" end + + it "should canonize resource reference values without order dependencies" do + args = [[:title, "/tmp/yay/"], [:type, "file"]] + ref = @type.new(args) + ref.to_s.should == "File[/tmp/yay]" + end + end describe Puppet::Parser::Resource::Reference, " when modeling defined types" do diff --git a/spec/unit/provider/cron/crontab.rb b/spec/unit/provider/cron/crontab.rb new file mode 100755 index 000000000..5904a58b7 --- /dev/null +++ b/spec/unit/provider/cron/crontab.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +describe Puppet::Type.type(:cron).provider(:crontab) do + before :each do + @cron_type = Puppet::Type.type(:cron) + @provider = @cron_type.provider(:crontab) + end + + it "should round-trip the name as a comment for @special events" do + parse = @provider.parse <<-CRON +# Puppet Name: test +@reboot /bin/echo > /tmp/puppet.txt + CRON + prefetch = @provider.prefetch_hook(parse) + + @provider.to_line(prefetch[0]).should =~ /Puppet Name: test/ + end + +end diff --git a/spec/unit/provider/mount/parsed.rb b/spec/unit/provider/mount/parsed.rb index cf9feaa94..d394b2997 100755 --- a/spec/unit/provider/mount/parsed.rb +++ b/spec/unit/provider/mount/parsed.rb @@ -108,6 +108,15 @@ describe provider_class do end Puppet::Type.type(:mount).provider(:parsed).default_target.should == should end + + it "should not crash on incomplete lines in fstab" do + parse = @provider_class.parse <<-FSTAB +/dev/incomplete +/dev/device name + FSTAB + + lambda{ @provider_class.to_line(parse[0]) }.should_not raise_error + end end describe provider_class, " when mounting an absent filesystem" do @@ -140,10 +149,12 @@ describe provider_class do end it "should write the mount to disk when :flush is called" do + old_text = @provider_class.target_object(@provider_class.default_target).read + @mount.flush text = @provider_class.target_object(@provider_class.default_target).read - text.should == @mount.class.to_line(@mount.property_hash) + "\n" + text.should == old_text + @mount.class.to_line(@mount.property_hash) + "\n" end end diff --git a/spec/unit/provider/service/init.rb b/spec/unit/provider/service/init.rb index 0bfeb9a18..32bfaa204 100755 --- a/spec/unit/provider/service/init.rb +++ b/spec/unit/provider/service/init.rb @@ -16,12 +16,26 @@ describe provider_class do # @resource.stubs(:[]).with(:ensure).returns :enabled @resource.stubs(:[]).with(:path).returns ["/service/path","/alt/service/path"] # @resource.stubs(:ref).returns "Service[myservice]" + File.stubs(:directory?).returns(true) @provider = provider_class.new @provider.resource = @resource end - describe "when serching for the init script" do + + describe "when searching for the init script" do + it "should discard paths that do not exist" do + File.stubs(:exist?).returns(false) + File.stubs(:directory?).returns(false) + @provider.paths.should be_empty + end + + it "should discard paths that are not directories" do + File.stubs(:exist?).returns(true) + File.stubs(:directory?).returns(false) + @provider.paths.should be_empty + end + it "should be able to find the init script in the service path" do File.expects(:stat).with("/service/path/myservice").returns true @provider.initscript.should == "/service/path/myservice" @@ -102,5 +116,6 @@ describe provider_class do @provider.restart end end + end end diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index 49abc13ec..9abcda54f 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -33,7 +33,7 @@ describe provider_class do end def genkey(key) - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam) file = @provider.default_target key.flush @@ -90,7 +90,9 @@ describe provider_class do before :each do @resource = stub("resource", :name => "foo") @resource.stubs(:[]).returns "foo" + @provider = provider_class.new(@resource) + provider_class.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam) end describe "when flushing" do diff --git a/spec/unit/provider/sshkey/parsed.rb b/spec/unit/provider/sshkey/parsed.rb new file mode 100755 index 000000000..c97656fbd --- /dev/null +++ b/spec/unit/provider/sshkey/parsed.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +provider_class = Puppet::Type.type(:sshkey).provider(:parsed) + +describe provider_class do + before do + @sshkey_class = Puppet::Type.type(:sshkey) + @provider_class = @sshkey_class.provider(:parsed) + end + + it "should not drop an empty alias" do + line = 'test,alias, ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzwHhxXvIrtfIwrudFqc8yQcIfMudrgpnuh1F3AV6d2BrLgu/yQE7W5UyJMUjfj427sQudRwKW45O0Jsnr33F4mUw+GIMlAAmp9g24/OcrTiB8ZUKIjoPy/cO4coxGi8/NECtRzpD/ZUPFh6OEpyOwJPMb7/EC2Az6Otw4StHdXUYw22zHazBcPFnv6zCgPx1hA7QlQDWTu4YcL0WmTYQCtMUb3FUqrcFtzGDD0ytosgwSd+JyN5vj5UwIABjnNOHPZ62EY1OFixnfqX/+dUwrFSs5tPgBF/KkC6R7tmbUfnBON6RrGEmu+ajOTOLy23qUZB4CQ53V7nyAWhzqSK+hw==' + parsed = @provider_class.parse_line(line) + parsed[:alias].should == ["alias",""] + end + +end diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb index da6db1548..089f48d27 100755 --- a/spec/unit/rails.rb +++ b/spec/unit/rails.rb @@ -42,7 +42,7 @@ describe Puppet::Rails, "when initializing any connection" do ActiveRecord::Base.stubs(:allow_concurrency=) ActiveRecord::Base.stubs(:verify_active_connections!) ActiveRecord::Base.stubs(:establish_connection) - Puppet::Rails.stubs(:database_arguments) + Puppet::Rails.stubs(:database_arguments).returns({}) Puppet::Rails.connect end @@ -64,7 +64,7 @@ describe Puppet::Rails, "when initializing any connection" do end it "should call ActiveRecord::Base.establish_connection with database_arguments" do - Puppet::Rails.expects(:database_arguments) + Puppet::Rails.expects(:database_arguments).returns({}) ActiveRecord::Base.expects(:establish_connection) Puppet::Rails.connect @@ -74,15 +74,15 @@ end describe Puppet::Rails, "when initializing a sqlite3 connection" do confine "Cannot test without ActiveRecord" => Puppet.features.rails? - it "should provide the adapter, log_level, and dbfile arguments" do + it "should provide the adapter, log_level, and database arguments" do Puppet.settings.expects(:value).with(:dbadapter).returns("sqlite3") Puppet.settings.expects(:value).with(:rails_loglevel).returns("testlevel") Puppet.settings.expects(:value).with(:dblocation).returns("testlocation") Puppet::Rails.database_arguments.should == { - :adapter => "sqlite3", + :adapter => "sqlite3", :log_level => "testlevel", - :dbfile => "testlocation" + :database => "testlocation" } end end @@ -90,7 +90,7 @@ end describe Puppet::Rails, "when initializing a mysql connection" do confine "Cannot test without ActiveRecord" => Puppet.features.rails? - it "should provide the adapter, log_level, and host, username, password, and database arguments" do + it "should provide the adapter, log_level, and host, username, password, database, and reconnect arguments" do Puppet.settings.stubs(:value).with(:dbadapter).returns("mysql") Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel") Puppet.settings.stubs(:value).with(:dbserver).returns("testserver") @@ -105,11 +105,12 @@ describe Puppet::Rails, "when initializing a mysql connection" do :host => "testserver", :username => "testuser", :password => "testpassword", - :database => "testname" + :database => "testname", + :reconnect => true } end - it "should provide the adapter, log_level, and host, username, password, database, and socket arguments" do + it "should provide the adapter, log_level, and host, username, password, database, socket, and reconnect arguments" do Puppet.settings.stubs(:value).with(:dbadapter).returns("mysql") Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel") Puppet.settings.stubs(:value).with(:dbserver).returns("testserver") @@ -125,7 +126,8 @@ describe Puppet::Rails, "when initializing a mysql connection" do :username => "testuser", :password => "testpassword", :database => "testname", - :socket => "testsocket" + :socket => "testsocket", + :reconnect => true } end diff --git a/spec/unit/rails/resource.rb b/spec/unit/rails/resource.rb index 9e2ff8cd2..e9162b92e 100755 --- a/spec/unit/rails/resource.rb +++ b/spec/unit/rails/resource.rb @@ -84,4 +84,24 @@ describe "Puppet::Rails::Resource" do @resource.merge_parser_resource(@parser) end end + + describe "merge_parameters" do + it "should replace values that have changed" do + @resource = Puppet::Rails::Resource.new + @resource.params_list = [{"name" => "replace", "value" => 1, "id" => 100 }] + + Puppet::Rails::ParamValue.expects(:delete).with([100]) + param_values = stub "param_values" + param_values.expects(:build).with({:value=>nil, :param_name=>nil, :line=>{"replace"=>2}}) + @resource.stubs(:param_values).returns(param_values) + + Puppet::Rails::ParamName.stubs(:accumulate_by_name) + + merge_resource = stub "merge_resource" + merge_resource.expects(:line).returns({ "replace" => 2 }) + merge_resource.stubs(:each).yields([["replace", 2]]) + + @resource.merge_parameters(merge_resource) + end + end end diff --git a/spec/unit/ssl/host.rb b/spec/unit/ssl/host.rb index 51223e6d5..6d7249088 100755 --- a/spec/unit/ssl/host.rb +++ b/spec/unit/ssl/host.rb @@ -90,55 +90,6 @@ describe Puppet::SSL::Host do Puppet::SSL::Host.localhost.should equal(two) end - it "should be able to verify its certificate matches its key" do - Puppet::SSL::Host.new("foo").should respond_to(:certificate_matches_key?) - end - - it "should consider the certificate invalid if it cannot find a key" do - host = Puppet::SSL::Host.new("foo") - host.expects(:key).returns nil - - host.should_not be_certificate_matches_key - end - - it "should consider the certificate invalid if it cannot find a certificate" do - host = Puppet::SSL::Host.new("foo") - host.expects(:key).returns mock("key") - host.expects(:certificate).returns nil - - host.should_not be_certificate_matches_key - end - - it "should consider the certificate invalid if the SSL certificate's key verification fails" do - host = Puppet::SSL::Host.new("foo") - - key = mock 'key', :content => "private_key" - sslcert = mock 'sslcert' - certificate = mock 'cert', :content => sslcert - - host.stubs(:key).returns key - host.stubs(:certificate).returns certificate - - sslcert.expects(:check_private_key).with("private_key").returns false - - host.should_not be_certificate_matches_key - end - - it "should consider the certificate valid if the SSL certificate's key verification succeeds" do - host = Puppet::SSL::Host.new("foo") - - key = mock 'key', :content => "private_key" - sslcert = mock 'sslcert' - certificate = mock 'cert', :content => sslcert - - host.stubs(:key).returns key - host.stubs(:certificate).returns certificate - - sslcert.expects(:check_private_key).with("private_key").returns true - - host.should be_certificate_matches_key - end - describe "when specifying the CA location" do before do [Puppet::SSL::Key, Puppet::SSL::Certificate, Puppet::SSL::CertificateRequest, Puppet::SSL::CertificateRevocationList].each do |klass| @@ -408,10 +359,11 @@ describe Puppet::SSL::Host do describe "when managing its certificate" do before do @realcert = mock 'certificate' - @cert = stub 'cert', :content => @realcert + @realcert.stubs(:check_private_key).with('private key').returns true + + @cert = stub 'cert', :content => @realcert, :expired? => false - @host.stubs(:key).returns mock("key") - @host.stubs(:certificate_matches_key?).returns true + @host.stubs(:key).returns stub("key",:content => 'private key' ) end it "should find the CA certificate if it does not have a certificate" do @@ -459,12 +411,22 @@ describe Puppet::SSL::Host do @host.certificate.should equal(@cert) end - it "should fail if the found certificate does not match the private key" do - @host.expects(:certificate_matches_key?).returns false + it "should immediately expire the cached copy if the found certificate does not match the private key" do + @realcert.expects(:check_private_key).with('private key').returns false + + Puppet::SSL::Certificate.stubs(:find).returns @cert + Puppet::SSL::Certificate.expects(:expire).with("myname") + + @host.certificate + end + + it "should not return a certificate if it does not match the private key" do + @realcert.expects(:check_private_key).with('private key').returns false Puppet::SSL::Certificate.stubs(:find).returns @cert + Puppet::SSL::Certificate.stubs(:expire).with("myname") - lambda { @host.certificate }.should raise_error(Puppet::Error) + @host.certificate.should == nil end it "should return any previously found certificate" do @@ -654,14 +616,14 @@ describe Puppet::SSL::Host do it "should catch and log errors during CSR saving" do @host.expects(:certificate).times(2).returns(nil).then.returns "foo" - @host.expects(:generate).times(2).raises(RuntimeError).then.returns nil + @host.expects(:generate).raises(RuntimeError).then.returns nil @host.stubs(:sleep) @host.wait_for_cert(1) end it "should sleep and retry after failures saving the CSR if waitforcert is enabled" do @host.expects(:certificate).times(2).returns(nil).then.returns "foo" - @host.expects(:generate).times(2).raises(RuntimeError).then.returns nil + @host.expects(:generate).raises(RuntimeError).then.returns nil @host.expects(:sleep).with(1) @host.wait_for_cert(1) end diff --git a/spec/unit/type.rb b/spec/unit/type.rb index fe2788ec6..11bedaaa2 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -89,6 +89,15 @@ describe Puppet::Type do Puppet::Type.type(:mount).new(:name => "foo").version.should == 0 end + it "should provide source_descriptors" do + resource = Puppet::Type.type(:mount).new(:name => "foo") + catalog = Puppet::Resource::Catalog.new + catalog.version = 50 + catalog.add_resource resource + + resource.source_descriptors.should == {:version=>50, :tags=>["mount", "foo"], :path=>"/Mount[foo]"} + end + describe "when choosing a default provider" do it "should choose the provider with the highest specificity" do # Make a fake type diff --git a/spec/unit/type/service.rb b/spec/unit/type/service.rb index 5e9d3b37f..f09ed98b9 100755 --- a/spec/unit/type/service.rb +++ b/spec/unit/type/service.rb @@ -88,20 +88,6 @@ describe Puppet::Type.type(:service), "when validating attribute values" do svc.should(:enable).should be_nil end - it "should discard paths that do not exist" do - FileTest.stubs(:exist?).returns(false) - FileTest.stubs(:directory?).returns(false) - svc = Puppet::Type.type(:service).new(:name => "yay", :path => "/one/two") - svc[:path].should be_empty - end - - it "should discard paths that are not directories" do - FileTest.stubs(:exist?).returns(true) - FileTest.stubs(:directory?).returns(false) - svc = Puppet::Type.type(:service).new(:name => "yay", :path => "/one/two") - svc[:path].should be_empty - end - it "should split paths on ':'" do FileTest.stubs(:exist?).returns(true) FileTest.stubs(:directory?).returns(true) diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb index 18938125d..4e1384246 100755 --- a/spec/unit/util/autoload.rb +++ b/spec/unit/util/autoload.rb @@ -111,6 +111,8 @@ describe Puppet::Util::Autoload do before do @autoload.stubs(:searchpath).returns %w{/a} Dir.stubs(:glob).returns "/path/to/file.rb" + + @autoload.class.stubs(:loaded?).returns(false) end [RuntimeError, LoadError, SyntaxError].each do |error| diff --git a/spec/unit/util/ldap/connection.rb b/spec/unit/util/ldap/connection.rb index 8bc85a620..bead64d01 100755 --- a/spec/unit/util/ldap/connection.rb +++ b/spec/unit/util/ldap/connection.rb @@ -8,7 +8,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/util/ldap/connection' # So our mocks and such all work, even when ldap isn't available. -unless defined?(LDAP::Conn) +unless Puppet.features.ldap? class LDAP class Conn def initialize(*args) diff --git a/spec/unit/util/log.rb b/spec/unit/util/log.rb index 35e6a71e8..97fb2f297 100755 --- a/spec/unit/util/log.rb +++ b/spec/unit/util/log.rb @@ -157,6 +157,20 @@ describe Puppet::Util::Log do end end + it "should use the source_descriptors" do + source = stub "source" + source.stubs(:source_descriptors).returns(:tags => ["tag","tag2"], :path => "path", :version => 100) + + log = Puppet::Util::Log.new(:level => "notice", :message => :foo) + log.expects(:tag).with("tag") + log.expects(:tag).with("tag2") + log.expects(:version=).with(100) + + log.source = source + + log.source.should == "path" + end + it "should copy over any version information" do catalog = Puppet::Resource::Catalog.new catalog.version = 25 diff --git a/spec/unit/util/queue.rb b/spec/unit/util/queue.rb index 19af9430e..c8a75550e 100755 --- a/spec/unit/util/queue.rb +++ b/spec/unit/util/queue.rb @@ -19,16 +19,24 @@ end mod = Puppet::Util::Queue client_classes = { :default => make_test_client_class('Bogus::Default'), :setup => make_test_client_class('Bogus::Setup') } -mod.register_queue_type(client_classes[:default], :default) -mod.register_queue_type(client_classes[:setup], :setup) describe Puppet::Util::Queue do + before :all do + mod.register_queue_type(client_classes[:default], :default) + mod.register_queue_type(client_classes[:setup], :setup) + end + before :each do @class = Class.new do extend mod end end + after :all do + instances = mod.instance_hash(:queue_clients) + [:default, :setup, :bogus, :aardvark, :conflict, :test_a, :test_b].each{ |x| instances.delete(x) } + end + context 'when determining a type name from a class' do it 'should handle a simple one-word class name' do mod.queue_type_from_class(make_test_client_class('Foo')).should == :foo diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb index 7e6cdaf30..88f4ac809 100755 --- a/spec/unit/util/selinux.rb +++ b/spec/unit/util/selinux.rb @@ -27,7 +27,12 @@ describe Puppet::Util::SELinux do Selinux.expects(:is_selinux_enabled).returns 0 selinux_support?.should be_false end - end + + it "should return nil if /proc/mounts does not exist" do + File.stubs(:open).with("/proc/mounts").raises("No such file or directory - /proc/mounts") + read_mounts.should == nil + end + end describe "filesystem detection" do before :each do @@ -189,7 +194,19 @@ describe Puppet::Util::SELinux do end describe "set_selinux_context" do - it "should return nil if there is no SELinux support" do + before :each do + fh = stub 'fh', :close => nil + File.stubs(:open).with("/proc/mounts").returns fh + fh.stubs(:read_nonblock).returns( + "rootfs / rootfs rw 0 0\n"+ + "/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n"+ + "/dev /dev tmpfs rw,relatime,mode=755 0 0\n"+ + "/proc /proc proc rw,relatime 0 0\n"+ + "/sys /sys sysfs rw,relatime 0 0\n" + ).then.raises EOFError + end + + it "should return nil if there is no SELinux support" do self.expects(:selinux_support?).returns false set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil end diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index 7527031de..4855df4b8 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -579,6 +579,25 @@ describe Puppet::Util::Settings do # and we should now have the new value in memory @settings[:two].should == "disk-replace" end + + it "should retain in-memory values if the file has a syntax error" do + # Init the value + text = "[main]\none = initial-value\n" + @settings.expects(:read_file).returns(text) + @settings.parse + @settings[:one].should == "initial-value" + + # Now replace the value with something bogus + text = "[main]\nkenny = killed-by-what-follows\n1 is 2, blah blah florp\n" + @settings.expects(:read_file).returns(text) + @settings.parse + + # The originally-overridden value should not be replaced with the default + @settings[:one].should == "initial-value" + + # and we should not have the new value in memory + @settings[:kenny].should be_nil + end end it "should provide a method for creating a catalog of resources from its configuration" do |
