diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-02-19 15:32:30 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-02-19 15:32:30 +1100 |
commit | 95b8414b8164b1beffea20973e204b1b5cbba763 (patch) | |
tree | 775a00896d2a4281f9cd3ae92b21d95f51307862 /spec/unit/file_serving | |
parent | d82bfd86288cc012018797d98168f918bff75778 (diff) | |
parent | 39f9818276e49020c1a6db9667371f7617d5cc93 (diff) | |
download | puppet-95b8414b8164b1beffea20973e204b1b5cbba763.tar.gz puppet-95b8414b8164b1beffea20973e204b1b5cbba763.tar.xz puppet-95b8414b8164b1beffea20973e204b1b5cbba763.zip |
Merge branch '0.24.x' of git://reductivelabs.com/puppet into 0.24.x
Diffstat (limited to 'spec/unit/file_serving')
-rwxr-xr-x | spec/unit/file_serving/configuration.rb | 389 | ||||
-rwxr-xr-x | spec/unit/file_serving/configuration/parser.rb | 175 |
2 files changed, 282 insertions, 282 deletions
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb index df46b9b6a..eecaefe5f 100755 --- a/spec/unit/file_serving/configuration.rb +++ b/spec/unit/file_serving/configuration.rb @@ -4,17 +4,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/configuration' -module FSConfigurationTesting - def setup - @path = "/path/to/configuration/file.conf" - Puppet.settings.stubs(:value).with(:fileserverconfig).returns(@path) - end - - def teardown - Puppet::FileServing::Configuration.clear_cache - end -end - describe Puppet::FileServing::Configuration do it "should make :new a private method" do proc { Puppet::FileServing::Configuration.new }.should raise_error @@ -35,193 +24,201 @@ describe Puppet::FileServing::Configuration do end end -describe Puppet::FileServing::Configuration, " when initializing" do - include FSConfigurationTesting - - it "should work without a configuration file" do - FileTest.stubs(:exists?).with(@path).returns(false) - proc { Puppet::FileServing::Configuration.create }.should_not raise_error - end - - it "should parse the configuration file if present" do - FileTest.stubs(:exists?).with(@path).returns(true) - @parser = mock 'parser' - @parser.expects(:parse).returns({}) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - Puppet::FileServing::Configuration.create - end - - it "should determine the path to the configuration file from the Puppet settings" do - Puppet::FileServing::Configuration.create - end -end - -describe Puppet::FileServing::Configuration, " when parsing the configuration file" do - include FSConfigurationTesting - - before do - FileTest.stubs(:exists?).with(@path).returns(true) - @parser = mock 'parser' - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - end - - it "should set the mount list to the results of parsing" do - @parser.expects(:parse).returns("one" => mock("mount")) - config = Puppet::FileServing::Configuration.create - config.mounted?("one").should be_true - end - - it "should not raise exceptions" do - @parser.expects(:parse).raises(ArgumentError) - proc { Puppet::FileServing::Configuration.create }.should_not raise_error - end - - it "should replace the existing mount list with the results of reparsing" do - @parser.expects(:parse).returns("one" => mock("mount")) - config = Puppet::FileServing::Configuration.create - config.mounted?("one").should be_true - # Now parse again - @parser.expects(:parse).returns("two" => mock('other')) - config.send(:readconfig, false) - config.mounted?("one").should be_false - config.mounted?("two").should be_true - end - - it "should not replace the mount list until the file is entirely parsed successfully" do - @parser.expects(:parse).returns("one" => mock("mount")) - @parser.expects(:parse).raises(ArgumentError) - config = Puppet::FileServing::Configuration.create - # Now parse again, so the exception gets thrown - config.send(:readconfig, false) - config.mounted?("one").should be_true - end -end - -describe Puppet::FileServing::Configuration, " when finding files" do - include FSConfigurationTesting - - before do - @parser = mock 'parser' - @parser.stubs(:changed?).returns true - FileTest.stubs(:exists?).with(@path).returns(true) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - - @mount1 = stub 'mount', :name => "one" - @mounts = {"one" => @mount1} - - Facter.stubs(:value).with("hostname").returns("whatever") - - @config = Puppet::FileServing::Configuration.create - end - - it "should fail if the uri does not match a leading slash followed by a valid mount name" do - @parser.expects(:parse).returns(@mounts) - proc { @config.file_path("something") }.should raise_error(ArgumentError) - end - - it "should use the first term after the first slash for the mount name" do - @parser.expects(:parse).returns(@mounts) - FileTest.stubs(:exists?).returns(true) - @mount1.expects(:file) - @config.file_path("/one") - end - - it "should use the remainder of the URI after the mount name as the file name" do - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file).with("something/else", {}) - FileTest.stubs(:exists?).returns(true) - @config.file_path("/one/something/else") - end - - it "should treat a bare name as a mount and no relative file" do - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file).with(nil, {}) - FileTest.stubs(:exists?).returns(true) - @config.file_path("/one") - end - - it "should treat a name with a trailing slash equivalently to a name with no trailing slash" do - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file).with(nil, {}) - FileTest.stubs(:exists?).returns(true) - @config.file_path("/one/") - end - - it "should return nil if the mount cannot be found" do - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns({}) - @config.file_path("/one/something").should be_nil - end - - it "should return nil if the mount does not contain the file" do - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file).with("something/else", {}).returns(nil) - @config.file_path("/one/something/else").should be_nil - end - - it "should return the fully qualified path if the mount exists" do - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file).with("something/else", {}).returns("/full/path") - @config.file_path("/one/something/else").should == "/full/path" - end - - it "should reparse the configuration file when it has changed" do - @mount1.stubs(:file).returns("whatever") - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns(@mounts) - FileTest.stubs(:exists?).returns(true) - @config.file_path("/one/something") - - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns({}) - @config.file_path("/one/something").should be_nil - end -end - -describe Puppet::FileServing::Configuration, " when checking authorization" do - include FSConfigurationTesting - - before do - @parser = mock 'parser' - @parser.stubs(:changed?).returns true - FileTest.stubs(:exists?).with(@path).returns(true) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - - @mount1 = stub 'mount', :name => "one" - @mounts = {"one" => @mount1} - @parser.stubs(:parse).returns(@mounts) - - Facter.stubs(:value).with("hostname").returns("whatever") - - @config = Puppet::FileServing::Configuration.create - end - - it "should return false if the mount cannot be found" do - @config.authorized?("/nope/my/file").should be_false - end - - it "should use the mount to determine authorization" do - @mount1.expects(:allowed?) - @config.authorized?("/one/my/file") - end - - it "should pass the client's name to the mount if provided" do - @mount1.expects(:allowed?).with("myhost", nil) - @config.authorized?("/one/my/file", :node => "myhost") - end +describe Puppet::FileServing::Configuration do - it "should pass the client's IP to the mount if provided" do - @mount1.expects(:allowed?).with("myhost", "myip") - @config.authorized?("/one/my/file", :node => "myhost", :ipaddress => "myip") + before :each do + @path = "/path/to/configuration/file.conf" + Puppet.settings.stubs(:value).with(:fileserverconfig).returns(@path) end - it "should return true if the mount allows the client" do - @mount1.expects(:allowed?).returns(true) - @config.authorized?("/one/my/file").should be_true + after :each do + Puppet::FileServing::Configuration.clear_cache end - it "should return false if the mount denies the client" do - @mount1.expects(:allowed?).returns(false) - @config.authorized?("/one/my/file").should be_false - end -end + describe Puppet::FileServing::Configuration, " when initializing" do + + it "should work without a configuration file" do + FileTest.stubs(:exists?).with(@path).returns(false) + proc { Puppet::FileServing::Configuration.create }.should_not raise_error + end + + it "should parse the configuration file if present" do + FileTest.stubs(:exists?).with(@path).returns(true) + @parser = mock 'parser' + @parser.expects(:parse).returns({}) + Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) + Puppet::FileServing::Configuration.create + end + + it "should determine the path to the configuration file from the Puppet settings" do + Puppet::FileServing::Configuration.create + end + end + + describe Puppet::FileServing::Configuration, " when parsing the configuration file" do + + before do + FileTest.stubs(:exists?).with(@path).returns(true) + @parser = mock 'parser' + Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) + end + + it "should set the mount list to the results of parsing" do + @parser.expects(:parse).returns("one" => mock("mount")) + config = Puppet::FileServing::Configuration.create + config.mounted?("one").should be_true + end + + it "should not raise exceptions" do + @parser.expects(:parse).raises(ArgumentError) + proc { Puppet::FileServing::Configuration.create }.should_not raise_error + end + + it "should replace the existing mount list with the results of reparsing" do + @parser.expects(:parse).returns("one" => mock("mount")) + config = Puppet::FileServing::Configuration.create + config.mounted?("one").should be_true + # Now parse again + @parser.expects(:parse).returns("two" => mock('other')) + config.send(:readconfig, false) + config.mounted?("one").should be_false + config.mounted?("two").should be_true + end + + it "should not replace the mount list until the file is entirely parsed successfully" do + @parser.expects(:parse).returns("one" => mock("mount")) + @parser.expects(:parse).raises(ArgumentError) + config = Puppet::FileServing::Configuration.create + # Now parse again, so the exception gets thrown + config.send(:readconfig, false) + config.mounted?("one").should be_true + end + end + + describe Puppet::FileServing::Configuration, " when finding files" do + + before do + @parser = mock 'parser' + @parser.stubs(:changed?).returns true + FileTest.stubs(:exists?).with(@path).returns(true) + Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) + + @mount1 = stub 'mount', :name => "one" + @mounts = {"one" => @mount1} + + Facter.stubs(:value).with("hostname").returns("whatever") + + @config = Puppet::FileServing::Configuration.create + end + + it "should fail if the uri does not match a leading slash followed by a valid mount name" do + @parser.expects(:parse).returns(@mounts) + proc { @config.file_path("something") }.should raise_error(ArgumentError) + end + + it "should use the first term after the first slash for the mount name" do + @parser.expects(:parse).returns(@mounts) + FileTest.stubs(:exists?).returns(true) + @mount1.expects(:file) + @config.file_path("/one") + end + + it "should use the remainder of the URI after the mount name as the file name" do + @parser.expects(:parse).returns(@mounts) + @mount1.expects(:file).with("something/else", {}) + FileTest.stubs(:exists?).returns(true) + @config.file_path("/one/something/else") + end + + it "should treat a bare name as a mount and no relative file" do + @parser.expects(:parse).returns(@mounts) + @mount1.expects(:file).with(nil, {}) + FileTest.stubs(:exists?).returns(true) + @config.file_path("/one") + end + + it "should treat a name with a trailing slash equivalently to a name with no trailing slash" do + @parser.expects(:parse).returns(@mounts) + @mount1.expects(:file).with(nil, {}) + FileTest.stubs(:exists?).returns(true) + @config.file_path("/one/") + end + + it "should return nil if the mount cannot be found" do + @parser.expects(:changed?).returns(true) + @parser.expects(:parse).returns({}) + @config.file_path("/one/something").should be_nil + end + + it "should return nil if the mount does not contain the file" do + @parser.expects(:parse).returns(@mounts) + @mount1.expects(:file).with("something/else", {}).returns(nil) + @config.file_path("/one/something/else").should be_nil + end + + it "should return the fully qualified path if the mount exists" do + @parser.expects(:parse).returns(@mounts) + @mount1.expects(:file).with("something/else", {}).returns("/full/path") + @config.file_path("/one/something/else").should == "/full/path" + end + + it "should reparse the configuration file when it has changed" do + @mount1.stubs(:file).returns("whatever") + @parser.expects(:changed?).returns(true) + @parser.expects(:parse).returns(@mounts) + FileTest.stubs(:exists?).returns(true) + @config.file_path("/one/something") + + @parser.expects(:changed?).returns(true) + @parser.expects(:parse).returns({}) + @config.file_path("/one/something").should be_nil + end + end + + describe Puppet::FileServing::Configuration, " when checking authorization" do + + before do + @parser = mock 'parser' + @parser.stubs(:changed?).returns true + FileTest.stubs(:exists?).with(@path).returns(true) + Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) + + @mount1 = stub 'mount', :name => "one" + @mounts = {"one" => @mount1} + @parser.stubs(:parse).returns(@mounts) + + Facter.stubs(:value).with("hostname").returns("whatever") + + @config = Puppet::FileServing::Configuration.create + end + + it "should return false if the mount cannot be found" do + @config.authorized?("/nope/my/file").should be_false + end + + it "should use the mount to determine authorization" do + @mount1.expects(:allowed?) + @config.authorized?("/one/my/file") + end + + it "should pass the client's name to the mount if provided" do + @mount1.expects(:allowed?).with("myhost", nil) + @config.authorized?("/one/my/file", :node => "myhost") + end + + it "should pass the client's IP to the mount if provided" do + @mount1.expects(:allowed?).with("myhost", "myip") + @config.authorized?("/one/my/file", :node => "myhost", :ipaddress => "myip") + end + + it "should return true if the mount allows the client" do + @mount1.expects(:allowed?).returns(true) + @config.authorized?("/one/my/file").should be_true + end + + it "should return false if the mount denies the client" do + @mount1.expects(:allowed?).returns(false) + @config.authorized?("/one/my/file").should be_false + end + end +end
\ No newline at end of file diff --git a/spec/unit/file_serving/configuration/parser.rb b/spec/unit/file_serving/configuration/parser.rb index aa296cf43..df2f629d5 100755 --- a/spec/unit/file_serving/configuration/parser.rb +++ b/spec/unit/file_serving/configuration/parser.rb @@ -10,8 +10,17 @@ describe Puppet::FileServing::Configuration::Parser do end end + module FSConfigurationParserTesting - def setup + def mock_file_content(content) + # We want an array, but we actually want our carriage returns on all of it. + lines = content.split("\n").collect { |l| l + "\n" } + @filehandle.stubs(:each).multiple_yields(*lines) + end +end + +describe Puppet::FileServing::Configuration::Parser do + before :each do @path = "/my/config.conf" FileTest.stubs(:exists?).with(@path).returns(true) FileTest.stubs(:readable?).with(@path).returns(true) @@ -20,113 +29,107 @@ module FSConfigurationParserTesting @parser = Puppet::FileServing::Configuration::Parser.new(@path) end - def mock_file_content(content) - # We want an array, but we actually want our carriage returns on all of it. - lines = content.split("\n").collect { |l| l + "\n" } - @filehandle.stubs(:each).multiple_yields(*lines) - end -end - -describe Puppet::FileServing::Configuration::Parser, " when parsing" do - include FSConfigurationParserTesting + describe Puppet::FileServing::Configuration::Parser, " when parsing" do + include FSConfigurationParserTesting - before do - @parser.stubs(:add_modules_mount) - end + before do + @parser.stubs(:add_modules_mount) + end - it "should allow comments" do - @filehandle.expects(:each).yields("# this is a comment\n") - proc { @parser.parse }.should_not raise_error - end + it "should allow comments" do + @filehandle.expects(:each).yields("# this is a comment\n") + proc { @parser.parse }.should_not raise_error + end - it "should allow blank lines" do - @filehandle.expects(:each).yields("\n") - proc { @parser.parse }.should_not raise_error - end + it "should allow blank lines" do + @filehandle.expects(:each).yields("\n") + proc { @parser.parse }.should_not raise_error + end - it "should create a new mount for each section in the configuration" do - mount1 = mock 'one' - mount2 = mock 'two' - Puppet::FileServing::Mount.expects(:new).with("one").returns(mount1) - Puppet::FileServing::Mount.expects(:new).with("two").returns(mount2) - mock_file_content "[one]\n[two]\n" - @parser.parse - end + it "should create a new mount for each section in the configuration" do + mount1 = mock 'one' + mount2 = mock 'two' + Puppet::FileServing::Mount.expects(:new).with("one").returns(mount1) + Puppet::FileServing::Mount.expects(:new).with("two").returns(mount2) + mock_file_content "[one]\n[two]\n" + @parser.parse + end - # This test is almost the exact same as the previous one. - it "should return a hash of the created mounts" do - mount1 = mock 'one' - mount2 = mock 'two' - Puppet::FileServing::Mount.expects(:new).with("one").returns(mount1) - Puppet::FileServing::Mount.expects(:new).with("two").returns(mount2) - mock_file_content "[one]\n[two]\n" + # This test is almost the exact same as the previous one. + it "should return a hash of the created mounts" do + mount1 = mock 'one' + mount2 = mock 'two' + Puppet::FileServing::Mount.expects(:new).with("one").returns(mount1) + Puppet::FileServing::Mount.expects(:new).with("two").returns(mount2) + mock_file_content "[one]\n[two]\n" - @parser.parse.should == {"one" => mount1, "two" => mount2} - end + @parser.parse.should == {"one" => mount1, "two" => mount2} + end - it "should only allow mount names that are alphanumeric plus dashes" do - mock_file_content "[a*b]\n" - proc { @parser.parse }.should raise_error(ArgumentError) - end + it "should only allow mount names that are alphanumeric plus dashes" do + mock_file_content "[a*b]\n" + proc { @parser.parse }.should raise_error(ArgumentError) + end - it "should fail if the value for path/allow/deny starts with an equals sign" do - mock_file_content "[one]\npath = /testing" - proc { @parser.parse }.should raise_error(ArgumentError) + it "should fail if the value for path/allow/deny starts with an equals sign" do + mock_file_content "[one]\npath = /testing" + proc { @parser.parse }.should raise_error(ArgumentError) + end end -end -describe Puppet::FileServing::Configuration::Parser, " when parsing mount attributes" do - include FSConfigurationParserTesting + describe Puppet::FileServing::Configuration::Parser, " when parsing mount attributes" do + include FSConfigurationParserTesting - before do - @mount = stub 'mount', :name => "one" - Puppet::FileServing::Mount.expects(:new).with("one").returns(@mount) - @parser.stubs(:add_modules_mount) - end + before do + @mount = stub 'mount', :name => "one" + Puppet::FileServing::Mount.expects(:new).with("one").returns(@mount) + @parser.stubs(:add_modules_mount) + end - it "should set the mount path to the path attribute from that section" do - mock_file_content "[one]\npath /some/path\n" + it "should set the mount path to the path attribute from that section" do + mock_file_content "[one]\npath /some/path\n" - @mount.expects(:path=).with("/some/path") - @parser.parse - end + @mount.expects(:path=).with("/some/path") + @parser.parse + end - it "should tell the mount to allow any allow values from the section" do - mock_file_content "[one]\nallow something\n" + it "should tell the mount to allow any allow values from the section" do + mock_file_content "[one]\nallow something\n" - @mount.expects(:info) - @mount.expects(:allow).with("something") - @parser.parse - end + @mount.expects(:info) + @mount.expects(:allow).with("something") + @parser.parse + end - it "should tell the mount to deny any deny values from the section" do - mock_file_content "[one]\ndeny something\n" + it "should tell the mount to deny any deny values from the section" do + mock_file_content "[one]\ndeny something\n" - @mount.expects(:info) - @mount.expects(:deny).with("something") - @parser.parse - end + @mount.expects(:info) + @mount.expects(:deny).with("something") + @parser.parse + end - it "should fail on any attributes other than path, allow, and deny" do - mock_file_content "[one]\ndo something\n" + it "should fail on any attributes other than path, allow, and deny" do + mock_file_content "[one]\ndo something\n" - proc { @parser.parse }.should raise_error(ArgumentError) + proc { @parser.parse }.should raise_error(ArgumentError) + end end -end -describe Puppet::FileServing::Configuration::Parser, " when parsing the modules mount" do - include FSConfigurationParserTesting + describe Puppet::FileServing::Configuration::Parser, " when parsing the modules mount" do + include FSConfigurationParserTesting - before do - @mount = stub 'mount', :name => "modules" - Puppet::FileServing::Mount.expects(:new).with("modules").returns(@mount) - end + before do + @mount = stub 'mount', :name => "modules" + Puppet::FileServing::Mount.expects(:new).with("modules").returns(@mount) + end - it "should warn if a path is set" do - mock_file_content "[modules]\npath /some/path\n" + it "should warn if a path is set" do + mock_file_content "[modules]\npath /some/path\n" - @modules.expects(:path=).never - Puppet.expects(:warning) - @parser.parse + @modules.expects(:path=).never + Puppet.expects(:warning) + @parser.parse + end end -end +end
\ No newline at end of file |