diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2011-07-29 13:00:04 -0700 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-07-29 13:00:04 -0700 |
| commit | 6cb35727272d62514d6b82b8525b4c44701f6ef6 (patch) | |
| tree | 8df4318c6f846f73b57c715b5a589f2930606b58 | |
| parent | 11e026f53966d4525afef388a2409796bc0d807f (diff) | |
| parent | 94f0b93b6065d1818f0f3b99d12d651655247c30 (diff) | |
| download | puppet-6cb35727272d62514d6b82b8525b4c44701f6ef6.tar.gz puppet-6cb35727272d62514d6b82b8525b4c44701f6ef6.tar.xz puppet-6cb35727272d62514d6b82b8525b4c44701f6ef6.zip | |
Merge branch 'ticket/2.7.x/8704-fileserverconf_parse_errors' into 2.7.x
* ticket/2.7.x/8704-fileserverconf_parse_errors:
(#8704) Give better errors for invalid fileserver.conf
| -rwxr-xr-x | lib/puppet/network/handler/fileserver.rb | 3 | ||||
| -rwxr-xr-x | spec/unit/network/handler/fileserver_spec.rb | 32 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 5b4b17a32..5da4cedef 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -269,6 +269,7 @@ class Puppet::Network::Handler value = $2 case var when "path" + raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount if mount.name == MODULES Puppet.warning "The '#{mount.name}' module can not have a path. Ignoring attempt to set it" else @@ -280,6 +281,7 @@ class Puppet::Network::Handler end end when "allow" + raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount value.split(/\s*,\s*/).each { |val| begin mount.info "allowing #{val} access" @@ -294,6 +296,7 @@ class Puppet::Network::Handler end } when "deny" + raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount value.split(/\s*,\s*/).each { |val| begin mount.info "denying #{val} access" diff --git a/spec/unit/network/handler/fileserver_spec.rb b/spec/unit/network/handler/fileserver_spec.rb index 08852634d..851736e76 100755 --- a/spec/unit/network/handler/fileserver_spec.rb +++ b/spec/unit/network/handler/fileserver_spec.rb @@ -25,6 +25,38 @@ describe Puppet::Network::Handler::FileServer do @mount = Puppet::Network::Handler::FileServer::Mount.new("some_path", @basedir) end + describe "when parsing the fileserver.conf" do + it "should create a valid mount when a valid conf is read" do + config_file = tmpfile('fileserver.conf') + mountdir = tmpdir('mountdir') + + conf_text = <<-HEREDOC + [mymount] + path #{mountdir} + allow anyone.com + deny nobody.com + HEREDOC + File.open(config_file, 'w') { |f| f.write conf_text } + + fs = Puppet::Network::Handler::FileServer.new(:Config => config_file) + mounts = fs.instance_variable_get(:@mounts) + mount = mounts["mymount"] + mount.path == mountdir + mount.instance_variable_get(:@declarations).map {|d| d.pattern}.should =~ [["com", "nobody"], ["com", "anyone"]] + end + + ['path', 'allow', 'deny'].each do |arg| + it "should error if config file doesn't specify a mount for #{arg} argument" do + config_file = tmpfile('fileserver.conf') + File.open(config_file, 'w') { |f| f.puts "#{arg} 127.0.0.1/24" } + + expect { + Puppet::Network::Handler::FileServer.new(:Config => config_file) + }.should raise_error(Puppet::Network::Handler::FileServerError, "No mount specified for argument #{arg} 127.0.0.1/24") + end + end + end + it "should list a single directory" do @mount.list("/", false, false).should == [["/", "directory"]] end |
