diff options
Diffstat (limited to 'spec/unit/indirector/file_server.rb')
| -rwxr-xr-x | spec/unit/indirector/file_server.rb | 104 |
1 files changed, 60 insertions, 44 deletions
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 |
