diff options
| author | Luke Kanies <luke@madstop.com> | 2005-08-28 02:23:10 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-08-28 02:23:10 +0000 |
| commit | f2795359521709b5d4a64900ebed5e7b0be84c6b (patch) | |
| tree | 59aba403256c85c6d0de6170422f2c2066329aa8 /test | |
| parent | 28be88cc6e13c1af193fe01d56a1a446a18e01bb (diff) | |
| download | puppet-f2795359521709b5d4a64900ebed5e7b0be84c6b.tar.gz puppet-f2795359521709b5d4a64900ebed5e7b0be84c6b.tar.xz puppet-f2795359521709b5d4a64900ebed5e7b0be84c6b.zip | |
This should be the commit that brings us to Beta 1. All tests pass, although I get some (gracefully handled) failures in tc_metrics.rb, and there is now a config file for the fileserver module, including authorization specification for it. I have also reworked error handling in the xmlrpc client and server so errors should propagate more correctly.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@594 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/executables/tc_puppetd.rb | 8 | ||||
| -rwxr-xr-x | test/executables/tc_puppetmasterd.rb | 15 | ||||
| -rw-r--r-- | test/parser/tc_lexer.rb | 3 | ||||
| -rw-r--r-- | test/parser/tc_parser.rb | 2 | ||||
| -rwxr-xr-x | test/server/tc_authstore.rb | 35 | ||||
| -rwxr-xr-x | test/server/tc_fileserver.rb | 69 | ||||
| -rw-r--r-- | test/server/tc_server.rb | 4 | ||||
| -rwxr-xr-x | test/test | 3 | ||||
| -rwxr-xr-x | test/types/tc_filesources.rb | 40 |
9 files changed, 146 insertions, 33 deletions
diff --git a/test/executables/tc_puppetd.rb b/test/executables/tc_puppetd.rb index 264bc80ef..38e382392 100755 --- a/test/executables/tc_puppetd.rb +++ b/test/executables/tc_puppetd.rb @@ -47,7 +47,7 @@ class TestPuppetDExe < Test::Unit::TestCase assert_nothing_raised { output = %x{puppetmasterd --port #{Puppet[:masterport]} --manifest #{file}}.chomp } - assert($? == 0) + assert($? == 0, "Puppetmasterd return status was %s" % $?) @@tmppids << $?.pid assert_equal("", output) end @@ -62,7 +62,7 @@ class TestPuppetDExe < Test::Unit::TestCase pid = ary[1].to_i end } - assert(pid) + assert(pid, "No puppetmasterd pid") assert_nothing_raised { Process.kill("-INT", pid) @@ -75,8 +75,8 @@ class TestPuppetDExe < Test::Unit::TestCase assert_nothing_raised { output = %x{puppetd --server localhost}.chomp } - assert($? == 0) - assert_equal("", output) + assert($? == 0, "Puppetd exited with code %s" % $?) + assert_equal("", output, "Puppetd produced output %s" % output) assert_nothing_raised { socket = TCPSocket.new("127.0.0.1", Puppet[:masterport]) diff --git a/test/executables/tc_puppetmasterd.rb b/test/executables/tc_puppetmasterd.rb index 44aa03da4..ef89aa044 100755 --- a/test/executables/tc_puppetmasterd.rb +++ b/test/executables/tc_puppetmasterd.rb @@ -38,6 +38,7 @@ class TestPuppetMasterD < Test::Unit::TestCase Puppet[:loglevel] = :debug end @@tmpfiles = [] + @port = 8320 end def startmasterd(args) @@ -48,10 +49,10 @@ class TestPuppetMasterD < Test::Unit::TestCase # cmd += " --debug" #end assert_nothing_raised { - output = %x{puppetmasterd #{args}}.chomp + output = %x{puppetmasterd --port #{@port} #{args}}.chomp } - assert($? == 0) - assert_equal("", output) + assert($? == 0, "Puppetmasterd exit status was %s" % $?) + assert_equal("", output, "Puppetmasterd produced output %s" % output) end def stopmasterd(running = true) @@ -91,13 +92,13 @@ class TestPuppetMasterD < Test::Unit::TestCase startmasterd("--manifest #{file}") assert_nothing_raised { - socket = TCPSocket.new("127.0.0.1", Puppet[:masterport]) + socket = TCPSocket.new("127.0.0.1", @port) socket.close } client = nil assert_nothing_raised() { - client = XMLRPC::Client.new("localhost", "/RPC2", Puppet[:masterport], + client = XMLRPC::Client.new("localhost", "/RPC2", @port, nil, nil, nil, nil, true, 5) } retval = nil @@ -105,7 +106,7 @@ class TestPuppetMasterD < Test::Unit::TestCase assert_nothing_raised() { retval = client.call("status.status", "") } - assert_equal(1, retval) + assert_equal(1, retval, "Status.status return value was %s" % retval) facts = {} Facter.each { |p,v| facts[p] = v @@ -149,7 +150,7 @@ class TestPuppetMasterD < Test::Unit::TestCase assert_nothing_raised() { retval = client.nothing } - assert_equal(1, retval) + assert_equal(1, retval, "return value was %s" % retval) facts = {} Facter.each { |p,v| facts[p] = v diff --git a/test/parser/tc_lexer.rb b/test/parser/tc_lexer.rb index b8fd3e23b..d0ed19324 100644 --- a/test/parser/tc_lexer.rb +++ b/test/parser/tc_lexer.rb @@ -1,7 +1,6 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end diff --git a/test/parser/tc_parser.rb b/test/parser/tc_parser.rb index 8a05a5765..cb3cea0e9 100644 --- a/test/parser/tc_parser.rb +++ b/test/parser/tc_parser.rb @@ -71,7 +71,5 @@ class TestParser < Test::Unit::TestCase assert_nothing_raised { ret = parser.parse } - puts ret.class - p ret end end diff --git a/test/server/tc_authstore.rb b/test/server/tc_authstore.rb index 89d3c72e1..38c657770 100755 --- a/test/server/tc_authstore.rb +++ b/test/server/tc_authstore.rb @@ -154,7 +154,7 @@ class TestAuthStore < TestPuppet } end - def test_ziprangedenials + def test_iprangedenials store = mkstore assert_nothing_raised("Failed to store overlapping IP ranges") { @@ -166,7 +166,7 @@ class TestAuthStore < TestPuppet assert(! store.allowed?("fake.name", "192.168.0.50"), "/24 ip allowed") end - def test_zsubdomaindenails + def test_subdomaindenails store = mkstore assert_nothing_raised("Failed to store overlapping IP ranges") { @@ -179,6 +179,37 @@ class TestAuthStore < TestPuppet assert(! store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") end + + def test_orderingstuff + store = mkstore + + assert_nothing_raised("Failed to store overlapping IP ranges") { + store.allow("*.madstop.com") + store.deny("192.168.0.0/24") + } + + assert(store.allowed?("hostname.madstop.com", "192.168.1.50"), + "hostname not allowed") + assert(! store.allowed?("hostname.madstop.com", "192.168.0.50"), + "Host allowed over IP") + end + + def test_globalallow + store = mkstore + + assert_nothing_raised("Failed to add global allow") { + store.allow("*") + } + + [ + %w{hostname.com 192.168.0.4}, + %w{localhost 192.168.0.1}, + %w{localhost 127.0.0.1} + + ].each { |ary| + assert(store.allowed?(*ary), "Failed to allow %s" % [ary.join(",")]) + } + end end # $Id$ diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb index 7369ef5ab..29895a38e 100755 --- a/test/server/tc_fileserver.rb +++ b/test/server/tc_fileserver.rb @@ -418,7 +418,7 @@ class TestFileServer < TestPuppet Dir.mkdir(basedir) mounts = {} - %w{thing thus ahna the}.each { |dir| + %w{thing thus these those}.each { |dir| path = File.join(basedir, dir) conftext << "[#{dir}] path #{path} @@ -431,7 +431,24 @@ class TestFileServer < TestPuppet @@tmpfiles << conffile File.open(conffile, "w") { |f| - f.print conftext + f.print "# a test config file + +[thing] + path #{basedir}/thing + allow 192.168.0.* + +[thus] + path #{basedir}/thus + allow *.madstop.com, *.kanies.com + deny *.sub.madstop.com + +[these] + path #{basedir}/these + +[those] + path #{basedir}/those + +" } @@ -443,6 +460,7 @@ class TestFileServer < TestPuppet } list = nil + # run through once with no host/ip info, to verify everything is working mounts.each { |mount, files| mount = "/#{mount}/" assert_nothing_raised { @@ -465,6 +483,53 @@ class TestFileServer < TestPuppet assert_match(/^\d+/, desc, "Got invalid description %s" % f) } } + + # now let's check that things are being correctly forbidden + { + "thing" => { + :deny => [ + ["hostname.com", "192.168.1.0"], + ["hostname.com", "192.158.0.0"] + ], + :allow => [ + ["hostname.com", "192.168.0.0"], + ["hostname.com", "192.168.0.245"], + ] + }, + "thus" => { + :deny => [ + ["hostname.com", "192.168.1.0"], + ["name.sub.madstop.com", "192.158.0.0"] + ], + :allow => [ + ["luke.kanies.com", "192.168.0.0"], + ["luke.madstop.com", "192.168.0.245"], + ] + } + }.each { |mount, hash| + mount = "/#{mount}/" + + hash.each { |type, ary| + ary.each { |sub| + host, ip = sub + + case type + when :deny: + assert_raise(Puppet::Server::AuthorizationError, + "Host %s, ip %s, allowed %s" % + [host, ip, mount]) { + list = server.list(mount, true, host, ip) + } + when :allow: + assert_nothing_raised("Host %s, ip %s, denied %s" % + [host, ip, mount]) { + list = server.list(mount, true, host, ip) + } + end + } + } + } + end end diff --git a/test/server/tc_server.rb b/test/server/tc_server.rb index 50c5a6cec..1b7225748 100644 --- a/test/server/tc_server.rb +++ b/test/server/tc_server.rb @@ -132,7 +132,6 @@ class TestServer < Test::Unit::TestCase clthread = Thread.new { assert_nothing_raised() { - Puppet.notice "calling status" retval = client.call("status.status", "") } } @@ -186,7 +185,6 @@ class TestServer < Test::Unit::TestCase retval = nil assert_nothing_raised() { - Puppet.notice "calling status" retval = client.call("status.status") } @@ -244,7 +242,6 @@ class TestServer < Test::Unit::TestCase retval = nil assert_nothing_raised() { - Puppet.notice "calling status" retval = client.getconfig } @@ -257,7 +254,6 @@ class TestServer < Test::Unit::TestCase facts = CGI.escape(Marshal.dump(Puppet::Client::MasterClient.facts)) assert_nothing_raised() { - Puppet.notice "calling status" retval = client.call("puppetmaster.getconfig", facts) } @@ -49,3 +49,6 @@ end suites.each { |suite| PuppetTestSuite.new(suite) } + +# This damn problem just doesn't seem to want to go away +system("%s/etc/init.d/sleeper stop 2>/dev/null 1>/dev/null" % $puppetbase) diff --git a/test/types/tc_filesources.rb b/test/types/tc_filesources.rb index ba10eaacd..cb280a288 100755 --- a/test/types/tc_filesources.rb +++ b/test/types/tc_filesources.rb @@ -194,7 +194,6 @@ class TestFileSources < Test::Unit::TestCase if networked source = "puppet://localhost/%s%s" % [networked, fromdir] end - Puppet.warning "Source is %s" % source recursive_source_test(source, todir) return [fromdir,todir] @@ -310,9 +309,28 @@ class TestFileSources < Test::Unit::TestCase assert(klass[file3]) end - def test_SimpleNetworkSources + def mkfileserverconf(mounts) + file = "/tmp/fileserverconftestingfile%s" % rand(100) + File.open(file, "w") { |f| + mounts.each { |path, name| + f.puts "[#{name}]\n\tpath #{path}\n\tallow *\n" + } + } + + @@tmpfiles << file + return file + end + + def test_zSimpleNetworkSources server = nil basedir = "/tmp/simplnetworksourcetesting" + + mounts = { + "/" => "root" + } + + fileserverconf = mkfileserverconf(mounts) + if File.exists?(basedir) system("rm -rf %s" % basedir) end @@ -335,9 +353,7 @@ class TestFileSources < Test::Unit::TestCase :Handlers => { :CA => {}, # so that certs autogenerate :FileServer => { - :Mount => { - "/" => "root" - } + :Config => fileserverconf } } ) @@ -364,7 +380,7 @@ class TestFileSources < Test::Unit::TestCase list = nil rpath = "/root%s" % tmpfile assert_nothing_raised { - list = client.call("fileserver.list", rpath) + list = client.call("fileserver.list", rpath, false) } assert_equal("/\tfile", list) @@ -387,7 +403,7 @@ class TestFileSources < Test::Unit::TestCase } end - def test_NetworkSources + def test_zNetworkSources server = nil basedir = "/tmp/networksourcetesting" if File.exists?(basedir) @@ -395,6 +411,12 @@ class TestFileSources < Test::Unit::TestCase end Dir.mkdir(basedir) + mounts = { + "/" => "root" + } + + fileserverconf = mkfileserverconf(mounts) + Puppet[:puppetconf] = basedir Puppet[:puppetvar] = basedir Puppet[:autosign] = true @@ -408,9 +430,7 @@ class TestFileSources < Test::Unit::TestCase :Handlers => { :CA => {}, # so that certs autogenerate :FileServer => { - :Mount => { - "/" => "root" - } + :Config => fileserverconf } } ) |
