summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/puppet/server/fileserver.rb19
-rwxr-xr-xtest/server/tc_fileserver.rb64
2 files changed, 83 insertions, 0 deletions
diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb
index aa513d68c..f7a15e6b9 100755
--- a/lib/puppet/server/fileserver.rb
+++ b/lib/puppet/server/fileserver.rb
@@ -42,6 +42,7 @@ class Server
end
def describe(file, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(file)
unless @mounts[mount].allowed?(client, clientip)
@@ -97,7 +98,9 @@ class Server
@noreadconfig = false
end
+ @configtimeout = hash[:ConfigTimeout] || 60
@configstamp = nil
+ @congigstatted = nil
if hash.include?(:Mount)
@passedconfig = true
@@ -118,6 +121,7 @@ class Server
end
def list(dir, recurse = false, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(dir)
unless @mounts[mount].allowed?(client, clientip)
@@ -177,6 +181,17 @@ class Server
def readconfig
return if @noreadconfig
+ if @configstamp and FileTest.exists?(@config)
+ if @configtimeout and @configstatted and
+ (Time.now - @configstatted > @configtimeout)
+ tmp = File.stat(@config).ctime
+
+ if tmp == @configstamp
+ return
+ end
+ end
+ end
+
@mounts.clear
begin
@@ -245,9 +260,13 @@ class Server
rescue Errno::ENOENT => detail
raise Puppet::Error, "%s does not exit" % @config
end
+
+ @configstamp = File.stat(@config).ctime
+ @configstatted = Time.now
end
def retrieve(file, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(file)
unless (@mounts.include?(mount))
diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb
index 29895a38e..7c0ad9570 100755
--- a/test/server/tc_fileserver.rb
+++ b/test/server/tc_fileserver.rb
@@ -531,6 +531,70 @@ class TestFileServer < TestPuppet
}
end
+
+ def test_filereread
+ server = nil
+ testdir = "/tmp/filerereadtesting"
+
+ @@tmpfiles << testdir
+
+ #Dir.mkdir(testdir)
+ files = mktestfiles(testdir)
+
+ conffile = "/tmp/fileservertestingfile"
+ @@tmpfiles << conffile
+
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
+
+[thing]
+ path #{testdir}
+ allow test1.domain.com
+"
+ }
+
+
+ assert_nothing_raised {
+ server = Puppet::Server::FileServer.new(
+ :Local => true,
+ :ConfigTimeout => 0.5,
+ :Config => conffile
+ )
+ }
+
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/thing/", false, "test1.domain.com", "127.0.0.1")
+ }
+ assert(list != "", "List returned nothing in rereard test")
+
+ assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", false, "test2.domain.com", "127.0.0.1")
+ }
+
+ sleep 1
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
+
+[thing]
+ path #{testdir}
+ allow test2.domain.com
+"
+ }
+
+ assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", false, "test1.domain.com", "127.0.0.1")
+ }
+
+ assert_nothing_raised {
+ list = server.list("/thing/", false, "test2.domain.com", "127.0.0.1")
+ }
+
+ assert(list != "", "List returned nothing in rereard test")
+
+ list = nil
+ end
+
end
# $Id$