From c7dc73f272c1e004ff1b7c806d5f47460b6bfe6d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Jul 2008 14:57:20 -0500 Subject: Fixing the user ldap provider tests Signed-off-by: Luke Kanies --- spec/unit/provider/user/ldap.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/unit/provider/user/ldap.rb b/spec/unit/provider/user/ldap.rb index 7e039d582..f1c571779 100755 --- a/spec/unit/provider/user/ldap.rb +++ b/spec/unit/provider/user/ldap.rb @@ -26,6 +26,7 @@ describe provider_class do it "should be able to manage passwords" do provider_class.should be_manages_passwords + end it "should use the ldap group provider to convert group names to numbers" do provider = provider_class.new(:name => "foo") -- cgit From d25c2b282cc4cd703bba3d2457f93431098ddc85 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 9 Jul 2008 10:29:45 -0500 Subject: Fixed #1407 - allowdupe is now a boolean group parameter. This just fixes a regression. Signed-off-by: Luke Kanies --- spec/unit/type/group.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 spec/unit/type/group.rb (limited to 'spec') diff --git a/spec/unit/type/group.rb b/spec/unit/type/group.rb new file mode 100755 index 000000000..d7e06dcd8 --- /dev/null +++ b/spec/unit/type/group.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Type.type(:group) do + before do + @class = Puppet::Type.type(:group) + end + + after do + @class.clear + end + + it "should have a default provider" do + @class.defaultprovider.should_not be_nil + end + + it "should have a default provider inheriting from Puppet::Provider" do + @class.defaultprovider.ancestors.should be_include(Puppet::Provider) + end + + describe "when validating attributes" do + [:name, :allowdupe].each do |param| + it "should have a #{param} parameter" do + @class.attrtype(param).should == :param + end + end + + [:ensure, :gid].each do |param| + it "should have a #{param} property" do + @class.attrtype(param).should == :property + end + end + end + + # #1407 - we need to declare the allowdupe param as boolean. + it "should have a boolean method for determining if duplicates are allowed" do + @class.create(:name => "foo").methods.should be_include("allowdupe?") + end +end -- cgit From 80436550a1e3040399e410be3edf7c44d29fc320 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 9 Jul 2008 17:41:21 -0700 Subject: Fixing #1408 - --loadclasses works again. The problem was that the mechanism I was using for passing the node to the compiler was conflicting with the Indirector::Request's method of handling node authentication. Signed-off-by: Luke Kanies --- spec/integration/node/catalog.rb | 10 ++++++++++ spec/unit/indirector/catalog/compiler.rb | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb index 1fa2afbb0..ed38ae987 100755 --- a/spec/integration/node/catalog.rb +++ b/spec/integration/node/catalog.rb @@ -40,5 +40,15 @@ describe Puppet::Node::Catalog do Puppet::Node::Catalog.find("me").should be_nil end + + it "should pass provided node information directly to the terminus" do + terminus = mock 'terminus' + + Puppet::Node::Catalog.indirection.stubs(:terminus).returns terminus + + node = mock 'node' + terminus.expects(:find).with { |request| request.options[:use_node] == node } + Puppet::Node::Catalog.find("me", :use_node => node) + end end end diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb index cf7186a5a..8cd3c72f4 100755 --- a/spec/unit/indirector/catalog/compiler.rb +++ b/spec/unit/indirector/catalog/compiler.rb @@ -114,13 +114,12 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do @node = Puppet::Node.new @name @node.stubs(:merge) @request = stub 'request', :key => @name, :options => {} - Puppet::Node.stubs(:find).with(@name).returns(@node) end it "should directly use provided nodes" do Puppet::Node.expects(:find).never - @compiler.interpreter.expects(:compile).with(@node) - @request.stubs(:options).returns(:node => @node) + @compiler.expects(:compile).with(@node) + @request.stubs(:options).returns(:use_node => @node) @compiler.find(@request) end @@ -130,12 +129,14 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do end it "should pass the found node to the interpreter for compiling" do + Puppet::Node.expects(:find).with(@name).returns(@node) config = mock 'config' @compiler.interpreter.expects(:compile).with(@node) @compiler.find(@request) end it "should return the results of compiling as the catalog" do + Puppet::Node.stubs(:find).returns(@node) config = mock 'config' result = mock 'result' @@ -144,6 +145,7 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do end it "should benchmark the compile process" do + Puppet::Node.stubs(:find).returns(@node) @compiler.stubs(:networked?).returns(true) @compiler.expects(:benchmark).with do |level, message| level == :notice and message =~ /^Compiled catalog/ -- cgit From 4c5293b837807f61002365114fd7004d2f74ad57 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Fri, 11 Jul 2008 14:39:52 +0200 Subject: Fix #1409, Move path expansion from the type into the provider This avoid exceptions during type instanciation when a user does not yet exist. The drawback is that we cannot use generated resources anymore and have to mkdir, chown and chmod directly in the provided which is somewhat hackish. --- spec/unit/provider/ssh_authorized_key/parsed.rb | 21 +++++++++++++ spec/unit/type/ssh_authorized_key.rb | 41 ------------------------- 2 files changed, 21 insertions(+), 41 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index c35ddc513..16efc5b58 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -71,4 +71,25 @@ describe provider_class do genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root@localhost\n" end + + it "should prefetch ~user/.ssh/authorized_keys when user is given" do + key = Puppet::Type.type(:ssh_authorized_key).create( + :name => "Test", + :key => "AA", + :type => "rsa", + :ensure => :present, + :user => "root") + prov = @provider.new key + + prov.prefetch + prov.target.should == File.expand_path("~root/.ssh/authorized_keys") + end + + it "should create destination dir" do + # No idea how to test the flush method + end + + it "should set correct default permissions" do + # No idea how to test the flush method + end end diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb index 0b41af40a..e21478479 100755 --- a/spec/unit/type/ssh_authorized_key.rb +++ b/spec/unit/type/ssh_authorized_key.rb @@ -77,47 +77,6 @@ describe ssh_authorized_key do @class.attrtype(:target).should == :property end - it "should autorequire parent directories when user is given" do - @catalog.add_resource @class.create( - :name => "Test", - :key => "AAA", - :type => "ssh-rsa", - :ensure => :present, - :user => "root") - @catalog.apply - - target = File.expand_path("~root/.ssh") - @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file)) - end - - it "should set target when user is given" do - @catalog.add_resource @class.create( - :name => "Test", - :key => "AAA", - :type => "ssh-rsa", - :ensure => :present, - :user => "root") - @catalog.apply - - target = File.expand_path("~root/.ssh/authorized_keys") - @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file)) - end - - - it "should autorequire parent directories when target is given" do - target = "/tmp/home/foo/bar/.ssh/authorized_keys" - - @catalog.add_resource @class.create( - :name => "Test", - :key => "AAA", - :type => "ssh-rsa", - :ensure => :present, - :target => target) - @catalog.apply - - @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file)) - end - it "should raise an error when neither user nor target is given" do proc do @class.create( -- cgit From 4ce7159baba4c637867c91519b5a3b16627dfca5 Mon Sep 17 00:00:00 2001 From: Andrew Shafer Date: Mon, 14 Jul 2008 19:54:52 -0600 Subject: Fail instead of log when rescuing remote file connections Issue 1397 one line fix, very simple --- spec/unit/type/file.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index f0ae70cd0..3ea4c3731 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -64,6 +64,11 @@ describe Puppet::Type.type(:file) do @file.property(:source).retrieve lambda { @file.property(:source).sync }.should raise_error(Puppet::Error) end + + it "should fail if it cannot describe remote contents" do + @filesource.server.stubs(:describe).raises(Puppet::Network::XMLRPCClientError.new("Testing")) + lambda { @file.retrieve }.should raise_error(Puppet::Error) + end end describe "when managing links" do -- cgit From bdbd992a6f5ff9628682179639923214d09a780c Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 17 Jul 2008 13:08:15 +1000 Subject: Updated /spec/unit/rails.rb test --- spec/unit/rails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb index bb2f991ca..382f7c0f4 100755 --- a/spec/unit/rails.rb +++ b/spec/unit/rails.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/rails' describe Puppet::Rails, "when initializing any connection" do - confine Puppet.features.rails? => "Cannot test without ActiveRecord" + confine "Cannot test without ActiveRecord" => Puppet.features.rails? before do @logger = mock 'logger' -- cgit From 7fa7251e30dfefc95dda6ef82181d4346f36880d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 16 Jul 2008 22:00:38 -0500 Subject: The mongrel-related tests now run without mongrel. Here were the main changes necessary: * Fixed the class loader so it only loads mongrel if it's available. * Fixed the test runner to skip example groups contained in non-runnable example groups. * Fixed the Mongrel tests to use quoted class names instead of constants, since the constants themselves would be absent. Signed-off-by: Luke Kanies --- spec/integration/indirector/rest.rb | 4 ++-- spec/unit/network/http.rb | 12 +++++++++--- spec/unit/network/http/mongrel.rb | 6 +++--- spec/unit/network/http/mongrel/rest.rb | 16 ++++++++++++++-- spec/unit/network/http/webrick.rb | 1 + spec/unit/network/http/webrick/rest.rb | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) (limited to 'spec') diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb index 7edd0b865..9efcdcbd3 100755 --- a/spec/integration/indirector/rest.rb +++ b/spec/integration/indirector/rest.rb @@ -118,7 +118,7 @@ describe Puppet::Indirector::REST do end it 'should return the instance of the model class associated with the provided lookup key' do - Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value) + Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value } end it 'should set a version timestamp on model instances' do @@ -334,7 +334,7 @@ describe Puppet::Indirector::REST do end it 'should return the instance of the model class associated with the provided lookup key' do - Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value) + Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value } end it 'should set an expiration on model instances' do diff --git a/spec/unit/network/http.rb b/spec/unit/network/http.rb index 79a0a88d4..1fa025b0b 100755 --- a/spec/unit/network/http.rb +++ b/spec/unit/network/http.rb @@ -12,9 +12,15 @@ describe Puppet::Network::HTTP do Puppet::Network::HTTP.server_class_by_type(:webrick).should be(Puppet::Network::HTTP::WEBrick) end - if Puppet.features.mongrel? - it "should return the mongrel HTTP server class when asked for a mongrel server" do - Puppet::Network::HTTP.server_class_by_type(:mongrel).should be(Puppet::Network::HTTP::Mongrel) + describe "when asked for a mongrel server" do + if Puppet.features.mongrel? + it "should return the mongrel server class" do + Puppet::Network::HTTP.server_class_by_type(:mongrel).should be(Puppet::Network::HTTP::Mongrel) + end + else + it "should fail" do + lambda { Puppet::Network::HTTP.server_class_by_type(:mongrel) }.should raise_error(ArgumentError) + end end end diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb index ccfca2f55..3a9cfb52f 100755 --- a/spec/unit/network/http/mongrel.rb +++ b/spec/unit/network/http/mongrel.rb @@ -6,7 +6,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/network/http' -describe Puppet::Network::HTTP::Mongrel, "after initializing" do +describe "Puppet::Network::HTTP::Mongrel", "after initializing" do confine "Mongrel is not available" => Puppet.features.mongrel? it "should not be listening" do @@ -14,7 +14,7 @@ describe Puppet::Network::HTTP::Mongrel, "after initializing" do end end -describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do +describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do confine "Mongrel is not available" => Puppet.features.mongrel? before do @@ -82,7 +82,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do end end -describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do +describe "Puppet::Network::HTTP::Mongrel", "when turning off listening" do confine "Mongrel is not available" => Puppet.features.mongrel? before do diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb index 3df925133..de5254a7a 100755 --- a/spec/unit/network/http/mongrel/rest.rb +++ b/spec/unit/network/http/mongrel/rest.rb @@ -3,10 +3,12 @@ require File.dirname(__FILE__) + '/../../../../spec_helper' require 'puppet/network/http' -describe Puppet::Network::HTTP::MongrelREST, "when initializing" do +describe "Puppet::Network::HTTP::MongrelREST", "when initializing" do confine "Mongrel is not available" => Puppet.features.mongrel? before do + require 'puppet/network/http/mongrel/rest' + @mock_mongrel = mock('Mongrel server') @mock_mongrel.stubs(:register) @mock_model = mock('indirected model') @@ -33,7 +35,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when initializing" do end end -describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do +describe "Puppet::Network::HTTP::MongrelREST", "when receiving a request" do confine "Mongrel is not available" => Puppet.features.mongrel? before do @@ -131,6 +133,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do end describe "and determining the request parameters", :shared => true do + confine "Mongrel is not available" => Puppet.features.mongrel? + before do @mock_request.stubs(:params).returns({}) end @@ -198,6 +202,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do end describe "when finding a model instance" do |variable| + confine "Mongrel is not available" => Puppet.features.mongrel? + it "should fail to find model if key is not specified" do @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foo'}) @mock_response.expects(:start).with(404) @@ -236,6 +242,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do end describe "when destroying a model instance" do |variable| + confine "Mongrel is not available" => Puppet.features.mongrel? + it "should fail to destroy model if key is not specified" do @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foo'}) @mock_response.expects(:start).with(404) @@ -281,6 +289,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do end describe "when saving a model instance" do |variable| + confine "Mongrel is not available" => Puppet.features.mongrel? + it "should fail to save model if data is not specified" do @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foo'}) @mock_request.stubs(:body).returns('') @@ -319,6 +329,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do end describe "when searching for model instances" do |variable| + confine "Mongrel is not available" => Puppet.features.mongrel? + it "should use a common method for determining the request parameters" do setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy') @handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy) diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index 78bd39145..9b024ae31 100755 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/network/http' +require 'puppet/network/http/webrick' describe Puppet::Network::HTTP::WEBrick, "after initializing" do it "should not be listening" do diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb index 45e5f0bd2..17d47e54c 100755 --- a/spec/unit/network/http/webrick/rest.rb +++ b/spec/unit/network/http/webrick/rest.rb @@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../../../../spec_helper' require 'puppet/network/http' +require 'puppet/network/http/webrick/rest' describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do before do -- cgit From a0fa09f6ee562dd1b61fe56dd4b914419d641986 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 18 Jul 2008 00:12:01 -0500 Subject: Revert "Fixed #1201 - all external node attributes are converted to strings." This reverts commit ac7f59618a80b6a4aac777f6184e7fa6a0614079. The reason for this revert is that the problem never really existed; Ruby's true and false are always used unless you quote them. --- spec/unit/indirector/node/exec.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'spec') diff --git a/spec/unit/indirector/node/exec.rb b/spec/unit/indirector/node/exec.rb index 2276e4298..09f13ab90 100755 --- a/spec/unit/indirector/node/exec.rb +++ b/spec/unit/indirector/node/exec.rb @@ -49,12 +49,6 @@ describe Puppet::Node::Exec do @searcher.find(@request) end - it "should convert all parameters into strings" do - @result[:parameters] = {"a" => true, "c" => 100} - @node.expects(:parameters=).with "a" => "true", "c" => "100" - @searcher.find(@request) - end - it "should set the resulting classes as the node classes" do @result[:classes] = %w{one two} @node.expects(:classes=).with %w{one two} -- cgit From d8937acb8c9b108e61330cbac703a17b2eaba9b3 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 18 Jul 2008 00:54:59 -0500 Subject: You can now select the encoding format when transferring the catalog, with 'yaml' still being the default but 'marshal' being an option. This is because testing has shown drastic performance differences between the two, with up to 70% of compile time being spent in YAML code. Use the 'catalog_format' setting to choose your format, and the setting must be set on the client. Signed-off-by: Luke Kanies --- spec/integration/defaults.rb | 4 ++ spec/unit/network/client/master.rb | 96 ++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 19 deletions(-) (limited to 'spec') diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb index c506700c8..54b673a1a 100755 --- a/spec/integration/defaults.rb +++ b/spec/integration/defaults.rb @@ -40,4 +40,8 @@ describe "Puppet defaults" do Puppet.settings.element(:rundir).owner.should be_nil Puppet.settings.element(:rundir).group.should be_nil end + + it "should default to yaml as the catalog format" do + Puppet.settings[:catalog_format].should == "yaml" + end end diff --git a/spec/unit/network/client/master.rb b/spec/unit/network/client/master.rb index 79ab8c86f..754fd0583 100755 --- a/spec/unit/network/client/master.rb +++ b/spec/unit/network/client/master.rb @@ -59,34 +59,92 @@ describe Puppet::Network::Client::Master, " when retrieving the catalog" do @client.getconfig end - it "should load the retrieved catalog using YAML" do - @client.stubs(:dostorage) - @client.class.stubs(:facts).returns(@facts) - @master.stubs(:getconfig).returns("myconfig") + describe "when the catalog format is set to yaml" do + before do + Puppet.settings.stubs(:value).returns "foo" + Puppet.settings.stubs(:value).with(:pluginsync).returns false + Puppet.settings.stubs(:value).with(:configtimeout).returns 10 + Puppet.settings.stubs(:value).with(:factsync).returns false + Puppet.settings.stubs(:value).with(:catalog_format).returns "yaml" + end - config = mock 'config' - YAML.expects(:load).with("myconfig").returns(config) + it "should request a yaml-encoded catalog" do + @client.stubs(:dostorage) + @client.class.stubs(:facts).returns(@facts) + @master.expects(:getconfig).with { |*args| args[1] == "yaml" } - @client.stubs(:setclasses) + @client.getconfig + end - config.stubs(:classes) - config.stubs(:to_catalog).returns(config) - config.stubs(:host_config=) - config.stubs(:from_cache).returns(true) + it "should load the retrieved catalog using YAML" do + @client.stubs(:dostorage) + @client.class.stubs(:facts).returns(@facts) + @master.stubs(:getconfig).returns("myconfig") - @client.getconfig + config = mock 'config' + YAML.expects(:load).with("myconfig").returns(config) + + @client.stubs(:setclasses) + + config.stubs(:classes) + config.stubs(:to_catalog).returns(config) + config.stubs(:host_config=) + config.stubs(:from_cache).returns(true) + + @client.getconfig + end + + it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do + @client.stubs(:dostorage) + @client.class.stubs(:facts).returns(@facts) + @master.stubs(:getconfig).returns("myconfig") + + YAML.expects(:load).with("myconfig").raises(ArgumentError) + + @client.expects(:use_cached_config).with(true) + + @client.getconfig + end end - it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do - @client.stubs(:dostorage) - @client.class.stubs(:facts).returns(@facts) - @master.stubs(:getconfig).returns("myconfig") + describe "from Marshal" do + before do + Puppet.settings.stubs(:value).returns "foo" + Puppet.settings.stubs(:value).with(:pluginsync).returns false + Puppet.settings.stubs(:value).with(:configtimeout).returns 10 + Puppet.settings.stubs(:value).with(:factsync).returns false + Puppet.settings.stubs(:value).with(:catalog_format).returns "marshal" + end - YAML.expects(:load).with("myconfig").raises(ArgumentError) + it "should load the retrieved catalog using Marshal" do + @client.stubs(:dostorage) + @client.class.stubs(:facts).returns(@facts) + @master.stubs(:getconfig).returns("myconfig") - @client.expects(:use_cached_config).with(true) + config = mock 'config' + Marshal.expects(:load).with("myconfig").returns(config) - @client.getconfig + @client.stubs(:setclasses) + + config.stubs(:classes) + config.stubs(:to_catalog).returns(config) + config.stubs(:host_config=) + config.stubs(:from_cache).returns(true) + + @client.getconfig + end + + it "should use the cached catalog if the retrieved catalog cannot be converted from Marshal" do + @client.stubs(:dostorage) + @client.class.stubs(:facts).returns(@facts) + @master.stubs(:getconfig).returns("myconfig") + + Marshal.expects(:load).with("myconfig").raises(ArgumentError) + + @client.expects(:use_cached_config).with(true) + + @client.getconfig + end end it "should set the classes.txt file with the classes listed in the retrieved catalog" do -- cgit From ebb219e496682862ac98d382afe014cf1c763f2f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 18 Jul 2008 17:51:25 -0500 Subject: Fixed all of the fileserving termini so they use indirection requests. This looks like a much larger commit than it is -- it doesn't change any behaviour at all, it just adds some integration tests (which expose the problem) and then switches from an ad-hoc api to a request-based api. Signed-off-by: Luke Kanies --- spec/integration/file_serving/metadata.rb | 1 - spec/integration/indirector/module_files.rb | 8 +- spec/shared_behaviours/file_server_terminus.rb | 4 +- spec/shared_behaviours/file_serving.rb | 22 ++++-- spec/unit/file_serving/terminus_helper.rb | 94 +++++++++++----------- spec/unit/indirector/direct_file_server.rb | 13 +--- spec/unit/indirector/file_metadata/modules.rb | 6 +- spec/unit/indirector/file_server.rb | 104 ++++++++++++++----------- spec/unit/indirector/module_files.rb | 86 +++++++++++--------- 9 files changed, 188 insertions(+), 150 deletions(-) (limited to 'spec') diff --git a/spec/integration/file_serving/metadata.rb b/spec/integration/file_serving/metadata.rb index 5600365f1..067cb566a 100755 --- a/spec/integration/file_serving/metadata.rb +++ b/spec/integration/file_serving/metadata.rb @@ -16,4 +16,3 @@ describe Puppet::FileServing::Metadata, " when finding files" do @indirection = Puppet::FileServing::Metadata.indirection end end - diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb index 1831bffbc..ae14aa5a7 100755 --- a/spec/integration/indirector/module_files.rb +++ b/spec/integration/indirector/module_files.rb @@ -20,7 +20,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module FileTest.expects(:exists?).with(filepath).returns(true) - @terminus.find("puppetmounts://host/modules/mymod/myfile").should be_instance_of(Puppet::FileServing::Content) + @request = Puppet::Indirector::Request.new(:content, :find, "puppetmounts://host/modules/mymod/myfile") + + @terminus.find(@request).should be_instance_of(Puppet::FileServing::Content) end end @@ -45,7 +47,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with FileServing::F Dir.expects(:entries).with(filepath).returns(%w{one two}) - result = @terminus.search("puppetmounts://host/modules/mymod/myfile", :recurse => true) + @request = Puppet::Indirector::Request.new(:content, :search, "puppetmounts://host/modules/mymod/myfile", :recurse => true) + + result = @terminus.search(@request) result.should be_instance_of(Array) result.length.should == 3 result.each { |r| r.should be_instance_of(Puppet::FileServing::Content) } diff --git a/spec/shared_behaviours/file_server_terminus.rb b/spec/shared_behaviours/file_server_terminus.rb index de08f29fc..bb6b67132 100644 --- a/spec/shared_behaviours/file_server_terminus.rb +++ b/spec/shared_behaviours/file_server_terminus.rb @@ -24,6 +24,8 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do # Stub out the modules terminus @modules = mock 'modules terminus' + + @request = Puppet::Indirector::Request.new(:indirection, :method, "puppetmounts://myhost/one/my/file") end it "should use the file server configuration to find files" do @@ -35,6 +37,6 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do FileTest.stubs(:exists?).with("/my/mount/path").returns(true) @mount1.expects(:file).with("my/file", :node => nil).returns(path) - @terminus.find("puppetmounts://myhost/one/my/file").should be_instance_of(@test_class) + @terminus.find(@request).should be_instance_of(@test_class) end end diff --git a/spec/shared_behaviours/file_serving.rb b/spec/shared_behaviours/file_serving.rb index 82f207243..ba01f75a1 100644 --- a/spec/shared_behaviours/file_serving.rb +++ b/spec/shared_behaviours/file_serving.rb @@ -5,13 +5,13 @@ describe "Puppet::FileServing::Files", :shared => true do it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do - uri = "puppet://myhost/mymod/my/file" + uri = "puppet://myhost/fakemod/my/file" @indirection.terminus(:rest).expects(:find) @test_class.find(uri) end it "should use the rest terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is not 'puppet'" do - uri = "puppet:///mymod/my/file" + uri = "puppet:///fakemod/my/file" Puppet.settings.stubs(:value).with(:name).returns("puppetd") Puppet.settings.stubs(:value).with(:modulepath).returns("") @indirection.terminus(:rest).expects(:find) @@ -19,7 +19,7 @@ describe "Puppet::FileServing::Files", :shared => true do end 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:///mymod/my/file" + uri = "puppet:///fakemod/my/file" Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing")) Puppet.settings.stubs(:value).with(:name).returns("puppet") Puppet.settings.stubs(:value).with(:modulepath, "testing").returns("") @@ -33,22 +33,32 @@ describe "Puppet::FileServing::Files", :shared => true do end it "should use the file_server terminus when the 'puppetmounts' URI scheme is used" do - uri = "puppetmounts:///mymod/my/file" + uri = "puppetmounts:///fakemod/my/file" @indirection.terminus(:file_server).expects(:find) @indirection.terminus(:file_server).stubs(:authorized?).returns(true) @test_class.find(uri) end it "should use the file terminus when the 'file' URI scheme is used" do - uri = "file:///mymod/my/file" + uri = "file:///fakemod/my/file" @indirection.terminus(:file).expects(:find) @test_class.find(uri) end it "should use the file terminus when a fully qualified path is provided" do - uri = "/mymod/my/file" + uri = "/fakemod/my/file" @indirection.terminus(:file).expects(:find) @test_class.find(uri) end + + it "should use the configuration to test whether the request is allowed" do + uri = "puppetmounts:///fakemod/my/file" + config = mock 'configuration' + @indirection.terminus(:file_server).stubs(:configuration).returns config + + @indirection.terminus(:file_server).expects(:find) + config.expects(:authorized?).returns(true) + @test_class.find(uri, :node => "foo", :ip => "bar") + end end diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb index b919469a2..763ce9eb0 100755 --- a/spec/unit/file_serving/terminus_helper.rb +++ b/spec/unit/file_serving/terminus_helper.rb @@ -14,65 +14,63 @@ describe Puppet::FileServing::TerminusHelper do @model = mock 'model' @helper.stubs(:model).returns(@model) + + @request = stub 'request', :key => "url", :options => {} end it "should use a fileset to find paths" do fileset = mock 'fileset', :files => [] Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset) - @helper.path2instances("url", "/my/file") + @helper.path2instances(@request, "/my/file") end it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do fileset = mock 'fileset', :files => [] Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset) - @helper.path2instances("url", "/my/file", :links => :a, :ignore => :b, :recurse => :c) - end -end - - -describe Puppet::FileServing::TerminusHelper, " when creating instances" do - before do - @helper = Object.new - @helper.extend(Puppet::FileServing::TerminusHelper) - - @model = mock 'model' - @helper.stubs(:model).returns(@model) - - @key = "puppet://host/mount/dir" - - @fileset = mock 'fileset', :files => %w{one two} - Puppet::FileServing::Fileset.expects(:new).returns(@fileset) - end - - it "should create an instance of the model for each path returned by the fileset" do - @model.expects(:new).returns(:one) - @model.expects(:new).returns(:two) - @helper.path2instances(@key, "/my/file").length.should == 2 - end - - it "should set each instance's key to be the original key plus the file-specific path" do - @model.expects(:new).with { |key, options| key == @key + "/one" }.returns(:one) - @model.expects(:new).with { |key, options| key == @key + "/two" }.returns(:two) - @helper.path2instances(@key, "/my/file") - end - - it "should set each returned instance's path to the original path" do - @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one) - @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two) - @helper.path2instances(@key, "/my/file") - end - - it "should set each returned instance's relative path to the file-specific path" do - @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one) - @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two) - @helper.path2instances(@key, "/my/file") + @request.stubs(:options).returns(:links => :a, :ignore => :b, :recurse => :c) + @helper.path2instances(@request, "/my/file") end - it "should set the links value on each instance if one is provided" do - one = mock 'one', :links= => :manage - two = mock 'two', :links= => :manage - @model.expects(:new).returns(one) - @model.expects(:new).returns(two) - @helper.path2instances(@key, "/my/file", :links => :manage) + describe "when creating instances" do + before do + @request.stubs(:key).returns "puppet://host/mount/dir" + + @fileset = mock 'fileset', :files => %w{one two} + Puppet::FileServing::Fileset.expects(:new).returns(@fileset) + end + + it "should create an instance of the model for each path returned by the fileset" do + @model.expects(:new).returns(:one) + @model.expects(:new).returns(:two) + @helper.path2instances(@request, "/my/file").length.should == 2 + end + + it "should set each instance's key to be the original key plus the file-specific path" do + @model.expects(:new).with { |key, options| key == @request.key + "/one" }.returns(:one) + @model.expects(:new).with { |key, options| key == @request.key + "/two" }.returns(:two) + @helper.path2instances(@request, "/my/file") + end + + it "should set each returned instance's path to the original path" do + @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one) + @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two) + @helper.path2instances(@request, "/my/file") + end + + it "should set each returned instance's relative path to the file-specific path" do + @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one) + @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two) + @helper.path2instances(@request, "/my/file") + end + + it "should set the links value on each instance if one is provided" do + one = mock 'one', :links= => :manage + two = mock 'two', :links= => :manage + @model.expects(:new).returns(one) + @model.expects(:new).returns(two) + + @request.options[:links] = :manage + @helper.path2instances(@request, "/my/file") + end end end diff --git a/spec/unit/indirector/direct_file_server.rb b/spec/unit/indirector/direct_file_server.rb index a8583716a..0753f1bbe 100755 --- a/spec/unit/indirector/direct_file_server.rb +++ b/spec/unit/indirector/direct_file_server.rb @@ -69,29 +69,20 @@ describe Puppet::Indirector::DirectFileServer do end describe Puppet::Indirector::DirectFileServer, "when searching for multiple files" do - it "should return nil if the file does not exist" do FileTest.expects(:exists?).with("/my/local").returns false @server.find(@request).should be_nil end - it "should pass the original key to :path2instances" do - FileTest.expects(:exists?).with("/my/local").returns true - @server.expects(:path2instances).with { |uri, path, options| uri == @uri } - @server.search(@request) - end - it "should use :path2instances from the terminus_helper to return instances if the file exists" do FileTest.expects(:exists?).with("/my/local").returns true @server.expects(:path2instances) @server.search(@request) end - it "should pass any options on to :path2instances" do + it "should pass the original request to :path2instances" do FileTest.expects(:exists?).with("/my/local").returns true - @server.expects(:path2instances).with { |uri, path, options| options == {:testing => :one, :other => :two}} - - @request.stubs(:options).returns(:testing => :one, :other => :two) + @server.expects(:path2instances).with(@request, "/my/local") @server.search(@request) end end diff --git a/spec/unit/indirector/file_metadata/modules.rb b/spec/unit/indirector/file_metadata/modules.rb index 62f01832c..3905a49ad 100755 --- a/spec/unit/indirector/file_metadata/modules.rb +++ b/spec/unit/indirector/file_metadata/modules.rb @@ -23,11 +23,13 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do @finder.stubs(:environment).returns(nil) @module = Puppet::Module.new("mymod", "/path/to") @finder.stubs(:find_module).returns(@module) + + @request = Puppet::Indirector::Request.new(:metadata, :find, "puppetmounts://hostname/modules/mymod/my/file") end it "should return nil if the file is not found" do FileTest.expects(:exists?).with("/path/to/files/my/file").returns false - @finder.find("puppetmounts://hostname/modules/mymod/my/file").should be_nil + @finder.find(@request).should be_nil end it "should retrieve the instance's attributes if the file is found" do @@ -35,6 +37,6 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do instance = mock 'metadta' Puppet::FileServing::Metadata.expects(:new).returns instance instance.expects :collect_attributes - @finder.find("puppetmounts://hostname/modules/mymod/my/file") + @finder.find(@request) end end diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb index 79be8cc29..ba951737a 100755 --- a/spec/unit/indirector/file_server.rb +++ b/spec/unit/indirector/file_server.rb @@ -27,34 +27,37 @@ describe Puppet::Indirector::FileServer do @uri = "puppetmounts://host/my/local/file" @configuration = mock 'configuration' Puppet::FileServing::Configuration.stubs(:create).returns(@configuration) + + @request = Puppet::Indirector::Request.new(:myind, :mymethod, @uri) end describe Puppet::Indirector::FileServer, " when finding files" do it "should use the path portion of the URI as the file name" do @configuration.expects(:file_path).with("/my/local/file", :node => nil) - @file_server.find(@uri) + @file_server.find(@request) end it "should use the FileServing configuration to convert the file name to a fully qualified path" do @configuration.expects(:file_path).with("/my/local/file", :node => nil) - @file_server.find(@uri) + @file_server.find(@request) end it "should pass the node name to the FileServing configuration if one is provided" do @configuration.expects(:file_path).with("/my/local/file", :node => "testing") - @file_server.find(@uri, :node => "testing") + @request.node = "testing" + @file_server.find(@request) end it "should return nil if no fully qualified path is found" do @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil) - @file_server.find(@uri).should be_nil + @file_server.find(@request).should be_nil end it "should return an instance of the model created with the full path if a file is found" do @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file") @model.expects(:new).returns(:myinstance) - @file_server.find(@uri).should == :myinstance + @file_server.find(@request).should == :myinstance end end @@ -66,23 +69,24 @@ describe Puppet::Indirector::FileServer do it "should create the instance with the key used to find the instance" do @model.expects(:new).with { |key, *options| key == @uri } - @file_server.find(@uri) + @file_server.find(@request) end it "should create the instance with the path at which the instance was found" do @model.expects(:new).with { |key, options| options[:path] == "/some/file" } - @file_server.find(@uri) + @file_server.find(@request) end it "should set the provided :links setting on to the instance if one is provided" do @model.expects(:new).returns(@instance) @instance.expects(:links=).with(:mytest) - @file_server.find(@uri, :links => :mytest) + @request.options[:links] = :mytest + @file_server.find(@request) end it "should not set a :links value if no :links parameter is provided" do @model.expects(:new).returns(@instance) - @file_server.find(@uri) + @file_server.find(@request) end end @@ -93,41 +97,52 @@ describe Puppet::Indirector::FileServer do end it "should deny the :destroy method" do - @file_server.authorized?(:destroy, "whatever").should be_false + @request.method = :destroy + @file_server.authorized?(@request).should be_false end it "should deny the :save method" do - @file_server.authorized?(:save, "whatever").should be_false - end + @request.method = :save + @file_server.authorized?(@request).should be_false + end + + describe "and finding file information" do + before do + @request.key = "puppetmounts://host/my/file" + @request.method = :find + end - it "should use the file server configuration to determine authorization" do - @configuration.expects(:authorized?) - @file_server.authorized?(:find, "puppetmounts://host/my/file") - end + it "should use the file server configuration to determine authorization" do + @configuration.expects(:authorized?) + @file_server.authorized?(@request) + end - it "should pass the file path from the URI to the file server configuration" do - @configuration.expects(:authorized?).with { |uri, *args| uri == "/my/file" } - @file_server.authorized?(:find, "puppetmounts://host/my/file") - end + it "should pass the file path from the URI to the file server configuration" do + @configuration.expects(:authorized?).with { |uri, *args| uri == "/my/file" } + @file_server.authorized?(@request) + end - it "should pass the node name to the file server configuration" do - @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" } - @file_server.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode") - end + it "should pass the node name to the file server configuration" do + @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" } + @request.node = "mynode" + @file_server.authorized?(@request) + end - it "should pass the IP address to the file server configuration" do - @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" } - @file_server.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip") - end + it "should pass the IP address to the file server configuration" do + @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" } + @request.ip = "myip" + @file_server.authorized?(@request) + end - it "should return false if the file server configuration denies authorization" do - @configuration.expects(:authorized?).returns(false) - @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_false - end + it "should return false if the file server configuration denies authorization" do + @configuration.expects(:authorized?).returns(false) + @file_server.authorized?(@request) + end - it "should return true if the file server configuration approves authorization" do - @configuration.expects(:authorized?).returns(true) - @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_true + it "should return true if the file server configuration approves authorization" do + @configuration.expects(:authorized?).returns(true) + @file_server.authorized?(@request) + end end end @@ -135,34 +150,35 @@ describe Puppet::Indirector::FileServer do it "should use the path portion of the URI as the file name" do @configuration.expects(:file_path).with("/my/local/file", :node => nil) - @file_server.search(@uri) + @file_server.search(@request) end it "should use the FileServing configuration to convert the file name to a fully qualified path" do @configuration.expects(:file_path).with("/my/local/file", :node => nil) - @file_server.search(@uri) + @file_server.search(@request) end it "should pass the node name to the FileServing configuration if one is provided" do @configuration.expects(:file_path).with("/my/local/file", :node => "testing") - @file_server.search(@uri, :node => "testing") + @request.node = "testing" + @file_server.search(@request) end it "should return nil if no fully qualified path is found" do @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil) - @file_server.search(@uri).should be_nil + @file_server.search(@request).should be_nil end it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file") - @file_server.expects(:path2instances).with(@uri, "/my/file", {}) - @file_server.search(@uri) + @file_server.expects(:path2instances) + @file_server.search(@request) end - it "should pass any options on to :path2instances" do + it "should pass the request on to :path2instances" do @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file") - @file_server.expects(:path2instances).with(@uri, "/my/file", :testing => :one, :other => :two) - @file_server.search(@uri, :testing => :one, :other => :two) + @file_server.expects(:path2instances).with(@request, "/my/file") + @file_server.search(@request) end end end diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb index f5b92e1fd..32dedd4f1 100755 --- a/spec/unit/indirector/module_files.rb +++ b/spec/unit/indirector/module_files.rb @@ -27,61 +27,66 @@ describe Puppet::Indirector::ModuleFiles do @uri = "puppetmounts://host/modules/my/local/file" @module = Puppet::Module.new("mymod", "/module/path") + + @request = stub 'request', :key => @uri, :options => {}, :node => nil, :ip => nil, :method => :find end describe Puppet::Indirector::ModuleFiles, " when finding files" do it "should strip off the leading '/modules' mount name" do Puppet::Module.expects(:find).with('my', "myenv").returns @module - @module_files.find(@uri) + @module_files.find(@request) end it "should not strip off leading terms that start with '/modules' but are longer words" do + @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file" Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil - @module_files.find("puppetmounts://host/modulestart/my/local/file") + @module_files.find(@request) end it "should search for a module whose name is the first term in the remaining file path" do Puppet::Module.expects(:find).with('my', "myenv").returns @module - @module_files.find(@uri) + @module_files.find(@request) end it "should search for a file relative to the module's files directory" do Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file") - @module_files.find(@uri) + @module_files.find(@request) end it "should return nil if the module does not exist" do Puppet::Module.expects(:find).with('my', "myenv").returns nil - @module_files.find(@uri).should be_nil + @module_files.find(@request).should be_nil end it "should return nil if the module exists but the file does not" do Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false) - @module_files.find(@uri).should be_nil + @module_files.find(@request).should be_nil end it "should return an instance of the model if a module is found and the file exists" do Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) @model.expects(:new).returns(:myinstance) - @module_files.find(@uri).should == :myinstance + @module_files.find(@request).should == :myinstance end it "should use the node's environment to look up the module if the node name is provided" do node = stub "node", :environment => "testing" Puppet::Node.expects(:find).with("mynode").returns(node) Puppet::Module.expects(:find).with('my', "testing") - @module_files.find(@uri, :node => "mynode") + + @request.stubs(:node).returns "mynode" + @module_files.find(@request) end it "should use the default environment setting to look up the module if the node name is not provided" do env = stub "environment", :name => "testing" Puppet::Node::Environment.stubs(:new).returns(env) Puppet::Module.expects(:find).with('my', "testing") - @module_files.find(@uri) + @module_files.find(@request) end end @@ -95,23 +100,25 @@ describe Puppet::Indirector::ModuleFiles do it "should create the instance with the key used to find the instance" do @model.expects(:new).with { |key, *options| key == @uri } - @module_files.find(@uri) + @module_files.find(@request) end it "should create the instance with the path at which the instance was found" do @model.expects(:new).with { |key, options| options[:path] == "/module/path/files/local/file" } - @module_files.find(@uri) + @module_files.find(@request) end it "should set the provided :links setting on to the instance if one is provided" do @model.expects(:new).returns(@instance) @instance.expects(:links=).with(:mytest) - @module_files.find(@uri, :links => :mytest) + + @request.options[:links] = :mytest + @module_files.find(@request) end it "should not set a :links value if no :links parameter is provided" do @model.expects(:new).returns(@instance) - @module_files.find(@uri) + @module_files.find(@request) end end @@ -127,46 +134,53 @@ describe Puppet::Indirector::ModuleFiles do end it "should deny the :destroy method" do - @module_files.authorized?(:destroy, "whatever").should be_false + @request.expects(:method).returns :destroy + @module_files.authorized?(@request).should be_false end it "should deny the :save method" do - @module_files.authorized?(:save, "whatever").should be_false + @request.expects(:method).returns :save + @module_files.authorized?(@request).should be_false end it "should use the file server configuration to determine authorization" do @configuration.expects(:authorized?) - @module_files.authorized?(:find, "puppetmounts://host/my/file") + @module_files.authorized?(@request) end it "should use the path directly from the URI if it already includes /modules" do + @request.expects(:key).returns "puppetmounts://host/modules/my/file" @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" } - @module_files.authorized?(:find, "puppetmounts://host/modules/my/file") + @module_files.authorized?(@request) end it "should add /modules to the file path if it's not included in the URI" do + @request.expects(:key).returns "puppetmounts://host/my/file" @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" } - @module_files.authorized?(:find, "puppetmounts://host/my/file") + @module_files.authorized?(@request) end it "should pass the node name to the file server configuration" do + @request.expects(:key).returns "puppetmounts://host/my/file" @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" } - @module_files.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode") + @request.stubs(:node).returns "mynode" + @module_files.authorized?(@request) end it "should pass the IP address to the file server configuration" do + @request.expects(:ip).returns "myip" @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" } - @module_files.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip") + @module_files.authorized?(@request) end it "should return false if the file server configuration denies authorization" do @configuration.expects(:authorized?).returns(false) - @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_false + @module_files.authorized?(@request).should be_false end it "should return true if the file server configuration approves authorization" do @configuration.expects(:authorized?).returns(true) - @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_true + @module_files.authorized?(@request).should be_true end end @@ -175,69 +189,71 @@ describe Puppet::Indirector::ModuleFiles do it "should strip off the leading '/modules' mount name" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module - @module_files.search(@uri) + @module_files.search(@request) end it "should not strip off leading terms that start with '/modules' but are longer words" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil - @module_files.search("puppetmounts://host/modulestart/my/local/file") + @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file" + @module_files.search @request end it "should search for a module whose name is the first term in the remaining file path" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module - @module_files.search(@uri) + @module_files.search(@request) end it "should search for a file relative to the module's files directory" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file") - @module_files.search(@uri) + @module_files.search(@request) end it "should return nil if the module does not exist" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns nil - @module_files.search(@uri).should be_nil + @module_files.search(@request).should be_nil end it "should return nil if the module exists but the file does not" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false) - @module_files.search(@uri).should be_nil + @module_files.search(@request).should be_nil end it "should use the node's environment to look up the module if the node name is provided" do node = stub "node", :environment => "testing" Puppet::Node.expects(:find).with("mynode").returns(node) Puppet::Module.expects(:find).with('my', "testing") - @module_files.search(@uri, :node => "mynode") + @request.stubs(:node).returns "mynode" + @module_files.search(@request) end it "should use the default environment setting to look up the module if the node name is not provided and the environment is not set to ''" do env = stub 'env', :name => "testing" Puppet::Node::Environment.stubs(:new).returns(env) Puppet::Module.expects(:find).with('my', "testing") - @module_files.search(@uri) + @module_files.search(@request) end it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) - @module_files.expects(:path2instances).with(@uri, "/module/path/files/local/file", {}) - @module_files.search(@uri) + @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file") + @module_files.search(@request) end - it "should pass any options on to :path2instances" do + it "should pass the request directly to :path2instances" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) - @module_files.expects(:path2instances).with(@uri, "/module/path/files/local/file", :testing => :one, :other => :two) - @module_files.search(@uri, :testing => :one, :other => :two) + @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file") + @module_files.search(@request) end end end -- cgit From 238b8d7f0a16eda971409d7423dc1f04cf0e2a34 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 18 Jul 2008 15:30:42 -0500 Subject: Fixing #1438 -- mongrel and module tests now pass. Signed-off-by: Luke Kanies --- spec/unit/module.rb | 4 ++-- spec/unit/network/http/mongrel.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/unit/module.rb b/spec/unit/module.rb index 2dadaa501..e79001ae1 100755 --- a/spec/unit/module.rb +++ b/spec/unit/module.rb @@ -143,8 +143,8 @@ describe Puppet::Module, " when searching for manifests when no module is found" it "should look for files relative to the current directory" do cwd = Dir.getwd - Dir.expects(:glob).with("#{cwd}/mymod/init.pp").returns(["#{cwd}/mymod/init.pp"]) - Puppet::Module.find_manifests("mymod/init.pp").should == ["#{cwd}/mymod/init.pp"] + Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"]) + Puppet::Module.find_manifests("foobar/init.pp").should == ["#{cwd}/foobar/init.pp"] end it "should only return files, not directories" do diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb index 3a9cfb52f..1732009a8 100755 --- a/spec/unit/network/http/mongrel.rb +++ b/spec/unit/network/http/mongrel.rb @@ -10,6 +10,8 @@ describe "Puppet::Network::HTTP::Mongrel", "after initializing" do confine "Mongrel is not available" => Puppet.features.mongrel? it "should not be listening" do + require 'puppet/network/http/mongrel' + Puppet::Network::HTTP::Mongrel.new.should_not be_listening end end @@ -18,6 +20,8 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do confine "Mongrel is not available" => Puppet.features.mongrel? before do + require 'puppet/network/http/mongrel' + @server = Puppet::Network::HTTP::Mongrel.new @mock_mongrel = mock('mongrel') @mock_mongrel.stubs(:run) -- cgit From f16da4250c16aeab932a81a349df059c69d7ee23 Mon Sep 17 00:00:00 2001 From: Brett Lentz Date: Fri, 18 Jul 2008 10:05:02 -0700 Subject: Merging fsweetser's selinux patch against 0.24.4 --- spec/unit/other/selinux.rb | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 spec/unit/other/selinux.rb (limited to 'spec') diff --git a/spec/unit/other/selinux.rb b/spec/unit/other/selinux.rb new file mode 100644 index 000000000..0974b71c3 --- /dev/null +++ b/spec/unit/other/selinux.rb @@ -0,0 +1,78 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/type/selboolean' +require 'puppet/type/selmodule' + +describe Puppet::Type::File, " when manipulating file contexts" do + before :each do + @file = Puppet.type(:file).create( + :path => "/tmp/foo", + :ensure => "file", + :seluser => "user_u", + :selrole => "role_r", + :seltype => "type_t") + end + it "should use :seluser to get/set an SELinux user file context attribute" do + @file[:seluser].should == "user_u" + end + it "should use :selrole to get/set an SELinux role file context attribute" do + @file[:selrole].should == "role_r" + end + it "should use :seltype to get/set an SELinux user file context attribute" do + @file[:seltype].should == "type_t" + end +end + +describe Puppet::Type::Selboolean, " when manipulating booleans" do + before :each do + @bool = Puppet.type(:selboolean).create( + :name => "foo", + :value => "on", + :persistent => true) + end + it "should be able to access :name" do + @bool[:name].should == "foo" + end + it "should be able to access :value" do + @bool[:value].should == :on + end + it "should set :value to off" do + @bool[:value] = :off + @bool[:value].should == :off + end + it "should be able to access :persistent" do + @bool[:persistent].should == :true + end + it "should set :persistent to false" do + @bool[:persistent] = false + @bool[:persistent].should == :false + end +end + +describe Puppet::Type::Selmodule, " when checking policy modules" do + before :each do + @module = Puppet.type(:selmodule).create( + :name => "foo", + :selmoduledir => "/some/path", + :selmodulepath => "/some/path/foo.pp", + :syncversion => true) + end + it "should be able to access :name" do + @module[:name].should == "foo" + end + it "should be able to access :selmoduledir" do + @module[:selmoduledir].should == "/some/path" + end + it "should be able to access :selmodulepath" do + @module[:selmodulepath].should == "/some/path/foo.pp" + end + it "should be able to access :syncversion" do + @module[:syncversion].should == :true + end + it "should set the syncversion value to false" do + @module[:syncversion] = :false + @module[:syncversion].should == :false + end +end -- cgit From 686ba4d4c21f6f1e073bd845492f2fe3cb4837a2 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sun, 20 Jul 2008 16:11:56 +1000 Subject: Revert "Merging fsweetser's selinux patch against 0.24.4" This reverts commit f16da4250c16aeab932a81a349df059c69d7ee23. --- spec/unit/other/selinux.rb | 78 ---------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 spec/unit/other/selinux.rb (limited to 'spec') diff --git a/spec/unit/other/selinux.rb b/spec/unit/other/selinux.rb deleted file mode 100644 index 0974b71c3..000000000 --- a/spec/unit/other/selinux.rb +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' - -require 'puppet/type/selboolean' -require 'puppet/type/selmodule' - -describe Puppet::Type::File, " when manipulating file contexts" do - before :each do - @file = Puppet.type(:file).create( - :path => "/tmp/foo", - :ensure => "file", - :seluser => "user_u", - :selrole => "role_r", - :seltype => "type_t") - end - it "should use :seluser to get/set an SELinux user file context attribute" do - @file[:seluser].should == "user_u" - end - it "should use :selrole to get/set an SELinux role file context attribute" do - @file[:selrole].should == "role_r" - end - it "should use :seltype to get/set an SELinux user file context attribute" do - @file[:seltype].should == "type_t" - end -end - -describe Puppet::Type::Selboolean, " when manipulating booleans" do - before :each do - @bool = Puppet.type(:selboolean).create( - :name => "foo", - :value => "on", - :persistent => true) - end - it "should be able to access :name" do - @bool[:name].should == "foo" - end - it "should be able to access :value" do - @bool[:value].should == :on - end - it "should set :value to off" do - @bool[:value] = :off - @bool[:value].should == :off - end - it "should be able to access :persistent" do - @bool[:persistent].should == :true - end - it "should set :persistent to false" do - @bool[:persistent] = false - @bool[:persistent].should == :false - end -end - -describe Puppet::Type::Selmodule, " when checking policy modules" do - before :each do - @module = Puppet.type(:selmodule).create( - :name => "foo", - :selmoduledir => "/some/path", - :selmodulepath => "/some/path/foo.pp", - :syncversion => true) - end - it "should be able to access :name" do - @module[:name].should == "foo" - end - it "should be able to access :selmoduledir" do - @module[:selmoduledir].should == "/some/path" - end - it "should be able to access :selmodulepath" do - @module[:selmodulepath].should == "/some/path/foo.pp" - end - it "should be able to access :syncversion" do - @module[:syncversion].should == :true - end - it "should set the syncversion value to false" do - @module[:syncversion] = :false - @module[:syncversion].should == :false - end -end -- cgit