summaryrefslogtreecommitdiffstats
path: root/test/network
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /test/network
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'test/network')
-rwxr-xr-xtest/network/authconfig.rb94
-rwxr-xr-xtest/network/authorization.rb226
-rwxr-xr-xtest/network/authstore.rb890
-rwxr-xr-xtest/network/client/ca.rb92
-rwxr-xr-xtest/network/client/dipper.rb42
-rwxr-xr-xtest/network/client_request.rb40
-rwxr-xr-xtest/network/handler/ca.rb500
-rwxr-xr-xtest/network/handler/fileserver.rb1920
-rwxr-xr-xtest/network/handler/master.rb116
-rwxr-xr-xtest/network/handler/report.rb128
-rwxr-xr-xtest/network/handler/runner.rb16
-rwxr-xr-xtest/network/rights.rb40
-rwxr-xr-xtest/network/server/mongrel_test.rb174
-rwxr-xr-xtest/network/server/webrick.rb184
-rwxr-xr-xtest/network/xmlrpc/client.rb60
-rwxr-xr-xtest/network/xmlrpc/processor.rb104
-rwxr-xr-xtest/network/xmlrpc/server.rb20
-rwxr-xr-xtest/network/xmlrpc/webrick_servlet.rb36
18 files changed, 2341 insertions, 2341 deletions
diff --git a/test/network/authconfig.rb b/test/network/authconfig.rb
index 18445bc8e..f53238d0b 100755
--- a/test/network/authconfig.rb
+++ b/test/network/authconfig.rb
@@ -7,63 +7,63 @@ require 'puppettest'
require 'puppet/network/authconfig'
class TestAuthConfig < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def request(call, client, ip)
- r = Puppet::Network::ClientRequest.new(client, ip, false)
- h, m = call.split(".")
- r.handler = h
- r.method = m
- r
- end
+ def request(call, client, ip)
+ r = Puppet::Network::ClientRequest.new(client, ip, false)
+ h, m = call.split(".")
+ r.handler = h
+ r.method = m
+ r
+ end
- def test_parsingconfigfile
- file = tempfile
- assert(Puppet[:authconfig], "No config path")
+ def test_parsingconfigfile
+ file = tempfile
+ assert(Puppet[:authconfig], "No config path")
- Puppet[:authconfig] = file
+ Puppet[:authconfig] = file
- File.open(file, "w") { |f|
- f.puts "[pelementserver.describe]
- allow *.madstop.com
- deny 10.10.1.1
+ File.open(file, "w") { |f|
+ f.puts "[pelementserver.describe]
+ allow *.madstop.com
+ deny 10.10.1.1
[fileserver]
- allow *.madstop.com
- deny 10.10.1.1
+ allow *.madstop.com
+ deny 10.10.1.1
[fileserver.list]
- allow 10.10.1.1
+ allow 10.10.1.1
"
- }
-
- config = nil
- assert_nothing_raised {
- config = Puppet::Network::AuthConfig.new(file)
- }
-
- assert_nothing_raised {
- assert(config.allowed?(request("pelementserver.describe", "culain.madstop.com", "1.1.1.1")), "Did not allow host")
- assert(! config.allowed?(request("pelementserver.describe", "culain.madstop.com", "10.10.1.1")), "Allowed host")
- assert(config.allowed?(request("fileserver.yay", "culain.madstop.com", "10.1.1.1")), "Did not allow host to fs")
- assert(! config.allowed?(request("fileserver.yay", "culain.madstop.com", "10.10.1.1")), "Allowed host to fs")
- assert(config.allowed?(request("fileserver.list", "culain.madstop.com", "10.10.1.1")), "Did not allow host to fs.list")
- }
- end
-
- def test_singleton
- auth = nil
- assert_nothing_raised { auth = Puppet::Network::AuthConfig.main }
- assert(auth, "did not get main authconfig")
-
- other = nil
- assert_nothing_raised { other = Puppet::Network::AuthConfig.main }
-
- assert_equal(
- auth.object_id, other.object_id,
+ }
+
+ config = nil
+ assert_nothing_raised {
+ config = Puppet::Network::AuthConfig.new(file)
+ }
+
+ assert_nothing_raised {
+ assert(config.allowed?(request("pelementserver.describe", "culain.madstop.com", "1.1.1.1")), "Did not allow host")
+ assert(! config.allowed?(request("pelementserver.describe", "culain.madstop.com", "10.10.1.1")), "Allowed host")
+ assert(config.allowed?(request("fileserver.yay", "culain.madstop.com", "10.1.1.1")), "Did not allow host to fs")
+ assert(! config.allowed?(request("fileserver.yay", "culain.madstop.com", "10.10.1.1")), "Allowed host to fs")
+ assert(config.allowed?(request("fileserver.list", "culain.madstop.com", "10.10.1.1")), "Did not allow host to fs.list")
+ }
+ end
+
+ def test_singleton
+ auth = nil
+ assert_nothing_raised { auth = Puppet::Network::AuthConfig.main }
+ assert(auth, "did not get main authconfig")
+
+ other = nil
+ assert_nothing_raised { other = Puppet::Network::AuthConfig.main }
+
+ assert_equal(
+ auth.object_id, other.object_id,
- "did not get same authconfig from class")
- end
+ "did not get same authconfig from class")
+ end
end
diff --git a/test/network/authorization.rb b/test/network/authorization.rb
index cecc1fd8d..f29fe2554 100755
--- a/test/network/authorization.rb
+++ b/test/network/authorization.rb
@@ -7,132 +7,132 @@ require 'puppet/network/authorization'
require 'mocha'
class TestAuthConfig < Test::Unit::TestCase
- include PuppetTest
-
- # A mock class for authconfig
- class FakeAuth
- class << self
- attr_accessor :allow, :exists
- end
- def allowed?(req)
- self.class.allow
- end
- def exists?
- self.class.exists
- end
- end
-
- class AuthTest
- include Puppet::Network::Authorization
-
- def clear
- @loaded.clear
- end
-
- def load(name)
- @loaded ||= []
- @loaded << name
- end
+ include PuppetTest
- def handler_loaded?(name)
- @loaded ||= []
- @loaded.include?(name)
- end
+ # A mock class for authconfig
+ class FakeAuth
+ class << self
+ attr_accessor :allow, :exists
end
-
- def setup
- super
- @obj = AuthTest.new
-
- # Override the authconfig to make life easier
- class << @obj
- def authconfig
- @authconfig ||= FakeAuth.new
- end
- end
- @request = Puppet::Network::ClientRequest.new("host", "ip", false)
- @request.handler = "foo"
- @request.method = "bar"
+ def allowed?(req)
+ self.class.allow
end
-
- def test_authconfig
- obj = AuthTest.new
- auth = nil
- assert_nothing_raised { auth = obj.send(:authconfig) }
- assert(auth, "did not get auth")
- assert_equal(Puppet::Network::AuthConfig.main.object_id, auth.object_id, "did not get main authconfig")
+ def exists?
+ self.class.exists
end
+ end
- def test_authorize
- # Make sure that unauthenticated clients can do puppetca stuff, but
- # nothing else.
- @request.handler = "puppetca"
- @request.method = "yay"
- assert(@obj.authorized?(@request), "Did not allow unauthenticated ca call")
- assert_logged(:notice, /Allowing/, "did not log call")
- @request.handler = "other"
- assert(! @obj.authorized?(@request), "Allowed unauthencated other call")
- assert_logged(:notice, /Denying/, "did not log call")
-
- @request.authenticated = true
- # We start without the namespace auth file, so everything should
- # start out denied
- assert(! @obj.authorized?(@request), "Allowed call with no config file")
- assert_logged(:notice, /Denying/, "did not log call")
-
- # Now set our run_mode to master, so calls are allowed
- Puppet.run_mode.stubs(:master?).returns true
-
- assert(
- @obj.authorized?(@request),
-
- "Denied call with no config file and master")
- assert_logged(:debug, /Allowing/, "did not log call")
+ class AuthTest
+ include Puppet::Network::Authorization
- # Now "create" the file, so we do real tests
- FakeAuth.exists = true
+ def clear
+ @loaded.clear
+ end
- # We start out denying
- assert(! @obj.authorized?(@request), "Allowed call when denying")
- assert_logged(:notice, /Denying/, "did not log call")
+ def load(name)
+ @loaded ||= []
+ @loaded << name
+ end
- FakeAuth.allow = true
- assert(@obj.authorized?(@request), "Denied call when allowing")
- assert_logged(:debug, /Allowing/, "did not log call")
+ def handler_loaded?(name)
+ @loaded ||= []
+ @loaded.include?(name)
end
+ end
- def test_available?
- # Start out false
- assert(! @obj.available?(@request), "Defaulted to true")
- assert_logged(:warning, /requested unavailable/, "did not log call")
+ def setup
+ super
+ @obj = AuthTest.new
- @obj.load(@request.handler)
- assert(@obj.available?(@request), "did not see it loaded")
+ # Override the authconfig to make life easier
+ class << @obj
+ def authconfig
+ @authconfig ||= FakeAuth.new
+ end
end
-
- # Make sure we raise things appropriately
- def test_verify
- # Start out unavailabl
- assert_raise(Puppet::Network::InvalidClientRequest) do
- @obj.verify(@request)
- end
- class << @obj
- def available?(req)
- true
- end
- end
- assert_raise(Puppet::Network::InvalidClientRequest) do
- @obj.verify(@request)
- end
- class << @obj
- def authorized?(req)
- true
- end
- end
- assert_nothing_raised do
- @obj.verify(@request)
- end
+ @request = Puppet::Network::ClientRequest.new("host", "ip", false)
+ @request.handler = "foo"
+ @request.method = "bar"
+ end
+
+ def test_authconfig
+ obj = AuthTest.new
+ auth = nil
+ assert_nothing_raised { auth = obj.send(:authconfig) }
+ assert(auth, "did not get auth")
+ assert_equal(Puppet::Network::AuthConfig.main.object_id, auth.object_id, "did not get main authconfig")
+ end
+
+ def test_authorize
+ # Make sure that unauthenticated clients can do puppetca stuff, but
+ # nothing else.
+ @request.handler = "puppetca"
+ @request.method = "yay"
+ assert(@obj.authorized?(@request), "Did not allow unauthenticated ca call")
+ assert_logged(:notice, /Allowing/, "did not log call")
+ @request.handler = "other"
+ assert(! @obj.authorized?(@request), "Allowed unauthencated other call")
+ assert_logged(:notice, /Denying/, "did not log call")
+
+ @request.authenticated = true
+ # We start without the namespace auth file, so everything should
+ # start out denied
+ assert(! @obj.authorized?(@request), "Allowed call with no config file")
+ assert_logged(:notice, /Denying/, "did not log call")
+
+ # Now set our run_mode to master, so calls are allowed
+ Puppet.run_mode.stubs(:master?).returns true
+
+ assert(
+ @obj.authorized?(@request),
+
+ "Denied call with no config file and master")
+ assert_logged(:debug, /Allowing/, "did not log call")
+
+ # Now "create" the file, so we do real tests
+ FakeAuth.exists = true
+
+ # We start out denying
+ assert(! @obj.authorized?(@request), "Allowed call when denying")
+ assert_logged(:notice, /Denying/, "did not log call")
+
+ FakeAuth.allow = true
+ assert(@obj.authorized?(@request), "Denied call when allowing")
+ assert_logged(:debug, /Allowing/, "did not log call")
+ end
+
+ def test_available?
+ # Start out false
+ assert(! @obj.available?(@request), "Defaulted to true")
+ assert_logged(:warning, /requested unavailable/, "did not log call")
+
+ @obj.load(@request.handler)
+ assert(@obj.available?(@request), "did not see it loaded")
+ end
+
+ # Make sure we raise things appropriately
+ def test_verify
+ # Start out unavailabl
+ assert_raise(Puppet::Network::InvalidClientRequest) do
+ @obj.verify(@request)
+ end
+ class << @obj
+ def available?(req)
+ true
+ end
+ end
+ assert_raise(Puppet::Network::InvalidClientRequest) do
+ @obj.verify(@request)
+ end
+ class << @obj
+ def authorized?(req)
+ true
+ end
+ end
+ assert_nothing_raised do
+ @obj.verify(@request)
end
+ end
end
diff --git a/test/network/authstore.rb b/test/network/authstore.rb
index 9837a4686..e608423bf 100755
--- a/test/network/authstore.rb
+++ b/test/network/authstore.rb
@@ -7,534 +7,534 @@ require 'mocha'
require 'puppet/network/authstore'
class TestAuthStore < Test::Unit::TestCase
- include PuppetTest
- Declaration = Puppet::Network::AuthStore::Declaration
- def mkstore
- store = nil
- assert_nothing_raised {
- store = Puppet::Network::AuthStore.new
- }
-
- store
+ include PuppetTest
+ Declaration = Puppet::Network::AuthStore::Declaration
+ def mkstore
+ store = nil
+ assert_nothing_raised {
+ store = Puppet::Network::AuthStore.new
+ }
+
+ store
+ end
+
+ def setup
+ super
+ @store = mkstore
+ end
+
+ def test_localallow
+ Puppet[:trace] = false
+ assert_nothing_raised {
+ assert(@store.allowed?(nil, nil), "Store disallowed local access")
+ }
+
+ assert_raise(Puppet::DevError) {
+ @store.allowed?("kirby.madstop.com", nil)
+ }
+
+ assert_raise(Puppet::DevError) {
+ @store.allowed?(nil, "192.168.0.1")
+ }
+ end
+
+ def test_simpleips
+ %w{
+ 192.168.0.5
+ 7.0.48.7
+ }.each { |ip|
+ assert_nothing_raised("Failed to @store IP address #{ip}") {
+ @store.allow(ip)
+ }
+
+ assert(@store.allowed?("hosttest.com", ip), "IP #{ip} not allowed")
+ }
+
+ #assert_raise(Puppet::AuthStoreError) {
+ # @store.allow("192.168.674.0")
+ #}
+ end
+
+ def test_ipranges
+ %w{
+ 192.168.0.*
+ 192.168.1.0/24
+ 192.178.*
+ 193.179.0.0/8
+ }.each { |range|
+ assert_nothing_raised("Failed to @store IP range #{range}") {
+ @store.allow(range)
+ }
+ }
+
+ %w{
+ 192.168.0.1
+ 192.168.1.5
+ 192.178.0.5
+ 193.0.0.1
+ }.each { |ip|
+ assert(@store.allowed?("fakename.com", ip), "IP #{ip} is not allowed")
+ }
+ end
+
+ def test_iprangedenials
+ assert_nothing_raised("Failed to @store overlapping IP ranges") {
+ @store.allow("192.168.0.0/16")
+ @store.deny("192.168.0.0/24")
+ }
+
+ assert(@store.allowed?("fake.name", "192.168.1.50"), "/16 ip not allowed")
+ assert(! @store.allowed?("fake.name", "192.168.0.50"), "/24 ip allowed")
+ end
+
+ def test_subdomaindenails
+ assert_nothing_raised("Failed to @store overlapping IP ranges") {
+ @store.allow("*.madstop.com")
+ @store.deny("*.sub.madstop.com")
+ }
+
+
+ assert(
+ @store.allowed?("hostname.madstop.com", "192.168.1.50"),
+
+ "hostname not allowed")
+
+ assert(
+ ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
+
+ "subname name allowed")
+ end
+
+ def test_orderingstuff
+ 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
+ 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 #{ary.join(",")}")
+ }
+ end
+
+ def test_store
+ assert_nothing_raised do
+
+ assert_nil(
+ @store.send(:store, :allow, "*.host.com"),
+
+ "store did not return nil")
end
+ assert_equal([Declaration.new(:allow, "*.host.com")],
+ @store.send(:instance_variable_get, "@declarations"),
+ "Did not store declaration")
- def setup
- super
- @store = mkstore
- end
-
- def test_localallow
- Puppet[:trace] = false
- assert_nothing_raised {
- assert(@store.allowed?(nil, nil), "Store disallowed local access")
- }
-
- assert_raise(Puppet::DevError) {
- @store.allowed?("kirby.madstop.com", nil)
- }
-
- assert_raise(Puppet::DevError) {
- @store.allowed?(nil, "192.168.0.1")
- }
- end
-
- def test_simpleips
- %w{
- 192.168.0.5
- 7.0.48.7
- }.each { |ip|
- assert_nothing_raised("Failed to @store IP address #{ip}") {
- @store.allow(ip)
- }
-
- assert(@store.allowed?("hosttest.com", ip), "IP #{ip} not allowed")
- }
-
- #assert_raise(Puppet::AuthStoreError) {
- # @store.allow("192.168.674.0")
- #}
- end
+ # Now add another one and make sure it gets sorted appropriately
+ assert_nothing_raised do
- def test_ipranges
- %w{
- 192.168.0.*
- 192.168.1.0/24
- 192.178.*
- 193.179.0.0/8
- }.each { |range|
- assert_nothing_raised("Failed to @store IP range #{range}") {
- @store.allow(range)
- }
- }
-
- %w{
- 192.168.0.1
- 192.168.1.5
- 192.178.0.5
- 193.0.0.1
- }.each { |ip|
- assert(@store.allowed?("fakename.com", ip), "IP #{ip} is not allowed")
- }
- end
-
- def test_iprangedenials
- assert_nothing_raised("Failed to @store overlapping IP ranges") {
- @store.allow("192.168.0.0/16")
- @store.deny("192.168.0.0/24")
- }
+ assert_nil(
+ @store.send(:store, :allow, "me.host.com"),
- assert(@store.allowed?("fake.name", "192.168.1.50"), "/16 ip not allowed")
- assert(! @store.allowed?("fake.name", "192.168.0.50"), "/24 ip allowed")
+ "store did not return nil")
end
- def test_subdomaindenails
- assert_nothing_raised("Failed to @store overlapping IP ranges") {
- @store.allow("*.madstop.com")
- @store.deny("*.sub.madstop.com")
- }
-
-
- assert(
- @store.allowed?("hostname.madstop.com", "192.168.1.50"),
-
- "hostname not allowed")
-
- assert(
- ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
-
- "subname name allowed")
- end
-
- def test_orderingstuff
- 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
- assert_nothing_raised("Failed to add global allow") {
- @store.allow("*")
- }
+ assert_equal(
[
- %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 #{ary.join(",")}")
- }
- end
-
- def test_store
- assert_nothing_raised do
-
- assert_nil(
- @store.send(:store, :allow, "*.host.com"),
+ Declaration.new(:allow, "me.host.com"),
- "store did not return nil")
- end
- assert_equal([Declaration.new(:allow, "*.host.com")],
- @store.send(:instance_variable_get, "@declarations"),
- "Did not store declaration")
+ Declaration.new(:allow, "*.host.com")
+ ],
+ @store.send(:instance_variable_get, "@declarations"),
+ "Did not sort declarations")
+ end
- # Now add another one and make sure it gets sorted appropriately
- assert_nothing_raised do
+ def test_allow_and_deny
+ store = Puppet::Network::AuthStore.new
+ store.expects(:store).with(:allow, "host.com")
+ store.allow("host.com")
- assert_nil(
- @store.send(:store, :allow, "me.host.com"),
+ store = Puppet::Network::AuthStore.new
+ store.expects(:store).with(:deny, "host.com")
+ store.deny("host.com")
- "store did not return nil")
- end
+ store = Puppet::Network::AuthStore.new
+ assert_nothing_raised do
+ assert_nil(
+ store.allow("*"),
- assert_equal(
- [
- Declaration.new(:allow, "me.host.com"),
-
- Declaration.new(:allow, "*.host.com")
- ],
- @store.send(:instance_variable_get, "@declarations"),
- "Did not sort declarations")
+ "allow did not return nil")
end
- def test_allow_and_deny
- store = Puppet::Network::AuthStore.new
- store.expects(:store).with(:allow, "host.com")
- store.allow("host.com")
-
- store = Puppet::Network::AuthStore.new
- store.expects(:store).with(:deny, "host.com")
- store.deny("host.com")
-
- store = Puppet::Network::AuthStore.new
- assert_nothing_raised do
-
- assert_nil(
- store.allow("*"),
-
- "allow did not return nil")
- end
+ assert(
+ store.globalallow?,
+
+ "did not enable global allow")
+ end
+
+ def test_hostnames
+ Puppet[:trace] = false
+ %w{
+ kirby.madstop.com
+ luke.madstop.net
+ name-other.madstop.net
+ }.each { |name|
+ assert_nothing_raised("Failed to @store simple name #{name}") {
+ @store.allow(name)
+ }
+ assert(@store.allowed?(name, "192.168.0.1"), "Name #{name} not allowed")
+ }
+
+ %w{
+ ^invalid!
+ inval$id
+
+ }.each { |pat|
+
+ assert_raise(
+ Puppet::AuthStoreError,
+
+ "name '#{pat}' was allowed") {
+ @store.allow(pat)
+ }
+ }
+ end
+
+ def test_domains
+ assert_nothing_raised("Failed to @store domains") {
+ @store.allow("*.a.very.long.domain.name.com")
+ @store.allow("*.madstop.com")
+ @store.allow("*.some-other.net")
+ @store.allow("*.much.longer.more-other.net")
+ }
+
+ %w{
+ madstop.com
+ culain.madstop.com
+ kirby.madstop.com
+ funtest.some-other.net
+ ya-test.madstop.com
+ some.much.much.longer.more-other.net
+ }.each { |name|
+ assert(@store.allowed?(name, "192.168.0.1"), "Host #{name} not allowed")
+ }
+
+ assert_raise(Puppet::AuthStoreError) {
+ @store.allow("domain.*.com")
+ }
+
+
+ assert(
+ !@store.allowed?("very.long.domain.name.com", "1.2.3.4"),
+
+ "Long hostname allowed")
+
+ assert_raise(Puppet::AuthStoreError) {
+ @store.allow("domain.*.other.com")
+ }
+ end
+
+ # #531
+ def test_case_insensitivity
+ @store.allow("hostname.com")
+
+ %w{hostname.com Hostname.COM hostname.Com HOSTNAME.COM}.each do |name|
+ assert(@store.allowed?(name, "127.0.0.1"), "did not allow #{name}")
+ end
+ end
- assert(
- store.globalallow?,
+ def test_allowed?
+ Puppet[:trace] = false
- "did not enable global allow")
- end
+ assert(
+ @store.allowed?(nil, nil),
- def test_hostnames
- Puppet[:trace] = false
- %w{
- kirby.madstop.com
- luke.madstop.net
- name-other.madstop.net
- }.each { |name|
- assert_nothing_raised("Failed to @store simple name #{name}") {
- @store.allow(name)
- }
- assert(@store.allowed?(name, "192.168.0.1"), "Name #{name} not allowed")
- }
-
- %w{
- ^invalid!
- inval$id
-
- }.each { |pat|
-
- assert_raise(
- Puppet::AuthStoreError,
-
- "name '#{pat}' was allowed") {
- @store.allow(pat)
- }
- }
+ "Did not default to true for local checks")
+ assert_raise(Puppet::DevError, "did not fail on one input") do
+ @store.allowed?("host.com", nil)
end
-
- def test_domains
- assert_nothing_raised("Failed to @store domains") {
- @store.allow("*.a.very.long.domain.name.com")
- @store.allow("*.madstop.com")
- @store.allow("*.some-other.net")
- @store.allow("*.much.longer.more-other.net")
- }
-
- %w{
- madstop.com
- culain.madstop.com
- kirby.madstop.com
- funtest.some-other.net
- ya-test.madstop.com
- some.much.much.longer.more-other.net
- }.each { |name|
- assert(@store.allowed?(name, "192.168.0.1"), "Host #{name} not allowed")
- }
-
- assert_raise(Puppet::AuthStoreError) {
- @store.allow("domain.*.com")
- }
-
-
- assert(
- !@store.allowed?("very.long.domain.name.com", "1.2.3.4"),
-
- "Long hostname allowed")
-
- assert_raise(Puppet::AuthStoreError) {
- @store.allow("domain.*.other.com")
- }
+ assert_raise(Puppet::DevError, "did not fail on one input") do
+ @store.allowed?(nil, "192.168.0.1")
end
- # #531
- def test_case_insensitivity
- @store.allow("hostname.com")
+ end
- %w{hostname.com Hostname.COM hostname.Com HOSTNAME.COM}.each do |name|
- assert(@store.allowed?(name, "127.0.0.1"), "did not allow #{name}")
- end
- end
+ # Make sure more specific allows and denies win over generalities
+ def test_specific_overrides
+ @store.allow("host.madstop.com")
+ @store.deny("*.madstop.com")
- def test_allowed?
- Puppet[:trace] = false
- assert(
- @store.allowed?(nil, nil),
+ assert(
+ @store.allowed?("host.madstop.com", "192.168.0.1"),
- "Did not default to true for local checks")
- assert_raise(Puppet::DevError, "did not fail on one input") do
- @store.allowed?("host.com", nil)
- end
- assert_raise(Puppet::DevError, "did not fail on one input") do
- @store.allowed?(nil, "192.168.0.1")
- end
+ "More specific allowal by name failed")
- end
+ @store.allow("192.168.0.1")
+ @store.deny("192.168.0.0/24")
- # Make sure more specific allows and denies win over generalities
- def test_specific_overrides
- @store.allow("host.madstop.com")
- @store.deny("*.madstop.com")
+ assert(
+ @store.allowed?("host.madstop.com", "192.168.0.1"),
- assert(
- @store.allowed?("host.madstop.com", "192.168.0.1"),
+ "More specific allowal by ip failed")
+ end
- "More specific allowal by name failed")
+ def test_dynamic_backreferences
+ @store.allow("$1.madstop.com")
- @store.allow("192.168.0.1")
- @store.deny("192.168.0.0/24")
+ assert_nothing_raised { @store.interpolate([nil, "host"]) }
+ assert(@store.allowed?("host.madstop.com", "192.168.0.1"), "interpolation failed")
+ assert_nothing_raised { @store.reset_interpolation }
+ end
+ def test_dynamic_ip
+ @store.allow("192.168.0.$1")
- assert(
- @store.allowed?("host.madstop.com", "192.168.0.1"),
+ assert_nothing_raised { @store.interpolate([nil, "12"]) }
+ assert(@store.allowed?("host.madstop.com", "192.168.0.12"), "interpolation failed")
+ assert_nothing_raised { @store.reset_interpolation }
+ end
- "More specific allowal by ip failed")
- end
+ def test_multiple_dynamic_backreferences
+ @store.allow("$1.$2")
- def test_dynamic_backreferences
- @store.allow("$1.madstop.com")
+ assert_nothing_raised { @store.interpolate([nil, "host", "madstop.com"]) }
+ assert(@store.allowed?("host.madstop.com", "192.168.0.1"), "interpolation failed")
+ assert_nothing_raised { @store.reset_interpolation }
+ end
- assert_nothing_raised { @store.interpolate([nil, "host"]) }
- assert(@store.allowed?("host.madstop.com", "192.168.0.1"), "interpolation failed")
- assert_nothing_raised { @store.reset_interpolation }
- end
-
- def test_dynamic_ip
- @store.allow("192.168.0.$1")
+ def test_multithreaded_allow_with_dynamic_backreferences
+ @store.allow("$1.madstop.com")
- assert_nothing_raised { @store.interpolate([nil, "12"]) }
- assert(@store.allowed?("host.madstop.com", "192.168.0.12"), "interpolation failed")
- assert_nothing_raised { @store.reset_interpolation }
- end
-
- def test_multiple_dynamic_backreferences
- @store.allow("$1.$2")
-
- assert_nothing_raised { @store.interpolate([nil, "host", "madstop.com"]) }
- assert(@store.allowed?("host.madstop.com", "192.168.0.1"), "interpolation failed")
- assert_nothing_raised { @store.reset_interpolation }
- end
-
- def test_multithreaded_allow_with_dynamic_backreferences
- @store.allow("$1.madstop.com")
-
- threads = []
- 9.times { |a|
- threads << Thread.new {
- 9.times { |b|
- Thread.pass
- @store.interpolate([nil, "a#{b}", "madstop.com"])
- Thread.pass
- assert( @store.allowed?("a#{b}.madstop.com", "192.168.0.1") )
- Thread.pass
- @store.reset_interpolation
- Thread.pass
- }
- }
- }
- threads.each { |th| th.join }
- end
+ threads = []
+ 9.times { |a|
+ threads << Thread.new {
+ 9.times { |b|
+ Thread.pass
+ @store.interpolate([nil, "a#{b}", "madstop.com"])
+ Thread.pass
+ assert( @store.allowed?("a#{b}.madstop.com", "192.168.0.1") )
+ Thread.pass
+ @store.reset_interpolation
+ Thread.pass
+ }
+ }
+ }
+ threads.each { |th| th.join }
+ end
end
class TestAuthStoreDeclaration < PuppetTest::TestCase
- include PuppetTest
- Declaration = Puppet::Network::AuthStore::Declaration
-
- def setup
- super
- @decl = Declaration.new(:allow, "hostname.com")
+ include PuppetTest
+ Declaration = Puppet::Network::AuthStore::Declaration
+
+ def setup
+ super
+ @decl = Declaration.new(:allow, "hostname.com")
+ end
+
+ def test_parse
+ {
+ "192.168.0.1" => [:ip, IPAddr.new("192.168.0.1"), nil],
+ "2001:700:300:1800::" => [:ip, IPAddr.new("2001:700:300:1800::"), nil],
+ "2001:700:300:1800::/64" => [:ip, IPAddr.new("2001:700:300:1800::/64"), 64],
+ "192.168.0.1/32" => [:ip, IPAddr.new("192.168.0.1/32"), 32],
+ "192.168.0.1/24" => [:ip, IPAddr.new("192.168.0.1/24"), 24],
+ "192.*" => [:ip, IPAddr.new("192.0.0.0/8"), 8],
+ "192.168.*" => [:ip, IPAddr.new("192.168.0.0/16"), 16],
+ "192.168.0.*" => [:ip, IPAddr.new("192.168.0.0/24"), 24],
+ "hostname.com" => [:domain, %w{com hostname}, nil],
+ "Hostname.COM" => [:domain, %w{com hostname}, nil],
+ "billy.Hostname.COM" => [:domain, %w{com hostname billy}, nil],
+ "billy-jean.Hostname.COM" => [:domain, %w{com hostname billy-jean}, nil],
+ "*.hostname.COM" => [:domain, %w{com hostname}, 2],
+ "*.hostname.COM" => [:domain, %w{com hostname}, 2],
+ "$1.hostname.COM" => [:dynamic, %w{com hostname $1}, nil],
+ "192.168.$1.$2" => [:dynamic, %w{$2 $1 168 192}, nil],
+ "8A5BC90C-B8FD-4CBC-81DA-BAD84D551791" => [:opaque, %w{8A5BC90C-B8FD-4CBC-81DA-BAD84D551791}, nil]
+ }.each do |input, output|
+
+ # Create a new decl each time, so values aren't cached.
+ assert_nothing_raised do
+ @decl = Declaration.new(:allow, input)
+ end
+
+ [:name, :pattern, :length].zip(output).each do |method, value|
+ assert_equal(value, @decl.send(method), "Got incorrect value for #{method} from #{input}")
+ end
end
- def test_parse
- {
- "192.168.0.1" => [:ip, IPAddr.new("192.168.0.1"), nil],
- "2001:700:300:1800::" => [:ip, IPAddr.new("2001:700:300:1800::"), nil],
- "2001:700:300:1800::/64" => [:ip, IPAddr.new("2001:700:300:1800::/64"), 64],
- "192.168.0.1/32" => [:ip, IPAddr.new("192.168.0.1/32"), 32],
- "192.168.0.1/24" => [:ip, IPAddr.new("192.168.0.1/24"), 24],
- "192.*" => [:ip, IPAddr.new("192.0.0.0/8"), 8],
- "192.168.*" => [:ip, IPAddr.new("192.168.0.0/16"), 16],
- "192.168.0.*" => [:ip, IPAddr.new("192.168.0.0/24"), 24],
- "hostname.com" => [:domain, %w{com hostname}, nil],
- "Hostname.COM" => [:domain, %w{com hostname}, nil],
- "billy.Hostname.COM" => [:domain, %w{com hostname billy}, nil],
- "billy-jean.Hostname.COM" => [:domain, %w{com hostname billy-jean}, nil],
- "*.hostname.COM" => [:domain, %w{com hostname}, 2],
- "*.hostname.COM" => [:domain, %w{com hostname}, 2],
- "$1.hostname.COM" => [:dynamic, %w{com hostname $1}, nil],
- "192.168.$1.$2" => [:dynamic, %w{$2 $1 168 192}, nil],
- "8A5BC90C-B8FD-4CBC-81DA-BAD84D551791" => [:opaque, %w{8A5BC90C-B8FD-4CBC-81DA-BAD84D551791}, nil]
- }.each do |input, output|
-
- # Create a new decl each time, so values aren't cached.
- assert_nothing_raised do
- @decl = Declaration.new(:allow, input)
- end
-
- [:name, :pattern, :length].zip(output).each do |method, value|
- assert_equal(value, @decl.send(method), "Got incorrect value for #{method} from #{input}")
- end
- end
-
- %w{-hostname.com hostname.*}.each do |input|
- assert_raise(Puppet::AuthStoreError, "Did not fail on #{input}") do
- @decl.pattern = input
- end
- end
-
- ["hostname .com", "192.168 .0.1"].each do |input|
- assert_raise(Puppet::AuthStoreError, "Did not fail on #{input}") do
- @decl.pattern = input
- end
- end
+ %w{-hostname.com hostname.*}.each do |input|
+ assert_raise(Puppet::AuthStoreError, "Did not fail on #{input}") do
+ @decl.pattern = input
+ end
end
- def test_result
- ["allow", :allow].each do |val|
- assert_nothing_raised { @decl.type = val }
- assert_equal(true, @decl.result, "did not result to true with #{val.inspect}")
- end
+ ["hostname .com", "192.168 .0.1"].each do |input|
+ assert_raise(Puppet::AuthStoreError, "Did not fail on #{input}") do
+ @decl.pattern = input
+ end
+ end
+ end
- [:deny, "deny"].each do |val|
- assert_nothing_raised { @decl.type = val }
+ def test_result
+ ["allow", :allow].each do |val|
+ assert_nothing_raised { @decl.type = val }
+ assert_equal(true, @decl.result, "did not result to true with #{val.inspect}")
+ end
- assert_equal(
- false, @decl.result,
+ [:deny, "deny"].each do |val|
+ assert_nothing_raised { @decl.type = val }
- "did not result to false with #{val.inspect}")
- end
+ assert_equal(
+ false, @decl.result,
- ["yay", 1, nil, false, true].each do |val|
- assert_raise(ArgumentError, "Did not fail on #{val.inspect}") do
- @decl.type = val
- end
- end
+ "did not result to false with #{val.inspect}")
end
- def test_munge_name
- {
- "hostname.com" => %w{com hostname},
- "alley.hostname.com" => %w{com hostname alley},
- "*.hostname.com" => %w{com hostname *},
- "*.HOSTNAME.Com" => %w{com hostname *},
- "*.HOSTNAME.Com" => %w{com hostname *},
-
- }.each do |input, output|
- assert_equal(output, @decl.send(:munge_name, input), "munged #{input} incorrectly")
- end
+ ["yay", 1, nil, false, true].each do |val|
+ assert_raise(ArgumentError, "Did not fail on #{val.inspect}") do
+ @decl.type = val
+ end
end
-
- # Make sure people can specify TLDs
- def test_match_tlds
- assert_nothing_raised {
- @decl.pattern = "*.tld"
- }
-
- assert_equal(%w{tld}, @decl.pattern, "Failed to allow custom tld")
+ end
+
+ def test_munge_name
+ {
+ "hostname.com" => %w{com hostname},
+ "alley.hostname.com" => %w{com hostname alley},
+ "*.hostname.com" => %w{com hostname *},
+ "*.HOSTNAME.Com" => %w{com hostname *},
+ "*.HOSTNAME.Com" => %w{com hostname *},
+
+ }.each do |input, output|
+ assert_equal(output, @decl.send(:munge_name, input), "munged #{input} incorrectly")
end
+ end
- # Make sure we sort correctly.
- def test_sorting
- # Make sure declarations with no length sort first.
- host_exact = Declaration.new(:allow, "host.com")
- host_range = Declaration.new(:allow, "*.host.com")
+ # Make sure people can specify TLDs
+ def test_match_tlds
+ assert_nothing_raised {
+ @decl.pattern = "*.tld"
+ }
- ip_exact = Declaration.new(:allow, "192.168.0.1")
- ip_range = Declaration.new(:allow, "192.168.0.*")
+ assert_equal(%w{tld}, @decl.pattern, "Failed to allow custom tld")
+ end
+ # Make sure we sort correctly.
+ def test_sorting
+ # Make sure declarations with no length sort first.
+ host_exact = Declaration.new(:allow, "host.com")
+ host_range = Declaration.new(:allow, "*.host.com")
- assert_equal(
- -1, host_exact <=> host_range,
+ ip_exact = Declaration.new(:allow, "192.168.0.1")
+ ip_range = Declaration.new(:allow, "192.168.0.*")
- "exact name match did not sort first")
+ assert_equal(
+ -1, host_exact <=> host_range,
- assert_equal(
- -1, ip_exact <=> ip_range,
+ "exact name match did not sort first")
- "exact ip match did not sort first")
- # Next make sure we sort by length
- ip_long = Declaration.new(:allow, "192.168.*")
- assert_equal(-1, ip_range <=> ip_long, "/16 sorted before /24 in ip")
+ assert_equal(
+ -1, ip_exact <=> ip_range,
- # Now try it using masks
- ip24 = Declaration.new(:allow, "192.168.0.0/24")
- ip16 = Declaration.new(:allow, "192.168.0.0/16")
+ "exact ip match did not sort first")
- assert_equal(-1, ip24 <=> ip16, "/16 sorted before /24 in ip with masks")
+ # Next make sure we sort by length
+ ip_long = Declaration.new(:allow, "192.168.*")
+ assert_equal(-1, ip_range <=> ip_long, "/16 sorted before /24 in ip")
- # Make sure ip checks sort before host checks
- assert_equal(-1, ip_exact <=> host_exact, "IP exact did not sort before host exact")
+ # Now try it using masks
+ ip24 = Declaration.new(:allow, "192.168.0.0/24")
+ ip16 = Declaration.new(:allow, "192.168.0.0/16")
+ assert_equal(-1, ip24 <=> ip16, "/16 sorted before /24 in ip with masks")
- assert_equal(
- -1, ip_range <=> host_range,
+ # Make sure ip checks sort before host checks
+ assert_equal(-1, ip_exact <=> host_exact, "IP exact did not sort before host exact")
- "IP range did not sort before host range")
- host_long = Declaration.new(:allow, "*.domain.host.com")
+ assert_equal(
+ -1, ip_range <=> host_range,
- assert_equal(-1, host_long <=> host_range, "did not sort by domain length")
+ "IP range did not sort before host range")
- # Now make sure denies sort before allows, for equivalent
- # declarations.
- host_deny = Declaration.new(:deny, "host.com")
- assert_equal(-1, host_deny <=> host_exact, "deny did not sort before allow when exact")
+ host_long = Declaration.new(:allow, "*.domain.host.com")
- host_range_deny = Declaration.new(:deny, "*.host.com")
- assert_equal(-1, host_range_deny <=> host_range, "deny did not sort before allow when ranged")
+ assert_equal(-1, host_long <=> host_range, "did not sort by domain length")
- ip_allow = Declaration.new(:allow, "192.168.0.0/16")
- ip_deny = Declaration.new(:deny, "192.168.0.0/16")
+ # Now make sure denies sort before allows, for equivalent
+ # declarations.
+ host_deny = Declaration.new(:deny, "host.com")
+ assert_equal(-1, host_deny <=> host_exact, "deny did not sort before allow when exact")
+ host_range_deny = Declaration.new(:deny, "*.host.com")
+ assert_equal(-1, host_range_deny <=> host_range, "deny did not sort before allow when ranged")
- assert_equal(
- -1, ip_deny <=> ip_allow,
+ ip_allow = Declaration.new(:allow, "192.168.0.0/16")
+ ip_deny = Declaration.new(:deny, "192.168.0.0/16")
- "deny did not sort before allow in ip range")
- %w{host.com *.domain.com 192.168.0.1 192.168.0.1/24}.each do |decl|
- assert_equal(0, Declaration.new(:allow, decl) <=>
- Declaration.new(:allow, decl),
- "Equivalent declarations for #{decl} were considered different"
- )
- end
- end
+ assert_equal(
+ -1, ip_deny <=> ip_allow,
- def test_match?
- host = Declaration.new(:allow, "host.com")
- host.expects(:matchname?).with("host.com")
- host.match?("host.com", "192.168.0.1")
+ "deny did not sort before allow in ip range")
- ip = Declaration.new(:allow, "192.168.0.1")
- ip.pattern.expects(:include?)
- ip.match?("host.com", "192.168.0.1")
+ %w{host.com *.domain.com 192.168.0.1 192.168.0.1/24}.each do |decl|
+ assert_equal(0, Declaration.new(:allow, decl) <=>
+ Declaration.new(:allow, decl),
+ "Equivalent declarations for #{decl} were considered different"
+ )
end
-
- def test_matchname?
- host = Declaration.new(:allow, "host.com")
- assert(host.send(:matchname?, "host.com"), "exact did not match")
- assert(! host.send(:matchname?, "yay.com"), "incorrect match")
-
- domain = Declaration.new(:allow, "*.domain.com")
- %w{host.domain.com domain.com very.long.domain.com very-long.domain.com }.each do |name|
- assert(domain.send(:matchname?, name), "Did not match #{name}")
- end
+ end
+
+ def test_match?
+ host = Declaration.new(:allow, "host.com")
+ host.expects(:matchname?).with("host.com")
+ host.match?("host.com", "192.168.0.1")
+
+ ip = Declaration.new(:allow, "192.168.0.1")
+ ip.pattern.expects(:include?)
+ ip.match?("host.com", "192.168.0.1")
+ end
+
+ def test_matchname?
+ host = Declaration.new(:allow, "host.com")
+ assert(host.send(:matchname?, "host.com"), "exact did not match")
+ assert(! host.send(:matchname?, "yay.com"), "incorrect match")
+
+ domain = Declaration.new(:allow, "*.domain.com")
+ %w{host.domain.com domain.com very.long.domain.com very-long.domain.com }.each do |name|
+ assert(domain.send(:matchname?, name), "Did not match #{name}")
end
+ end
end
diff --git a/test/network/client/ca.rb b/test/network/client/ca.rb
index 27350831a..5037fe48d 100755
--- a/test/network/client/ca.rb
+++ b/test/network/client/ca.rb
@@ -8,62 +8,62 @@ require 'puppet/network/client/ca'
require 'puppet/sslcertificates/support'
class TestClientCA < Test::Unit::TestCase
- include PuppetTest::ServerTest
+ include PuppetTest::ServerTest
- def setup
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- super
- @ca = Puppet::Network::Handler.ca.new
- @client = Puppet::Network::Client.ca.new :CA => @ca
- end
-
- def test_request_cert
- assert_nothing_raised("Could not request cert") do
- @client.request_cert
- end
+ def setup
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ super
+ @ca = Puppet::Network::Handler.ca.new
+ @client = Puppet::Network::Client.ca.new :CA => @ca
+ end
- [:hostprivkey, :hostcert, :localcacert].each do |name|
- assert(FileTest.exists?(Puppet.settings[name]), "Did not create cert #{name}")
- end
+ def test_request_cert
+ assert_nothing_raised("Could not request cert") do
+ @client.request_cert
end
- # Make sure the ca defaults to specific ports and names
- def test_ca_server
- Puppet.settings.stubs(:value).returns "eh"
- Puppet.settings.expects(:value).with(:ca_server).returns("myca")
- Puppet.settings.expects(:value).with(:ca_port).returns(321)
- Puppet.settings.stubs(:value).with(:http_proxy_host).returns(nil)
- Puppet.settings.stubs(:value).with(:http_proxy_port).returns(nil)
- Puppet.settings.stubs(:value).with(:http_keepalive).returns(false)
- Puppet.settings.stubs(:value).with(:configtimeout).returns(180)
-
- # Just throw an error; the important thing is the values, not what happens next.
- Net::HTTP.stubs(:new).with("myca", 321, nil, nil).raises(ArgumentError)
- assert_raise(ArgumentError) { Puppet::Network::Client.ca.new }
+ [:hostprivkey, :hostcert, :localcacert].each do |name|
+ assert(FileTest.exists?(Puppet.settings[name]), "Did not create cert #{name}")
end
+ end
- # #578
- def test_invalid_certs_are_not_written
- # Run the get once, which should be valid
+ # Make sure the ca defaults to specific ports and names
+ def test_ca_server
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:ca_server).returns("myca")
+ Puppet.settings.expects(:value).with(:ca_port).returns(321)
+ Puppet.settings.stubs(:value).with(:http_proxy_host).returns(nil)
+ Puppet.settings.stubs(:value).with(:http_proxy_port).returns(nil)
+ Puppet.settings.stubs(:value).with(:http_keepalive).returns(false)
+ Puppet.settings.stubs(:value).with(:configtimeout).returns(180)
- assert_nothing_raised("Could not get a certificate") do
- @client.request_cert
- end
+ # Just throw an error; the important thing is the values, not what happens next.
+ Net::HTTP.stubs(:new).with("myca", 321, nil, nil).raises(ArgumentError)
+ assert_raise(ArgumentError) { Puppet::Network::Client.ca.new }
+ end
- # Now remove the cert and keys, so we get a broken cert
- File.unlink(Puppet[:hostcert])
- File.unlink(Puppet[:localcacert])
- File.unlink(Puppet[:hostprivkey])
+ # #578
+ def test_invalid_certs_are_not_written
+ # Run the get once, which should be valid
- @client = Puppet::Network::Client.ca.new :CA => @ca
- @ca.expects(:getcert).returns("yay") # not a valid cert
- # Now make sure it fails, since we'll get the old cert but have new keys
- assert_raise(Puppet::Network::Client::CA::InvalidCertificate, "Did not fail on invalid cert") do
- @client.request_cert
- end
+ assert_nothing_raised("Could not get a certificate") do
+ @client.request_cert
+ end
+
+ # Now remove the cert and keys, so we get a broken cert
+ File.unlink(Puppet[:hostcert])
+ File.unlink(Puppet[:localcacert])
+ File.unlink(Puppet[:hostprivkey])
- # And then make sure the cert isn't written to disk
- assert(! FileTest.exists?(Puppet[:hostcert]), "Invalid cert got written to disk")
+ @client = Puppet::Network::Client.ca.new :CA => @ca
+ @ca.expects(:getcert).returns("yay") # not a valid cert
+ # Now make sure it fails, since we'll get the old cert but have new keys
+ assert_raise(Puppet::Network::Client::CA::InvalidCertificate, "Did not fail on invalid cert") do
+ @client.request_cert
end
+
+ # And then make sure the cert isn't written to disk
+ assert(! FileTest.exists?(Puppet[:hostcert]), "Invalid cert got written to disk")
+ end
end
diff --git a/test/network/client/dipper.rb b/test/network/client/dipper.rb
index 17298c45b..d4f784628 100755
--- a/test/network/client/dipper.rb
+++ b/test/network/client/dipper.rb
@@ -6,29 +6,29 @@ require 'puppettest'
require 'puppet/file_bucket/dipper'
class TestDipperClient < Test::Unit::TestCase
- include PuppetTest::ServerTest
-
- def setup
- super
- @dipper = Puppet::FileBucket::Dipper.new(:Path => tempfile)
+ include PuppetTest::ServerTest
+
+ def setup
+ super
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => tempfile)
+ end
+
+ # Make sure we can create a new file with 'restore'.
+ def test_restore_to_new_file
+ file = tempfile
+ text = "asdf;lkajseofiqwekj"
+ File.open(file, "w") { |f| f.puts text }
+ md5 = nil
+ assert_nothing_raised("Could not send file") do
+ md5 = @dipper.backup(file)
end
- # Make sure we can create a new file with 'restore'.
- def test_restore_to_new_file
- file = tempfile
- text = "asdf;lkajseofiqwekj"
- File.open(file, "w") { |f| f.puts text }
- md5 = nil
- assert_nothing_raised("Could not send file") do
- md5 = @dipper.backup(file)
- end
-
- newfile = tempfile
- assert_nothing_raised("could not restore to new path") do
- @dipper.restore(newfile, md5)
- end
-
- assert_equal(File.read(file), File.read(newfile), "did not restore correctly")
+ newfile = tempfile
+ assert_nothing_raised("could not restore to new path") do
+ @dipper.restore(newfile, md5)
end
+
+ assert_equal(File.read(file), File.read(newfile), "did not restore correctly")
+ end
end
diff --git a/test/network/client_request.rb b/test/network/client_request.rb
index 3a35706be..25fc57ff4 100755
--- a/test/network/client_request.rb
+++ b/test/network/client_request.rb
@@ -7,32 +7,32 @@ require 'puppettest'
require 'puppet/network/client_request'
class TestClientRequest < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def test_initialize
- req = nil
- assert_nothing_raised do
- req = Puppet::Network::ClientRequest.new("name", "ip", false)
- end
+ def test_initialize
+ req = nil
+ assert_nothing_raised do
+ req = Puppet::Network::ClientRequest.new("name", "ip", false)
+ end
- assert_equal("name", req.name, "host name was not set correctly")
- assert_equal("ip", req.ip, "host ip was not set correctly")
- assert_equal(false, req.authenticated, "host auth was not set correctly")
- assert(! req.authenticated, "host was incorrectly considered authenticated")
+ assert_equal("name", req.name, "host name was not set correctly")
+ assert_equal("ip", req.ip, "host ip was not set correctly")
+ assert_equal(false, req.authenticated, "host auth was not set correctly")
+ assert(! req.authenticated, "host was incorrectly considered authenticated")
- req.authenticated = true
- assert(req.authenticated, "host was not considered authenticated")
+ req.authenticated = true
+ assert(req.authenticated, "host was not considered authenticated")
- assert_raise(ArgumentError) do
- req.call
- end
+ assert_raise(ArgumentError) do
+ req.call
+ end
- req.handler = "yay"
- req.method = "foo"
- assert_equal("yay.foo", req.call, "call was not built correctly")
+ req.handler = "yay"
+ req.method = "foo"
+ assert_equal("yay.foo", req.call, "call was not built correctly")
- assert_equal("name(ip)", req.to_s, "request string not correct")
- end
+ assert_equal("name(ip)", req.to_s, "request string not correct")
+ end
end
diff --git a/test/network/handler/ca.rb b/test/network/handler/ca.rb
index 401b8d5fe..79a1b15dc 100755
--- a/test/network/handler/ca.rb
+++ b/test/network/handler/ca.rb
@@ -9,265 +9,265 @@ require 'mocha'
$short = (ARGV.length > 0 and ARGV[0] == "short")
class TestCA < Test::Unit::TestCase
- include PuppetTest::ServerTest
-
- def setup
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- super
- end
-
- # Verify that we're autosigning. We have to autosign a "different" machine,
- # since we always autosign the CA server's certificate.
- def test_autocertgeneration
- ca = nil
-
- # create our ca
- assert_nothing_raised {
- ca = Puppet::Network::Handler.ca.new(:autosign => true)
- }
-
- # create a cert with a fake name
- key = nil
- csr = nil
- cert = nil
- hostname = "test.domain.com"
- assert_nothing_raised {
- cert = Puppet::SSLCertificates::Certificate.new(
- :name => "test.domain.com"
- )
- }
-
- # make the request
- assert_nothing_raised {
- cert.mkcsr
- }
-
- # and get it signed
- certtext = nil
- cacerttext = nil
- assert_nothing_raised {
- certtext, cacerttext = ca.getcert(cert.csr.to_s)
- }
-
- # they should both be strings
- assert_instance_of(String, certtext)
- assert_instance_of(String, cacerttext)
-
- # and they should both be valid certs
- assert_nothing_raised {
- OpenSSL::X509::Certificate.new(certtext)
- }
- assert_nothing_raised {
- OpenSSL::X509::Certificate.new(cacerttext)
- }
-
- # and pull it again, just to make sure we're getting the same thing
- newtext = nil
- assert_nothing_raised {
- newtext, cacerttext = ca.getcert(
- cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
- )
- }
-
- assert_equal(certtext,newtext)
- end
-
- # this time don't use autosign
- def test_storeAndSign
- ca = nil
- caserv = nil
-
- # make our CA server
- assert_nothing_raised {
- caserv = Puppet::Network::Handler.ca.new(:autosign => false)
- }
-
- # retrieve the actual ca object
- assert_nothing_raised {
- ca = caserv.ca
- }
-
- # make our test cert again
- key = nil
- csr = nil
- cert = nil
- hostname = "test.domain.com"
- assert_nothing_raised {
- cert = Puppet::SSLCertificates::Certificate.new(
- :name => "anothertest.domain.com"
- )
- }
- # and the CSR
- assert_nothing_raised {
- cert.mkcsr
- }
-
- # retrieve them
- certtext = nil
- assert_nothing_raised {
- certtext, cacerttext = caserv.getcert(
- cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
- )
- }
-
- # verify we got nothing back, since autosign is off
- assert_equal("", certtext)
-
- # now sign it manually, with the CA object
- x509 = nil
- assert_nothing_raised {
- x509, cacert = ca.sign(cert.csr)
- }
-
- # and write it out
- cert.cert = x509
- assert_nothing_raised {
- cert.write
- }
-
- assert(File.exists?(cert.certfile))
-
- # now get them again, and verify that we actually get them
- newtext = nil
- assert_nothing_raised {
- newtext, cacerttext = caserv.getcert(cert.csr.to_s)
- }
-
- assert(newtext)
- assert_nothing_raised {
- OpenSSL::X509::Certificate.new(newtext)
- }
-
- # Now verify that we can clean a given host's certs
- assert_nothing_raised {
- ca.clean("anothertest.domain.com")
- }
-
- assert(!File.exists?(cert.certfile), "Cert still exists after clean")
- end
-
- # and now test the autosign file
- def test_autosign
- autosign = File.join(tmpdir, "autosigntesting")
- @@tmpfiles << autosign
- File.open(autosign, "w") { |f|
- f.puts "hostmatch.domain.com"
- f.puts "*.other.com"
- }
-
- caserv = nil
- assert_nothing_raised {
- caserv = Puppet::Network::Handler.ca.new(:autosign => autosign)
- }
-
- # make sure we know what's going on
- assert(caserv.autosign?("hostmatch.domain.com"))
- assert(caserv.autosign?("fakehost.other.com"))
- assert(!caserv.autosign?("kirby.reductivelabs.com"))
- assert(!caserv.autosign?("culain.domain.com"))
- end
-
- # verify that things aren't autosigned by default
- def test_nodefaultautosign
- caserv = nil
- assert_nothing_raised {
- caserv = Puppet::Network::Handler.ca.new
- }
-
- # make sure we know what's going on
- assert(!caserv.autosign?("hostmatch.domain.com"))
- assert(!caserv.autosign?("fakehost.other.com"))
- assert(!caserv.autosign?("kirby.reductivelabs.com"))
- assert(!caserv.autosign?("culain.domain.com"))
- end
-
- # We want the CA to autosign its own certificate, because otherwise
- # the puppetmasterd CA does not autostart.
- def test_caautosign
- server = nil
- Puppet.stubs(:master?).returns true
- assert_nothing_raised {
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
+ include PuppetTest::ServerTest
+
+ def setup
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ super
+ end
+
+ # Verify that we're autosigning. We have to autosign a "different" machine,
+ # since we always autosign the CA server's certificate.
+ def test_autocertgeneration
+ ca = nil
+
+ # create our ca
+ assert_nothing_raised {
+ ca = Puppet::Network::Handler.ca.new(:autosign => true)
+ }
+
+ # create a cert with a fake name
+ key = nil
+ csr = nil
+ cert = nil
+ hostname = "test.domain.com"
+ assert_nothing_raised {
+ cert = Puppet::SSLCertificates::Certificate.new(
+ :name => "test.domain.com"
+ )
+ }
+
+ # make the request
+ assert_nothing_raised {
+ cert.mkcsr
+ }
+
+ # and get it signed
+ certtext = nil
+ cacerttext = nil
+ assert_nothing_raised {
+ certtext, cacerttext = ca.getcert(cert.csr.to_s)
+ }
+
+ # they should both be strings
+ assert_instance_of(String, certtext)
+ assert_instance_of(String, cacerttext)
+
+ # and they should both be valid certs
+ assert_nothing_raised {
+ OpenSSL::X509::Certificate.new(certtext)
+ }
+ assert_nothing_raised {
+ OpenSSL::X509::Certificate.new(cacerttext)
+ }
+
+ # and pull it again, just to make sure we're getting the same thing
+ newtext = nil
+ assert_nothing_raised {
+ newtext, cacerttext = ca.getcert(
+ cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
+ )
+ }
+
+ assert_equal(certtext,newtext)
+ end
+
+ # this time don't use autosign
+ def test_storeAndSign
+ ca = nil
+ caserv = nil
+
+ # make our CA server
+ assert_nothing_raised {
+ caserv = Puppet::Network::Handler.ca.new(:autosign => false)
+ }
+
+ # retrieve the actual ca object
+ assert_nothing_raised {
+ ca = caserv.ca
+ }
+
+ # make our test cert again
+ key = nil
+ csr = nil
+ cert = nil
+ hostname = "test.domain.com"
+ assert_nothing_raised {
+ cert = Puppet::SSLCertificates::Certificate.new(
+ :name => "anothertest.domain.com"
+ )
+ }
+ # and the CSR
+ assert_nothing_raised {
+ cert.mkcsr
+ }
+
+ # retrieve them
+ certtext = nil
+ assert_nothing_raised {
+ certtext, cacerttext = caserv.getcert(
+ cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
+ )
+ }
+
+ # verify we got nothing back, since autosign is off
+ assert_equal("", certtext)
+
+ # now sign it manually, with the CA object
+ x509 = nil
+ assert_nothing_raised {
+ x509, cacert = ca.sign(cert.csr)
+ }
+
+ # and write it out
+ cert.cert = x509
+ assert_nothing_raised {
+ cert.write
+ }
+
+ assert(File.exists?(cert.certfile))
+
+ # now get them again, and verify that we actually get them
+ newtext = nil
+ assert_nothing_raised {
+ newtext, cacerttext = caserv.getcert(cert.csr.to_s)
+ }
+
+ assert(newtext)
+ assert_nothing_raised {
+ OpenSSL::X509::Certificate.new(newtext)
+ }
+
+ # Now verify that we can clean a given host's certs
+ assert_nothing_raised {
+ ca.clean("anothertest.domain.com")
+ }
+
+ assert(!File.exists?(cert.certfile), "Cert still exists after clean")
+ end
+
+ # and now test the autosign file
+ def test_autosign
+ autosign = File.join(tmpdir, "autosigntesting")
+ @@tmpfiles << autosign
+ File.open(autosign, "w") { |f|
+ f.puts "hostmatch.domain.com"
+ f.puts "*.other.com"
+ }
+
+ caserv = nil
+ assert_nothing_raised {
+ caserv = Puppet::Network::Handler.ca.new(:autosign => autosign)
+ }
+
+ # make sure we know what's going on
+ assert(caserv.autosign?("hostmatch.domain.com"))
+ assert(caserv.autosign?("fakehost.other.com"))
+ assert(!caserv.autosign?("kirby.reductivelabs.com"))
+ assert(!caserv.autosign?("culain.domain.com"))
+ end
+
+ # verify that things aren't autosigned by default
+ def test_nodefaultautosign
+ caserv = nil
+ assert_nothing_raised {
+ caserv = Puppet::Network::Handler.ca.new
+ }
+
+ # make sure we know what's going on
+ assert(!caserv.autosign?("hostmatch.domain.com"))
+ assert(!caserv.autosign?("fakehost.other.com"))
+ assert(!caserv.autosign?("kirby.reductivelabs.com"))
+ assert(!caserv.autosign?("culain.domain.com"))
+ end
+
+ # We want the CA to autosign its own certificate, because otherwise
+ # the puppetmasterd CA does not autostart.
+ def test_caautosign
+ server = nil
+ Puppet.stubs(:master?).returns true
+ assert_nothing_raised {
+
+ server = Puppet::Network::HTTPServer::WEBrick.new(
- :Port => @@port,
+ :Port => @@port,
- :Handlers => {
- :CA => {}, # so that certs autogenerate
- :Status => nil
- }
- )
+ :Handlers => {
+ :CA => {}, # so that certs autogenerate
+ :Status => nil
}
+ )
+ }
+ end
+
+ # Make sure true/false causes the file to be ignored.
+ def test_autosign_true_beats_file
+ caserv = nil
+ assert_nothing_raised {
+ caserv = Puppet::Network::Handler.ca.new
+ }
+
+ host = "hostname.domain.com"
+
+ # Create an autosign file
+ file = tempfile
+ Puppet[:autosign] = file
+
+ File.open(file, "w") { |f|
+ f.puts host
+ }
+
+ # Start with "false"
+ Puppet[:autosign] = false
+
+ assert(! caserv.autosign?(host), "Host was incorrectly autosigned")
+
+ # Then set it to true
+ Puppet[:autosign] = true
+ assert(caserv.autosign?(host), "Host was not autosigned")
+ # And try a different host
+ assert(caserv.autosign?("other.yay.com"), "Host was not autosigned")
+
+ # And lastly the file
+ Puppet[:autosign] = file
+ assert(caserv.autosign?(host), "Host was not autosigned")
+
+ # And try a different host
+ assert(! caserv.autosign?("other.yay.com"), "Host was autosigned")
+ end
+
+ # Make sure that a CSR created with keys that don't match the existing
+ # cert throws an exception on the server.
+ def test_mismatched_public_keys_throws_exception
+ ca = Puppet::Network::Handler.ca.new
+
+ # First initialize the server
+ client = Puppet::Network::Client.ca.new :CA => ca
+ client.request_cert
+ File.unlink(Puppet[:hostcsr])
+
+ # Now use a different cert name
+ Puppet[:certname] = "my.host.com"
+ client = Puppet::Network::Client.ca.new :CA => ca
+ firstcsr = client.csr
+ File.unlink(Puppet[:hostcsr]) if FileTest.exists?(Puppet[:hostcsr])
+
+ assert_nothing_raised("Could not get cert") do
+ ca.getcert(firstcsr.to_s)
end
- # Make sure true/false causes the file to be ignored.
- def test_autosign_true_beats_file
- caserv = nil
- assert_nothing_raised {
- caserv = Puppet::Network::Handler.ca.new
- }
-
- host = "hostname.domain.com"
-
- # Create an autosign file
- file = tempfile
- Puppet[:autosign] = file
-
- File.open(file, "w") { |f|
- f.puts host
- }
-
- # Start with "false"
- Puppet[:autosign] = false
-
- assert(! caserv.autosign?(host), "Host was incorrectly autosigned")
-
- # Then set it to true
- Puppet[:autosign] = true
- assert(caserv.autosign?(host), "Host was not autosigned")
- # And try a different host
- assert(caserv.autosign?("other.yay.com"), "Host was not autosigned")
-
- # And lastly the file
- Puppet[:autosign] = file
- assert(caserv.autosign?(host), "Host was not autosigned")
-
- # And try a different host
- assert(! caserv.autosign?("other.yay.com"), "Host was autosigned")
- end
-
- # Make sure that a CSR created with keys that don't match the existing
- # cert throws an exception on the server.
- def test_mismatched_public_keys_throws_exception
- ca = Puppet::Network::Handler.ca.new
-
- # First initialize the server
- client = Puppet::Network::Client.ca.new :CA => ca
- client.request_cert
- File.unlink(Puppet[:hostcsr])
-
- # Now use a different cert name
- Puppet[:certname] = "my.host.com"
- client = Puppet::Network::Client.ca.new :CA => ca
- firstcsr = client.csr
- File.unlink(Puppet[:hostcsr]) if FileTest.exists?(Puppet[:hostcsr])
-
- assert_nothing_raised("Could not get cert") do
- ca.getcert(firstcsr.to_s)
- end
-
- # Now get rid of the public key, forcing a new csr
- File.unlink(Puppet[:hostprivkey])
+ # Now get rid of the public key, forcing a new csr
+ File.unlink(Puppet[:hostprivkey])
- client = Puppet::Network::Client.ca.new :CA => ca
+ client = Puppet::Network::Client.ca.new :CA => ca
- second_csr = client.csr
+ second_csr = client.csr
- assert(firstcsr.to_s != second_csr.to_s, "CSR did not change")
+ assert(firstcsr.to_s != second_csr.to_s, "CSR did not change")
- assert_raise(Puppet::Error, "CA allowed mismatched keys") do
- ca.getcert(second_csr.to_s)
- end
+ assert_raise(Puppet::Error, "CA allowed mismatched keys") do
+ ca.getcert(second_csr.to_s)
end
+ end
end
diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb
index bfe76d078..d979821bb 100755
--- a/test/network/handler/fileserver.rb
+++ b/test/network/handler/fileserver.rb
@@ -6,833 +6,833 @@ require 'puppettest'
require 'puppet/network/handler/fileserver'
class TestFileServer < Test::Unit::TestCase
- include PuppetTest
-
- def mkmount(path = nil)
- mount = nil
- name = "yaytest"
- base = path || tempfile
- Dir.mkdir(base) unless FileTest.exists?(base)
- # Create a test file
- File.open(File.join(base, "file"), "w") { |f| f.puts "bazoo" }
- assert_nothing_raised {
- mount = Puppet::Network::Handler.fileserver::Mount.new(name, base)
- }
+ include PuppetTest
+
+ def mkmount(path = nil)
+ mount = nil
+ name = "yaytest"
+ base = path || tempfile
+ Dir.mkdir(base) unless FileTest.exists?(base)
+ # Create a test file
+ File.open(File.join(base, "file"), "w") { |f| f.puts "bazoo" }
+ assert_nothing_raised {
+ mount = Puppet::Network::Handler.fileserver::Mount.new(name, base)
+ }
- mount
- end
- # make a simple file source
- def mktestdir
- testdir = File.join(tmpdir, "remotefilecopytesting")
- @@tmpfiles << testdir
-
- # create a tmpfile
- pattern = "tmpfile"
- tmpfile = File.join(testdir, pattern)
- assert_nothing_raised {
- Dir.mkdir(testdir)
- File.open(tmpfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- }
+ mount
+ end
+ # make a simple file source
+ def mktestdir
+ testdir = File.join(tmpdir, "remotefilecopytesting")
+ @@tmpfiles << testdir
- [testdir, %r{#{pattern}}, tmpfile]
- end
+ # create a tmpfile
+ pattern = "tmpfile"
+ tmpfile = File.join(testdir, pattern)
+ assert_nothing_raised {
+ Dir.mkdir(testdir)
+ File.open(tmpfile, "w") { |f|
+ 3.times { f.puts rand(100) }
+ }
+ }
- # make a bunch of random test files
- def mktestfiles(testdir)
- @@tmpfiles << testdir
- assert_nothing_raised {
- files = %w{a b c d e}.collect { |l|
- name = File.join(testdir, "file#{l}")
- File.open(name, "w") { |f|
- f.puts rand(100)
- }
-
- name
- }
+ [testdir, %r{#{pattern}}, tmpfile]
+ end
- return files
+ # make a bunch of random test files
+ def mktestfiles(testdir)
+ @@tmpfiles << testdir
+ assert_nothing_raised {
+ files = %w{a b c d e}.collect { |l|
+ name = File.join(testdir, "file#{l}")
+ File.open(name, "w") { |f|
+ f.puts rand(100)
}
- end
- def assert_describe(base, file, server)
- file = File.basename(file)
- assert_nothing_raised {
- desc = server.describe(base + file)
- assert(desc, "Got no description for #{file}")
- assert(desc != "", "Got no description for #{file}")
- assert_match(/^\d+/, desc, "Got invalid description #{desc}")
- }
- end
+ name
+ }
- # test for invalid names
- def test_namefailures
- server = nil
- assert_nothing_raised {
+ return files
+ }
+ end
- server = Puppet::Network::Handler.fileserver.new(
+ def assert_describe(base, file, server)
+ file = File.basename(file)
+ assert_nothing_raised {
+ desc = server.describe(base + file)
+ assert(desc, "Got no description for #{file}")
+ assert(desc != "", "Got no description for #{file}")
+ assert_match(/^\d+/, desc, "Got invalid description #{desc}")
+ }
+ end
- :Local => true,
+ # test for invalid names
+ def test_namefailures
+ server = nil
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- [" ", "=" "+", "&", "#", "*"].each do |char|
- assert_raise(Puppet::Network::Handler::FileServerError, "'#{char}' did not throw a failure in fileserver module names") {
- server.mount("/tmp", "invalid#{char}name")
- }
- end
- end
+ :Local => true,
- # verify that listing the root behaves as expected
- def test_listroot
- server = nil
- testdir, pattern, tmpfile = mktestdir
+ :Config => false
+ )
+ }
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
+ [" ", "=" "+", "&", "#", "*"].each do |char|
+ assert_raise(Puppet::Network::Handler::FileServerError, "'#{char}' did not throw a failure in fileserver module names") {
+ server.mount("/tmp", "invalid#{char}name")
+ }
+ end
+ end
- # and make our fileserver
- assert_nothing_raised {
+ # verify that listing the root behaves as expected
+ def test_listroot
+ server = nil
+ testdir, pattern, tmpfile = mktestdir
- server = Puppet::Network::Handler.fileserver.new(
+ file = nil
+ checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
- :Local => true,
+ # and make our fileserver
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- # mount the testdir
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
+ :Local => true,
- # and verify different iterations of 'root' return the same value
- list = nil
- assert_nothing_raised {
- list = server.list("/test/", :manage, true, false)
- }
+ :Config => false
+ )
+ }
- assert(list =~ pattern)
+ # mount the testdir
+ assert_nothing_raised {
+ server.mount(testdir, "test")
+ }
- assert_nothing_raised {
- list = server.list("/test", :manage, true, false)
- }
- assert(list =~ pattern)
+ # and verify different iterations of 'root' return the same value
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/test/", :manage, true, false)
+ }
- end
+ assert(list =~ pattern)
- # test listing individual files
- def test_getfilelist
- server = nil
- testdir, pattern, tmpfile = mktestdir
+ assert_nothing_raised {
+ list = server.list("/test", :manage, true, false)
+ }
+ assert(list =~ pattern)
- file = nil
+ end
- assert_nothing_raised {
+ # test listing individual files
+ def test_getfilelist
+ server = nil
+ testdir, pattern, tmpfile = mktestdir
- server = Puppet::Network::Handler.fileserver.new(
+ file = nil
- :Local => true,
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
+ :Local => true,
- # get our listing
- list = nil
- sfile = "/test/tmpfile"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
+ :Config => false
+ )
+ }
- output = "/\tfile"
+ assert_nothing_raised {
+ server.mount(testdir, "test")
+ }
- # verify it got listed as a file
- assert_equal(output, list)
+ # get our listing
+ list = nil
+ sfile = "/test/tmpfile"
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false)
+ }
- # verify we got all fields
- assert(list !~ /\t\t/)
+ output = "/\tfile"
- # verify that we didn't get the directory itself
- list.split("\n").each { |line|
- assert(line !~ %r{remotefile})
- }
+ # verify it got listed as a file
+ assert_equal(output, list)
- # and then verify that the contents match
- contents = File.read(tmpfile)
+ # verify we got all fields
+ assert(list !~ /\t\t/)
- ret = nil
- assert_nothing_raised {
- ret = server.retrieve(sfile)
- }
+ # verify that we didn't get the directory itself
+ list.split("\n").each { |line|
+ assert(line !~ %r{remotefile})
+ }
- assert_equal(contents, ret)
- end
+ # and then verify that the contents match
+ contents = File.read(tmpfile)
- # check that the fileserver is seeing newly created files
- def test_seenewfiles
- server = nil
- testdir, pattern, tmpfile = mktestdir
+ ret = nil
+ assert_nothing_raised {
+ ret = server.retrieve(sfile)
+ }
+ assert_equal(contents, ret)
+ end
- newfile = File.join(testdir, "newfile")
+ # check that the fileserver is seeing newly created files
+ def test_seenewfiles
+ server = nil
+ testdir, pattern, tmpfile = mktestdir
- # go through the whole schtick again...
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
- assert_nothing_raised {
+ newfile = File.join(testdir, "newfile")
- server = Puppet::Network::Handler.fileserver.new(
+ # go through the whole schtick again...
+ file = nil
+ checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
- :Local => true,
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
+ :Local => true,
- list = nil
- sfile = "/test/"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
+ :Config => false
+ )
+ }
- # create the new file
- File.open(newfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
+ assert_nothing_raised {
+ server.mount(testdir, "test")
+ }
- newlist = nil
- assert_nothing_raised {
- newlist = server.list(sfile, :manage, true, false)
- }
+ list = nil
+ sfile = "/test/"
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false)
+ }
- # verify the list has changed
- assert(list != newlist)
+ # create the new file
+ File.open(newfile, "w") { |f|
+ 3.times { f.puts rand(100) }
+ }
- # and verify that we are specifically seeing the new file
- assert(newlist =~ /newfile/)
- end
+ newlist = nil
+ assert_nothing_raised {
+ newlist = server.list(sfile, :manage, true, false)
+ }
- # verify we can mount /, which is what local file servers will
- # normally do
- def test_mountroot
- server = nil
- assert_nothing_raised {
+ # verify the list has changed
+ assert(list != newlist)
- server = Puppet::Network::Handler.fileserver.new(
+ # and verify that we are specifically seeing the new file
+ assert(newlist =~ /newfile/)
+ end
- :Local => true,
+ # verify we can mount /, which is what local file servers will
+ # normally do
+ def test_mountroot
+ server = nil
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- assert_nothing_raised {
- server.mount("/", "root")
- }
+ :Local => true,
- testdir, pattern, tmpfile = mktestdir
+ :Config => false
+ )
+ }
- list = nil
- assert_nothing_raised {
- list = server.list("/root/#{testdir}", :manage, true, false)
- }
+ assert_nothing_raised {
+ server.mount("/", "root")
+ }
- assert(list =~ pattern)
- assert_nothing_raised {
- list = server.list("/root#{testdir}", :manage, true, false)
- }
+ testdir, pattern, tmpfile = mktestdir
- assert(list =~ pattern)
- end
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/root/#{testdir}", :manage, true, false)
+ }
- # verify that we're correctly recursing the right number of levels
- def test_recursionlevels
- server = nil
- assert_nothing_raised {
+ assert(list =~ pattern)
+ assert_nothing_raised {
+ list = server.list("/root#{testdir}", :manage, true, false)
+ }
- server = Puppet::Network::Handler.fileserver.new(
+ assert(list =~ pattern)
+ end
- :Local => true,
+ # verify that we're correctly recursing the right number of levels
+ def test_recursionlevels
+ server = nil
+ assert_nothing_raised {
- :Config => false
- )
- }
+ server = Puppet::Network::Handler.fileserver.new(
- # make our deep recursion
- basedir = File.join(tmpdir, "recurseremotetesting")
- testdir = "#{basedir}/with/some/sub/directories/for/the/purposes/of/testing"
- oldfile = File.join(testdir, "oldfile")
- assert_nothing_raised {
- system("mkdir -p #{testdir}")
- File.open(oldfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- @@tmpfiles << basedir
- }
+ :Local => true,
- assert_nothing_raised {
- server.mount(basedir, "test")
- }
+ :Config => false
+ )
+ }
- # get our list
- list = nil
- assert_nothing_raised {
- list = server.list("/test/with", :manage, false, false)
- }
+ # make our deep recursion
+ basedir = File.join(tmpdir, "recurseremotetesting")
+ testdir = "#{basedir}/with/some/sub/directories/for/the/purposes/of/testing"
+ oldfile = File.join(testdir, "oldfile")
+ assert_nothing_raised {
+ system("mkdir -p #{testdir}")
+ File.open(oldfile, "w") { |f|
+ 3.times { f.puts rand(100) }
+ }
+ @@tmpfiles << basedir
+ }
- # make sure we only got one line, since we're not recursing
- assert(list !~ /\n/)
+ assert_nothing_raised {
+ server.mount(basedir, "test")
+ }
- # for each level of recursion, make sure we get the right list
- [0, 1, 2].each { |num|
- assert_nothing_raised {
- list = server.list("/test/with", :manage, num, false)
- }
+ # get our list
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/test/with", :manage, false, false)
+ }
- count = 0
- while list =~ /\n/
- list.sub!(/\n/, '')
- count += 1
- end
- assert_equal(num, count)
- }
- end
+ # make sure we only got one line, since we're not recursing
+ assert(list !~ /\n/)
+
+ # for each level of recursion, make sure we get the right list
+ [0, 1, 2].each { |num|
+ assert_nothing_raised {
+ list = server.list("/test/with", :manage, num, false)
+ }
+
+ count = 0
+ while list =~ /\n/
+ list.sub!(/\n/, '')
+ count += 1
+ end
+ assert_equal(num, count)
+ }
+ end
- # verify that we're not seeing the dir we ask for; i.e., that our
- # list is relative to that dir, not it's parent dir
- def test_listedpath
- server = nil
- assert_nothing_raised {
+ # verify that we're not seeing the dir we ask for; i.e., that our
+ # list is relative to that dir, not it's parent dir
+ def test_listedpath
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => false
- )
- }
+ :Config => false
+ )
+ }
- # create a deep dir
- basedir = tempfile
- testdir = "#{basedir}/with/some/sub/directories/for/testing"
- oldfile = File.join(testdir, "oldfile")
- assert_nothing_raised {
- system("mkdir -p #{testdir}")
- File.open(oldfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- @@tmpfiles << basedir
- }
+ # create a deep dir
+ basedir = tempfile
+ testdir = "#{basedir}/with/some/sub/directories/for/testing"
+ oldfile = File.join(testdir, "oldfile")
+ assert_nothing_raised {
+ system("mkdir -p #{testdir}")
+ File.open(oldfile, "w") { |f|
+ 3.times { f.puts rand(100) }
+ }
+ @@tmpfiles << basedir
+ }
- # mounty mounty
- assert_nothing_raised {
- server.mount(basedir, "localhost")
- }
+ # mounty mounty
+ assert_nothing_raised {
+ server.mount(basedir, "localhost")
+ }
- list = nil
- # and then check a few dirs
- assert_nothing_raised {
- list = server.list("/localhost/with", :manage, false, false)
- }
+ list = nil
+ # and then check a few dirs
+ assert_nothing_raised {
+ list = server.list("/localhost/with", :manage, false, false)
+ }
- assert(list !~ /with/)
+ assert(list !~ /with/)
- assert_nothing_raised {
- list = server.list("/localhost/with/some/sub", :manage, true, false)
- }
+ assert_nothing_raised {
+ list = server.list("/localhost/with/some/sub", :manage, true, false)
+ }
- assert(list !~ /sub/)
- end
+ assert(list !~ /sub/)
+ end
- # test many dirs, not necessarily very deep
- def test_widelists
- server = nil
- assert_nothing_raised {
+ # test many dirs, not necessarily very deep
+ def test_widelists
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => false
- )
- }
+ :Config => false
+ )
+ }
- basedir = tempfile
- dirs = %w{a set of directories}
- assert_nothing_raised {
- Dir.mkdir(basedir)
- dirs.each { |dir|
- Dir.mkdir(File.join(basedir, dir))
- }
- @@tmpfiles << basedir
- }
+ basedir = tempfile
+ dirs = %w{a set of directories}
+ assert_nothing_raised {
+ Dir.mkdir(basedir)
+ dirs.each { |dir|
+ Dir.mkdir(File.join(basedir, dir))
+ }
+ @@tmpfiles << basedir
+ }
- assert_nothing_raised {
- server.mount(basedir, "localhost")
- }
+ assert_nothing_raised {
+ server.mount(basedir, "localhost")
+ }
- list = nil
- assert_nothing_raised {
- list = server.list("/localhost/", :manage, 1, false)
- }
- assert_instance_of(String, list, "Server returned %s instead of string")
- list = list.split("\n")
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/localhost/", :manage, 1, false)
+ }
+ assert_instance_of(String, list, "Server returned %s instead of string")
+ list = list.split("\n")
- assert_equal(dirs.length + 1, list.length)
- end
+ assert_equal(dirs.length + 1, list.length)
+ end
- # verify that 'describe' works as advertised
- def test_describe
- server = nil
- testdir = tstdir
- files = mktestfiles(testdir)
+ # verify that 'describe' works as advertised
+ def test_describe
+ server = nil
+ testdir = tstdir
+ files = mktestfiles(testdir)
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
+ file = nil
+ checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
- assert_nothing_raised {
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => false
- )
- }
+ :Config => false
+ )
+ }
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
+ assert_nothing_raised {
+ server.mount(testdir, "test")
+ }
- # get our list
- list = nil
- sfile = "/test/"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
+ # get our list
+ list = nil
+ sfile = "/test/"
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false)
+ }
- # and describe each file in the list
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
+ # and describe each file in the list
+ assert_nothing_raised {
+ list.split("\n").each { |line|
+ file, type = line.split("\t")
- desc = server.describe(sfile + file)
- }
- }
+ desc = server.describe(sfile + file)
+ }
+ }
- # and then make sure we can describe everything that we know is there
- files.each { |file|
- assert_describe(sfile, file, server)
- }
+ # and then make sure we can describe everything that we know is there
+ files.each { |file|
+ assert_describe(sfile, file, server)
+ }
- # And then describe some files that we know aren't there
- retval = nil
- assert_nothing_raised("Describing non-existent files raised an error") {
- retval = server.describe(sfile + "noexisties")
- }
+ # And then describe some files that we know aren't there
+ retval = nil
+ assert_nothing_raised("Describing non-existent files raised an error") {
+ retval = server.describe(sfile + "noexisties")
+ }
- assert_equal("", retval, "Description of non-existent files returned a value")
+ assert_equal("", retval, "Description of non-existent files returned a value")
- # Now try to describe some sources that don't even exist
- retval = nil
+ # Now try to describe some sources that don't even exist
+ retval = nil
- assert_raise(
- Puppet::Network::Handler::FileServerError,
+ assert_raise(
+ Puppet::Network::Handler::FileServerError,
- "Describing non-existent mount did not raise an error") {
- retval = server.describe("/notmounted/noexisties")
- }
+ "Describing non-existent mount did not raise an error") {
+ retval = server.describe("/notmounted/noexisties")
+ }
- assert_nil(retval, "Description of non-existent mounts returned a value")
- end
+ assert_nil(retval, "Description of non-existent mounts returned a value")
+ end
- def test_describe_does_not_fail_when_mount_does_not_find_file
- server = Puppet::Network::Handler.fileserver.new(:Local => true, :Config => false)
+ def test_describe_does_not_fail_when_mount_does_not_find_file
+ server = Puppet::Network::Handler.fileserver.new(:Local => true, :Config => false)
- assert_nothing_raised("Failed when describing missing plugins") do
- server.describe "/plugins"
- end
+ assert_nothing_raised("Failed when describing missing plugins") do
+ server.describe "/plugins"
end
+ end
- # test that our config file is parsing and working as planned
- def test_configfile
- server = nil
- basedir = File.join(tmpdir, "fileserverconfigfiletesting")
- @@tmpfiles << basedir
+ # test that our config file is parsing and working as planned
+ def test_configfile
+ server = nil
+ basedir = File.join(tmpdir, "fileserverconfigfiletesting")
+ @@tmpfiles << basedir
- # make some dirs for mounting
- Dir.mkdir(basedir)
- mounts = {}
- %w{thing thus the-se those}.each { |dir|
- path = File.join(basedir, dir)
- Dir.mkdir(path)
- mounts[dir] = mktestfiles(path)
+ # make some dirs for mounting
+ Dir.mkdir(basedir)
+ mounts = {}
+ %w{thing thus the-se those}.each { |dir|
+ path = File.join(basedir, dir)
+ Dir.mkdir(path)
+ mounts[dir] = mktestfiles(path)
- }
+ }
- # create an example file with each of them
- conffile = tempfile
- @@tmpfiles << conffile
+ # create an example file with each of them
+ conffile = tempfile
+ @@tmpfiles << conffile
- File.open(conffile, "w") { |f|
- f.print "# a test config file
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
[thing]
- path #{basedir}/thing
- allow 192.168.0.*
+ path #{basedir}/thing
+ allow 192.168.0.*
[thus]
- path #{basedir}/thus
- allow *.madstop.com, *.kanies.com
- deny *.sub.madstop.com
+ path #{basedir}/thus
+ allow *.madstop.com, *.kanies.com
+ deny *.sub.madstop.com
[the-se]
- path #{basedir}/the-se
+ path #{basedir}/the-se
[those]
- path #{basedir}/those
+ path #{basedir}/those
"
- }
+ }
- # create a server with the file
- assert_nothing_raised {
+ # create a server with the file
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => false,
+ :Local => false,
- :Config => conffile
- )
- }
-
- list = nil
- # run through once with no host/ip info, to verify everything is working
- mounts.each { |mount, files|
- mount = "/#{mount}/"
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
+ :Config => conffile
+ )
+ }
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
+ list = nil
+ # run through once with no host/ip info, to verify everything is working
+ mounts.each { |mount, files|
+ mount = "/#{mount}/"
+ assert_nothing_raised {
+ list = server.list(mount, :manage, true, false)
+ }
- desc = server.describe(mount + file)
- }
- }
+ assert_nothing_raised {
+ list.split("\n").each { |line|
+ file, type = line.split("\t")
- files.each { |f|
- assert_describe(mount, f, server)
- }
+ desc = server.describe(mount + file)
}
+ }
- # now let's check that things are being correctly forbidden
- # this is just a map of names and expected results
- {
- "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"],
- ]
+ files.each { |f|
+ assert_describe(mount, f, server)
+ }
+ }
+
+ # now let's check that things are being correctly forbidden
+ # this is just a map of names and expected results
+ {
+ "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}/"
+
+ # run through the map
+ hash.each { |type, ary|
+ ary.each { |sub|
+ host, ip = sub
+
+ case type
+ when :deny
+
+ assert_raise(
+ Puppet::AuthorizationError,
+
+ "Host #{host}, ip #{ip}, allowed #{mount}") {
+ list = server.list(mount, :manage, true, false, host, ip)
}
- }.each { |mount, hash|
- mount = "/#{mount}/"
-
- # run through the map
- hash.each { |type, ary|
- ary.each { |sub|
- host, ip = sub
-
- case type
- when :deny
-
- assert_raise(
- Puppet::AuthorizationError,
-
- "Host #{host}, ip #{ip}, allowed #{mount}") {
- list = server.list(mount, :manage, true, false, host, ip)
- }
- when :allow
- assert_nothing_raised("Host #{host}, ip #{ip}, denied #{mount}") {
- list = server.list(mount, :manage, true, false, host, ip)
- }
- end
- }
+ when :allow
+ assert_nothing_raised("Host #{host}, ip #{ip}, denied #{mount}") {
+ list = server.list(mount, :manage, true, false, host, ip)
}
+ end
}
+ }
+ }
- end
+ end
- # Test that we smoothly handle invalid config files
- def test_configfailures
- # create an example file with each of them
- conffile = tempfile
+ # Test that we smoothly handle invalid config files
+ def test_configfailures
+ # create an example file with each of them
+ conffile = tempfile
- invalidmounts = {
- "noexist" => "[noexist]
- path /this/path/does/not/exist
- allow 192.168.0.*
+ invalidmounts = {
+ "noexist" => "[noexist]
+ path /this/path/does/not/exist
+ allow 192.168.0.*
"
}
- invalidconfigs = [
- "[not valid]
- path /this/path/does/not/exist
- allow 192.168.0.*
+ invalidconfigs = [
+ "[not valid]
+ path /this/path/does/not/exist
+ allow 192.168.0.*
",
"[valid]
- invalidstatement
- path /etc
- allow 192.168.0.*
+ invalidstatement
+ path /etc
+ allow 192.168.0.*
",
"[valid]
- allow 192.168.0.*
+ allow 192.168.0.*
"
]
- invalidmounts.each { |mount, text|
- File.open(conffile, "w") { |f|
- f.print text
- }
+ invalidmounts.each { |mount, text|
+ File.open(conffile, "w") { |f|
+ f.print text
+ }
- # create a server with the file
- server = nil
- assert_nothing_raised {
+ # create a server with the file
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => conffile
- )
- }
+ :Config => conffile
+ )
+ }
- assert_raise(
- Puppet::Network::Handler::FileServerError,
+ assert_raise(
+ Puppet::Network::Handler::FileServerError,
- "Invalid mount was mounted") {
- server.list(mount, :manage)
- }
- }
+ "Invalid mount was mounted") {
+ server.list(mount, :manage)
+ }
+ }
- invalidconfigs.each_with_index { |text, i|
- File.open(conffile, "w") { |f|
- f.print text
- }
+ invalidconfigs.each_with_index { |text, i|
+ File.open(conffile, "w") { |f|
+ f.print text
+ }
- # create a server with the file
- server = nil
+ # create a server with the file
+ server = nil
- assert_raise(
- Puppet::Network::Handler::FileServerError,
+ assert_raise(
+ Puppet::Network::Handler::FileServerError,
- "Invalid config #{i} did not raise error") {
+ "Invalid config #{i} did not raise error") {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => conffile
- )
- }
- }
- end
+ :Config => conffile
+ )
+ }
+ }
+ end
- # verify we reread the config file when it changes
- def test_filereread
- server = nil
+ # verify we reread the config file when it changes
+ def test_filereread
+ server = nil
- conffile = tempfile
- dir = tstdir
+ conffile = tempfile
+ dir = tstdir
- files = mktestfiles(dir)
- File.open(conffile, "w") { |f|
- f.print "# a test config file
+ files = mktestfiles(dir)
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
[thing]
- path #{dir}
- allow test1.domain.com
+ path #{dir}
+ allow test1.domain.com
"
- }
+ }
- # Reset the timeout, so we reload faster
- Puppet[:filetimeout] = 0.5
+ # Reset the timeout, so we reload faster
+ Puppet[:filetimeout] = 0.5
- # start our server with a fast timeout
- assert_nothing_raised {
+ # start our server with a fast timeout
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => false,
+ :Local => false,
- :Config => conffile
- )
- }
+ :Config => conffile
+ )
+ }
- list = nil
- assert_nothing_raised {
+ list = nil
+ assert_nothing_raised {
- list = server.list(
- "/thing/", :manage, false, false,
+ list = server.list(
+ "/thing/", :manage, false, false,
- "test1.domain.com", "127.0.0.1")
- }
- assert(list != "", "List returned nothing in rereard test")
+ "test1.domain.com", "127.0.0.1")
+ }
+ assert(list != "", "List returned nothing in rereard test")
- assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
- }
+ assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
+ }
- sleep 1
- File.open(conffile, "w") { |f|
- f.print "# a test config file
+ sleep 1
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
[thing]
- path #{dir}
- allow test2.domain.com
+ path #{dir}
+ allow test2.domain.com
"
+ }
+
+ assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1")
}
- assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1")
- }
+ assert_nothing_raised {
+ list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
+ }
- assert_nothing_raised {
- list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
- }
+ assert(list != "", "List returned nothing in rereard test")
- assert(list != "", "List returned nothing in rereard test")
+ list = nil
+ end
- list = nil
- end
+ # Verify that we get converted to the right kind of string
+ def test_mountstring
+ mount = nil
+ name = "yaytest"
+ path = tmpdir
+ assert_nothing_raised {
+ mount = Puppet::Network::Handler.fileserver::Mount.new(name, path)
+ }
- # Verify that we get converted to the right kind of string
- def test_mountstring
- mount = nil
- name = "yaytest"
- path = tmpdir
- assert_nothing_raised {
- mount = Puppet::Network::Handler.fileserver::Mount.new(name, path)
- }
+ assert_equal("mount[#{name}]", mount.to_s)
+ end
- assert_equal("mount[#{name}]", mount.to_s)
- end
+ def test_servinglinks
+ # Disable the checking, so changes propagate immediately.
+ Puppet[:filetimeout] = -5
+ server = nil
+ source = tempfile
+ file = File.join(source, "file")
+ link = File.join(source, "link")
+ Dir.mkdir(source)
+ File.open(file, "w") { |f| f.puts "yay" }
+ File.symlink(file, link)
+ assert_nothing_raised {
- def test_servinglinks
- # Disable the checking, so changes propagate immediately.
- Puppet[:filetimeout] = -5
- server = nil
- source = tempfile
- file = File.join(source, "file")
- link = File.join(source, "link")
- Dir.mkdir(source)
- File.open(file, "w") { |f| f.puts "yay" }
- File.symlink(file, link)
- assert_nothing_raised {
+ server = Puppet::Network::Handler.fileserver.new(
- server = Puppet::Network::Handler.fileserver.new(
+ :Local => true,
- :Local => true,
+ :Config => false
+ )
+ }
- :Config => false
- )
- }
+ assert_nothing_raised {
+ server.mount(source, "mount")
+ }
- assert_nothing_raised {
- server.mount(source, "mount")
- }
+ # First describe the link when following
+ results = {}
+ assert_nothing_raised {
+ server.describe("/mount/link", :follow).split("\t").zip(
+ Puppet::Network::Handler.fileserver::CHECKPARAMS
+ ).each { |v,p| results[p] = v }
+ }
- # First describe the link when following
- results = {}
- assert_nothing_raised {
- server.describe("/mount/link", :follow).split("\t").zip(
- Puppet::Network::Handler.fileserver::CHECKPARAMS
- ).each { |v,p| results[p] = v }
- }
+ assert_equal("file", results[:type])
- assert_equal("file", results[:type])
+ # Then not
+ results = {}
+ assert_nothing_raised {
+ server.describe("/mount/link", :manage).split("\t").zip(
+ Puppet::Network::Handler.fileserver::CHECKPARAMS
+ ).each { |v,p| results[p] = v }
+ }
- # Then not
- results = {}
- assert_nothing_raised {
- server.describe("/mount/link", :manage).split("\t").zip(
- Puppet::Network::Handler.fileserver::CHECKPARAMS
- ).each { |v,p| results[p] = v }
- }
+ assert_equal("link", results[:type])
- assert_equal("link", results[:type])
+ results.each { |p,v|
+ assert(v, "#{p} has no value")
+ assert(v != "", "#{p} has no value")
+ }
+ end
+
+ # Test that substitution patterns in the path are exapanded
+ # properly. Disabled, because it was testing too much of the process
+ # and in a non-portable way. This is a thorough enough test that it should
+ # be kept, but it should be done in a way that is clearly portable (e.g.,
+ # no md5 sums of file paths).
+ def test_host_specific
+ client1 = "client1.example.com"
+ client2 = "client2.example.com"
+ ip = "127.0.0.1"
+
+ # Setup a directory hierarchy for the tests
+ fsdir = File.join(tmpdir, "host-specific")
+ @@tmpfiles << fsdir
+ hostdir = File.join(fsdir, "host")
+ fqdndir = File.join(fsdir, "fqdn")
+ client1_hostdir = File.join(hostdir, "client1")
+ client2_fqdndir = File.join(fqdndir, client2)
+ contents = {
+ client1_hostdir => "client1\n",
+ client2_fqdndir => client2 + "\n"
+ }
+ [fsdir, hostdir, fqdndir, client1_hostdir, client2_fqdndir].each { |d| Dir.mkdir(d) }
- results.each { |p,v|
- assert(v, "#{p} has no value")
- assert(v != "", "#{p} has no value")
- }
+ [client1_hostdir, client2_fqdndir].each do |d|
+ File.open(File.join(d, "file.txt"), "w") do |f|
+ f.print contents[d]
+ end
end
-
- # Test that substitution patterns in the path are exapanded
- # properly. Disabled, because it was testing too much of the process
- # and in a non-portable way. This is a thorough enough test that it should
- # be kept, but it should be done in a way that is clearly portable (e.g.,
- # no md5 sums of file paths).
- def test_host_specific
- client1 = "client1.example.com"
- client2 = "client2.example.com"
- ip = "127.0.0.1"
-
- # Setup a directory hierarchy for the tests
- fsdir = File.join(tmpdir, "host-specific")
- @@tmpfiles << fsdir
- hostdir = File.join(fsdir, "host")
- fqdndir = File.join(fsdir, "fqdn")
- client1_hostdir = File.join(hostdir, "client1")
- client2_fqdndir = File.join(fqdndir, client2)
- contents = {
- client1_hostdir => "client1\n",
- client2_fqdndir => client2 + "\n"
- }
- [fsdir, hostdir, fqdndir, client1_hostdir, client2_fqdndir].each { |d| Dir.mkdir(d) }
-
- [client1_hostdir, client2_fqdndir].each do |d|
- File.open(File.join(d, "file.txt"), "w") do |f|
- f.print contents[d]
- end
- end
- conffile = tempfile
- File.open(conffile, "w") do |f|
- f.print("
+ conffile = tempfile
+ File.open(conffile, "w") do |f|
+ f.print("
[host]
path #{hostdir}/%h
allow *
@@ -840,421 +840,421 @@ allow *
path #{fqdndir}/%H
allow *
")
- end
+ end
- server = nil
- assert_nothing_raised {
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler.fileserver.new(
+ server = Puppet::Network::Handler.fileserver.new(
- :Local => true,
+ :Local => true,
- :Config => conffile
- )
- }
+ :Config => conffile
+ )
+ }
- # check that list returns the correct thing for the two clients
- list = nil
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client1, ip)
- }
- assert_equal("/\tfile", list)
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client2, ip)
- }
- assert_equal("", list)
+ # check that list returns the correct thing for the two clients
+ list = nil
+ sfile = "/host/file.txt"
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false, client1, ip)
+ }
+ assert_equal("/\tfile", list)
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false, client2, ip)
+ }
+ assert_equal("", list)
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client1, ip)
- }
- assert_equal("", list)
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client2, ip)
- }
- assert_equal("/\tfile", list)
+ sfile = "/fqdn/file.txt"
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false, client1, ip)
+ }
+ assert_equal("", list)
+ assert_nothing_raised {
+ list = server.list(sfile, :manage, true, false, client2, ip)
+ }
+ assert_equal("/\tfile", list)
- # check describe
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client1, ip).split("\t")
- }
- assert_equal(5, list.size)
- assert_equal("file", list[1])
- md5 = Digest::MD5.hexdigest(contents[client1_hostdir])
- assert_equal("{md5}#{md5}", list[4])
+ # check describe
+ sfile = "/host/file.txt"
+ assert_nothing_raised {
+ list = server.describe(sfile, :manage, client1, ip).split("\t")
+ }
+ assert_equal(5, list.size)
+ assert_equal("file", list[1])
+ md5 = Digest::MD5.hexdigest(contents[client1_hostdir])
+ assert_equal("{md5}#{md5}", list[4])
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client2, ip).split("\t")
- }
- assert_equal([], list)
+ assert_nothing_raised {
+ list = server.describe(sfile, :manage, client2, ip).split("\t")
+ }
+ assert_equal([], list)
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client1, ip).split("\t")
- }
- assert_equal([], list)
+ sfile = "/fqdn/file.txt"
+ assert_nothing_raised {
+ list = server.describe(sfile, :manage, client1, ip).split("\t")
+ }
+ assert_equal([], list)
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client2, ip).split("\t")
- }
- assert_equal(5, list.size)
- assert_equal("file", list[1])
- md5 = Digest::MD5.hexdigest(contents[client2_fqdndir])
- assert_equal("{md5}#{md5}", list[4])
-
- # Check retrieve
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client1, ip).chomp
- }
- assert_equal(contents[client1_hostdir].chomp, list)
+ assert_nothing_raised {
+ list = server.describe(sfile, :manage, client2, ip).split("\t")
+ }
+ assert_equal(5, list.size)
+ assert_equal("file", list[1])
+ md5 = Digest::MD5.hexdigest(contents[client2_fqdndir])
+ assert_equal("{md5}#{md5}", list[4])
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client2, ip).chomp
- }
- assert_equal("", list)
+ # Check retrieve
+ sfile = "/host/file.txt"
+ assert_nothing_raised {
+ list = server.retrieve(sfile, :manage, client1, ip).chomp
+ }
+ assert_equal(contents[client1_hostdir].chomp, list)
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client1, ip).chomp
- }
- assert_equal("", list)
+ assert_nothing_raised {
+ list = server.retrieve(sfile, :manage, client2, ip).chomp
+ }
+ assert_equal("", list)
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client2, ip).chomp
- }
- assert_equal(contents[client2_fqdndir].chomp, list)
- end
+ sfile = "/fqdn/file.txt"
+ assert_nothing_raised {
+ list = server.retrieve(sfile, :manage, client1, ip).chomp
+ }
+ assert_equal("", list)
- # Make sure the 'subdir' method in Mount works.
- def test_mount_subdir
- mount = nil
- base = tempfile
- Dir.mkdir(base)
- subdir = File.join(base, "subdir")
- Dir.mkdir(subdir)
- [base, subdir].each do |d|
- File.open(File.join(d, "file"), "w") { |f| f.puts "bazoo" }
- end
- mount = mkmount(base)
-
- assert_equal(base, mount.subdir, "Did not default to base path")
- assert_equal(subdir, mount.subdir("subdir"), "Did not default to base path")
+ assert_nothing_raised {
+ list = server.retrieve(sfile, :manage, client2, ip).chomp
+ }
+ assert_equal(contents[client2_fqdndir].chomp, list)
+ end
+
+ # Make sure the 'subdir' method in Mount works.
+ def test_mount_subdir
+ mount = nil
+ base = tempfile
+ Dir.mkdir(base)
+ subdir = File.join(base, "subdir")
+ Dir.mkdir(subdir)
+ [base, subdir].each do |d|
+ File.open(File.join(d, "file"), "w") { |f| f.puts "bazoo" }
end
+ mount = mkmount(base)
- # Make sure mounts get correctly marked expandable or not, depending on
- # the path.
- def test_expandable
- name = "yaytest"
- dir = tempfile
- Dir.mkdir(dir)
+ assert_equal(base, mount.subdir, "Did not default to base path")
+ assert_equal(subdir, mount.subdir("subdir"), "Did not default to base path")
+ end
- mount = mkmount
- assert_nothing_raised {
- mount.path = dir
- }
+ # Make sure mounts get correctly marked expandable or not, depending on
+ # the path.
+ def test_expandable
+ name = "yaytest"
+ dir = tempfile
+ Dir.mkdir(dir)
- assert(! mount.expandable?, "Mount incorrectly called expandable")
+ mount = mkmount
+ assert_nothing_raised {
+ mount.path = dir
+ }
- assert_nothing_raised {
- mount.path = "/dir/a%a"
- }
- assert(mount.expandable?, "Mount not called expandable")
+ assert(! mount.expandable?, "Mount incorrectly called expandable")
- # This isn't a valid replacement pattern, so it should throw an error
- # because the dir doesn't exist
- assert_raise(Puppet::Network::Handler::FileServerError) {
- mount.path = "/dir/a%"
- }
+ assert_nothing_raised {
+ mount.path = "/dir/a%a"
+ }
+ assert(mount.expandable?, "Mount not called expandable")
- # Now send it back to a normal path
- assert_nothing_raised {
- mount.path = dir
- }
- # Make sure it got reverted
- assert(! mount.expandable?, "Mount incorrectly called expandable")
+ # This isn't a valid replacement pattern, so it should throw an error
+ # because the dir doesn't exist
+ assert_raise(Puppet::Network::Handler::FileServerError) {
+ mount.path = "/dir/a%"
+ }
+ # Now send it back to a normal path
+ assert_nothing_raised {
+ mount.path = dir
+ }
+ # Make sure it got reverted
+ assert(! mount.expandable?, "Mount incorrectly called expandable")
- end
- def test_mount_expand
- mount = mkmount
-
- check = proc do |client, pattern, repl|
- path = "/my/#{pattern}/file"
- assert_equal("/my/#{repl}/file", mount.expand(path, client))
- end
-
- # Do a round of checks with a fake client
- client = "host.domain.com"
- {"%h" => "host", # Short name
- "%H" => client, # Full name
- "%d" => "domain.com", # domain
- "%%" => "%", # escape
- "%o" => "%o" # other
- }.each do |pat, repl|
- result = check.call(client, pat, repl)
- end
-
- # Now, check that they use Facter info
- client = nil
- Facter.stubs(:value).with { |v| v.to_s == "hostname" }.returns("myhost")
- Facter.stubs(:value).with { |v| v.to_s == "domain" }.returns("mydomain.com")
-
-
- Facter.stubs(:to_hash).returns(
- {
- :ipaddress => "127.0.0.1",
- :hostname => "myhost",
- :domain => "mydomain.com",
-
- })
-
-
- {"%h" => "myhost", # Short name
- "%H" => "myhost.mydomain.com", # Full name
- "%d" => "mydomain.com", # domain
- "%%" => "%", # escape
- "%o" => "%o" # other
- }.each do |pat, repl|
- check.call(client, pat, repl)
- end
+ end
- end
+ def test_mount_expand
+ mount = mkmount
- # Test that the fileserver expands the %h and %d things.
- def test_fileserver_expansion
- server = nil
- assert_nothing_raised {
+ check = proc do |client, pattern, repl|
+ path = "/my/#{pattern}/file"
+ assert_equal("/my/#{repl}/file", mount.expand(path, client))
+ end
- server = Puppet::Network::Handler.fileserver.new(
+ # Do a round of checks with a fake client
+ client = "host.domain.com"
+ {"%h" => "host", # Short name
+ "%H" => client, # Full name
+ "%d" => "domain.com", # domain
+ "%%" => "%", # escape
+ "%o" => "%o" # other
+ }.each do |pat, repl|
+ result = check.call(client, pat, repl)
+ end
- :Local => true,
+ # Now, check that they use Facter info
+ client = nil
+ Facter.stubs(:value).with { |v| v.to_s == "hostname" }.returns("myhost")
+ Facter.stubs(:value).with { |v| v.to_s == "domain" }.returns("mydomain.com")
- :Config => false
- )
- }
- dir = tempfile
+ Facter.stubs(:to_hash).returns(
+ {
+ :ipaddress => "127.0.0.1",
+ :hostname => "myhost",
+ :domain => "mydomain.com",
- # When mocks attack, part 2
- kernel_fact = Facter.value(:kernel)
+ })
- ip = '127.0.0.1'
+ {"%h" => "myhost", # Short name
+ "%H" => "myhost.mydomain.com", # Full name
+ "%d" => "mydomain.com", # domain
+ "%%" => "%", # escape
+ "%o" => "%o" # other
+ }.each do |pat, repl|
+ check.call(client, pat, repl)
+ end
- Facter.stubs(:to_hash).returns(
- {
- :kernel => kernel_fact,
- :ipaddress => "127.0.0.1",
- :hostname => "myhost",
- :domain => "mydomain.com",
+ end
- })
+ # Test that the fileserver expands the %h and %d things.
+ def test_fileserver_expansion
+ server = nil
+ assert_nothing_raised {
- Dir.mkdir(dir)
- host = "myhost.mydomain.com"
- {
- "%H" => "myhost.mydomain.com", "%h" => "myhost", "%d" => "mydomain.com"
- }.each do |pattern, string|
- file = File.join(dir, string)
- mount = File.join(dir, pattern)
- File.open(file, "w") do |f| f.puts "yayness: #{string}" end
- name = "name"
- obj = nil
- assert_nothing_raised {
- obj = server.mount(mount, name)
- }
- obj.allow "*"
+ server = Puppet::Network::Handler.fileserver.new(
- ret = nil
- assert_nothing_raised do
- ret = server.list("/name", :manage, false, false, host, ip)
- end
+ :Local => true,
- assert_equal("/\tfile", ret)
+ :Config => false
+ )
+ }
- assert_nothing_raised do
- ret = server.describe("/name", :manage, host, ip)
- end
- assert(ret =~ /\tfile\t/, "Did not get valid a description (#{ret.inspect})")
+ dir = tempfile
- assert_nothing_raised do
- ret = server.retrieve("/name", :manage, host, ip)
- end
+ # When mocks attack, part 2
+ kernel_fact = Facter.value(:kernel)
- assert_equal(ret, File.read(file))
+ ip = '127.0.0.1'
- server.umount(name)
- File.unlink(file)
- end
+ Facter.stubs(:to_hash).returns(
+ {
+ :kernel => kernel_fact,
+ :ipaddress => "127.0.0.1",
+ :hostname => "myhost",
+ :domain => "mydomain.com",
+
+ })
+
+ Dir.mkdir(dir)
+ host = "myhost.mydomain.com"
+ {
+ "%H" => "myhost.mydomain.com", "%h" => "myhost", "%d" => "mydomain.com"
+ }.each do |pattern, string|
+ file = File.join(dir, string)
+ mount = File.join(dir, pattern)
+ File.open(file, "w") do |f| f.puts "yayness: #{string}" end
+ name = "name"
+ obj = nil
+ assert_nothing_raised {
+ obj = server.mount(mount, name)
+ }
+ obj.allow "*"
+
+ ret = nil
+ assert_nothing_raised do
+ ret = server.list("/name", :manage, false, false, host, ip)
+ end
+
+ assert_equal("/\tfile", ret)
+
+ assert_nothing_raised do
+ ret = server.describe("/name", :manage, host, ip)
+ end
+ assert(ret =~ /\tfile\t/, "Did not get valid a description (#{ret.inspect})")
+
+ assert_nothing_raised do
+ ret = server.retrieve("/name", :manage, host, ip)
+ end
+
+ assert_equal(ret, File.read(file))
+
+ server.umount(name)
+
+ File.unlink(file)
end
+ end
+
+ # Test the default modules fileserving
+ def test_modules_default
+ moddir = tempfile
+ Dir.mkdir(moddir)
+ mounts = {}
+ Puppet[:modulepath] = moddir
+
+ mods = %w{green red}.collect do |name|
+ path = File::join(moddir, name, Puppet::Module::FILES)
+ FileUtils::mkdir_p(path)
+ if name == "green"
+ file = File::join(path, "test.txt")
+ File::open(file, "w") { |f| f.print name }
+ end
- # Test the default modules fileserving
- def test_modules_default
- moddir = tempfile
- Dir.mkdir(moddir)
- mounts = {}
- Puppet[:modulepath] = moddir
-
- mods = %w{green red}.collect do |name|
- path = File::join(moddir, name, Puppet::Module::FILES)
- FileUtils::mkdir_p(path)
- if name == "green"
- file = File::join(path, "test.txt")
- File::open(file, "w") { |f| f.print name }
- end
-
- Puppet::Module::find(name)
- end
+ Puppet::Module::find(name)
+ end
- conffile = tempfile
+ conffile = tempfile
- File.open(conffile, "w") { |f| f.puts "# a test config file" }
+ File.open(conffile, "w") { |f| f.puts "# a test config file" }
- # create a server with the file
- server = nil
- assert_nothing_raised {
+ # create a server with the file
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler::FileServer.new(
+ server = Puppet::Network::Handler::FileServer.new(
- :Local => false ,
+ :Local => false ,
- :Config => conffile
- )
- }
+ :Config => conffile
+ )
+ }
- mods.each do |mod|
- mount = "/#{mod.name}/"
- list = nil
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
- list = list.split("\n")
- if mod.name == "green"
- assert_equal(2, list.size)
- assert_equal("/\tdirectory", list[0])
- assert_equal("/test.txt\tfile", list[1])
- else
- assert_equal(1, list.size)
- assert_equal("/\tdirectory", list[0])
- end
-
- assert_nothing_raised("Host 'allow' denied #{mount}") {
- server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
- }
- end
+ mods.each do |mod|
+ mount = "/#{mod.name}/"
+ list = nil
+ assert_nothing_raised {
+ list = server.list(mount, :manage, true, false)
+ }
+ list = list.split("\n")
+ if mod.name == "green"
+ assert_equal(2, list.size)
+ assert_equal("/\tdirectory", list[0])
+ assert_equal("/test.txt\tfile", list[1])
+ else
+ assert_equal(1, list.size)
+ assert_equal("/\tdirectory", list[0])
+ end
+
+ assert_nothing_raised("Host 'allow' denied #{mount}") {
+ server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
+ }
end
+ end
- # Test that configuring deny/allow for modules works
- def test_modules_config
- moddir = tempfile
- Dir.mkdir(moddir)
- mounts = {}
- Puppet[:modulepath] = moddir
+ # Test that configuring deny/allow for modules works
+ def test_modules_config
+ moddir = tempfile
+ Dir.mkdir(moddir)
+ mounts = {}
+ Puppet[:modulepath] = moddir
- path = File::join(moddir, "amod", Puppet::Module::FILES)
- file = File::join(path, "test.txt")
- FileUtils::mkdir_p(path)
- File::open(file, "w") { |f| f.print "Howdy" }
+ path = File::join(moddir, "amod", Puppet::Module::FILES)
+ file = File::join(path, "test.txt")
+ FileUtils::mkdir_p(path)
+ File::open(file, "w") { |f| f.print "Howdy" }
- mod = Puppet::Module::find("amod")
+ mod = Puppet::Module::find("amod")
- conffile = tempfile
- @@tmpfiles << conffile
+ conffile = tempfile
+ @@tmpfiles << conffile
- File.open(conffile, "w") { |f|
- f.print "# a test config file
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
[modules]
- path #{basedir}/thing
- allow 192.168.0.*
+ path #{basedir}/thing
+ allow 192.168.0.*
"
- }
+ }
- # create a server with the file
- server = nil
- assert_nothing_raised {
+ # create a server with the file
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::Handler::FileServer.new(
+ server = Puppet::Network::Handler::FileServer.new(
- :Local => false,
+ :Local => false,
- :Config => conffile
- )
- }
+ :Config => conffile
+ )
+ }
- list = nil
- mount = "/#{mod.name}/"
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
+ list = nil
+ mount = "/#{mod.name}/"
+ assert_nothing_raised {
+ list = server.list(mount, :manage, true, false)
+ }
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
- server.describe(mount + file)
- }
- }
+ assert_nothing_raised {
+ list.split("\n").each { |line|
+ file, type = line.split("\t")
+ server.describe(mount + file)
+ }
+ }
- assert_describe(mount, file, server)
+ assert_describe(mount, file, server)
- # now let's check that things are being correctly forbidden
+ # now let's check that things are being correctly forbidden
- assert_raise(
- Puppet::AuthorizationError,
+ assert_raise(
+ Puppet::AuthorizationError,
- "Host 'deny' allowed #{mount}") {
- server.list(mount, :manage, true, false, 'deny.example.com', "192.168.1.1")
- }
- assert_nothing_raised("Host 'allow' denied #{mount}") {
- server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
- }
- end
+ "Host 'deny' allowed #{mount}") {
+ server.list(mount, :manage, true, false, 'deny.example.com', "192.168.1.1")
+ }
+ assert_nothing_raised("Host 'allow' denied #{mount}") {
+ server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
+ }
+ end
- # Make sure we successfully throw errors -- someone ran into this with
- # 0.22.4.
- def test_failures
- # create a server with the file
- server = nil
+ # Make sure we successfully throw errors -- someone ran into this with
+ # 0.22.4.
+ def test_failures
+ # create a server with the file
+ server = nil
- config = tempfile
- [
- "[this is invalid]\nallow one.two.com", # invalid name
- "[valid]\nallow *.testing something.com", # invalid allow
- "[valid]\nallow one.two.com\ndeny *.testing something.com", # invalid deny
- ].each do |failer|
- File.open(config, "w") { |f| f.puts failer }
- assert_raise(Puppet::Network::Handler::FileServerError, "Did not fail on #{failer.inspect}") {
+ config = tempfile
+ [
+ "[this is invalid]\nallow one.two.com", # invalid name
+ "[valid]\nallow *.testing something.com", # invalid allow
+ "[valid]\nallow one.two.com\ndeny *.testing something.com", # invalid deny
+ ].each do |failer|
+ File.open(config, "w") { |f| f.puts failer }
+ assert_raise(Puppet::Network::Handler::FileServerError, "Did not fail on #{failer.inspect}") {
- server = Puppet::Network::Handler::FileServer.new(
+ server = Puppet::Network::Handler::FileServer.new(
- :Local => false,
+ :Local => false,
- :Config => config
- )
- }
- end
+ :Config => config
+ )
+ }
end
-
- def test_can_start_without_configuration
- Puppet[:fileserverconfig] = tempfile
- assert_nothing_raised("Could not create fileserver when configuration is absent") do
- server = Puppet::Network::Handler::FileServer.new(
- :Local => false
- )
- end
+ end
+
+ def test_can_start_without_configuration
+ Puppet[:fileserverconfig] = tempfile
+ assert_nothing_raised("Could not create fileserver when configuration is absent") do
+ server = Puppet::Network::Handler::FileServer.new(
+ :Local => false
+ )
end
+ end
- def test_creates_default_mounts_when_no_configuration_is_available
- Puppet[:fileserverconfig] = tempfile
- server = Puppet::Network::Handler::FileServer.new(:Local => false)
+ def test_creates_default_mounts_when_no_configuration_is_available
+ Puppet[:fileserverconfig] = tempfile
+ server = Puppet::Network::Handler::FileServer.new(:Local => false)
- assert(server.mounted?("plugins"), "Did not create default plugins mount when missing configuration file")
- assert(server.mounted?("modules"), "Did not create default modules mount when missing configuration file")
- end
+ assert(server.mounted?("plugins"), "Did not create default plugins mount when missing configuration file")
+ assert(server.mounted?("modules"), "Did not create default modules mount when missing configuration file")
+ end
end
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index a802b0a0a..81869ac06 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -6,89 +6,89 @@ require 'puppettest'
require 'puppet/network/handler/master'
class TestMaster < Test::Unit::TestCase
- include PuppetTest::ServerTest
+ include PuppetTest::ServerTest
- def setup
- super
- @master = Puppet::Network::Handler.master.new(:Manifest => tempfile)
+ def setup
+ super
+ @master = Puppet::Network::Handler.master.new(:Manifest => tempfile)
- @catalog = stub 'catalog', :extract => ""
- Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
- end
+ @catalog = stub 'catalog', :extract => ""
+ Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
+ end
- def teardown
- super
- Puppet::Util::Cacher.expire
- end
+ def teardown
+ super
+ Puppet::Util::Cacher.expire
+ end
- def test_freshness_is_always_now
- now1 = mock 'now1'
- Time.stubs(:now).returns(now1)
+ def test_freshness_is_always_now
+ now1 = mock 'now1'
+ Time.stubs(:now).returns(now1)
- now1.expects(:to_i).returns 10
+ now1.expects(:to_i).returns 10
- assert_equal(@master.freshness, 10, "Did not return current time as freshness")
- end
+ assert_equal(@master.freshness, 10, "Did not return current time as freshness")
+ end
- def test_hostname_is_used_if_client_is_missing
- @master.expects(:decode_facts).returns("hostname" => "yay")
- Puppet::Node::Facts.expects(:new).with { |name, facts| name == "yay" }.returns(stub('facts', :save => nil))
+ def test_hostname_is_used_if_client_is_missing
+ @master.expects(:decode_facts).returns("hostname" => "yay")
+ Puppet::Node::Facts.expects(:new).with { |name, facts| name == "yay" }.returns(stub('facts', :save => nil))
- @master.getconfig("facts")
- end
+ @master.getconfig("facts")
+ end
- def test_facts_are_saved
- facts = mock('facts')
- Puppet::Node::Facts.expects(:new).returns(facts)
- facts.expects(:save)
+ def test_facts_are_saved
+ facts = mock('facts')
+ Puppet::Node::Facts.expects(:new).returns(facts)
+ facts.expects(:save)
- @master.stubs(:decode_facts)
+ @master.stubs(:decode_facts)
- @master.getconfig("facts", "yaml", "foo.com")
- end
+ @master.getconfig("facts", "yaml", "foo.com")
+ end
- def test_catalog_is_used_for_compiling
- facts = stub('facts', :save => nil)
- Puppet::Node::Facts.stubs(:new).returns(facts)
+ def test_catalog_is_used_for_compiling
+ facts = stub('facts', :save => nil)
+ Puppet::Node::Facts.stubs(:new).returns(facts)
- @master.stubs(:decode_facts)
+ @master.stubs(:decode_facts)
- Puppet::Resource::Catalog.expects(:find).with("foo.com").returns(@catalog)
+ Puppet::Resource::Catalog.expects(:find).with("foo.com").returns(@catalog)
- @master.getconfig("facts", "yaml", "foo.com")
- end
+ @master.getconfig("facts", "yaml", "foo.com")
+ end
end
class TestMasterFormats < Test::Unit::TestCase
- def setup
- @facts = stub('facts', :save => nil)
- Puppet::Node::Facts.stubs(:new).returns(@facts)
+ def setup
+ @facts = stub('facts', :save => nil)
+ Puppet::Node::Facts.stubs(:new).returns(@facts)
- @master = Puppet::Network::Handler.master.new(:Code => "")
- @master.stubs(:decode_facts)
+ @master = Puppet::Network::Handler.master.new(:Code => "")
+ @master.stubs(:decode_facts)
- @catalog = stub 'catalog', :extract => ""
- Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
- end
+ @catalog = stub 'catalog', :extract => ""
+ Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
+ end
- def test_marshal_can_be_used
- @catalog.expects(:extract).returns "myextract"
+ def test_marshal_can_be_used
+ @catalog.expects(:extract).returns "myextract"
- Marshal.expects(:dump).with("myextract").returns "eh"
+ Marshal.expects(:dump).with("myextract").returns "eh"
- @master.getconfig("facts", "marshal", "foo.com")
- end
+ @master.getconfig("facts", "marshal", "foo.com")
+ end
- def test_yaml_can_be_used
- extract = mock 'extract'
- @catalog.expects(:extract).returns extract
+ def test_yaml_can_be_used
+ extract = mock 'extract'
+ @catalog.expects(:extract).returns extract
- extract.expects(:to_yaml).returns "myaml"
+ extract.expects(:to_yaml).returns "myaml"
- @master.getconfig("facts", "yaml", "foo.com")
- end
+ @master.getconfig("facts", "yaml", "foo.com")
+ end
- def test_failure_when_non_yaml_or_marshal_is_used
- assert_raise(RuntimeError) { @master.getconfig("facts", "blah", "foo.com") }
- end
+ def test_failure_when_non_yaml_or_marshal_is_used
+ assert_raise(RuntimeError) { @master.getconfig("facts", "blah", "foo.com") }
+ end
end
diff --git a/test/network/handler/report.rb b/test/network/handler/report.rb
index ed7a96f57..590dcdb13 100755
--- a/test/network/handler/report.rb
+++ b/test/network/handler/report.rb
@@ -7,77 +7,77 @@ require 'puppet/network/handler/report'
require 'puppettest/reporttesting'
class TestReportServer < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::Reporttesting
-
- Report = Puppet::Network::Handler.report
- Puppet::Util.logmethods(self)
-
- def mkserver
- server = nil
- assert_nothing_raised {
- server = Puppet::Network::Handler.report.new
- }
- server
- end
-
- def mkclient(server = nil)
- server ||= mkserver
- client = nil
- assert_nothing_raised {
- client = Puppet::Network::Client.report.new(:Report => server)
- }
-
- client
- end
-
- def test_process
- server = Puppet::Network::Handler.report.new
-
- # We have to run multiple reports to make sure there's no conflict
- reports = []
- $run = []
- 2.times do |i|
- name = "processtest#{i}"
- reports << name
-
- Report.newreport(name) do
- def process
- $run << self.report_name
- end
- end
+ include PuppetTest
+ include PuppetTest::Reporttesting
+
+ Report = Puppet::Network::Handler.report
+ Puppet::Util.logmethods(self)
+
+ def mkserver
+ server = nil
+ assert_nothing_raised {
+ server = Puppet::Network::Handler.report.new
+ }
+ server
+ end
+
+ def mkclient(server = nil)
+ server ||= mkserver
+ client = nil
+ assert_nothing_raised {
+ client = Puppet::Network::Client.report.new(:Report => server)
+ }
+
+ client
+ end
+
+ def test_process
+ server = Puppet::Network::Handler.report.new
+
+ # We have to run multiple reports to make sure there's no conflict
+ reports = []
+ $run = []
+ 2.times do |i|
+ name = "processtest#{i}"
+ reports << name
+
+ Report.newreport(name) do
+ def process
+ $run << self.report_name
end
- Puppet[:reports] = reports.collect { |r| r.to_s }.join(",")
-
- report = fakereport
+ end
+ end
+ Puppet[:reports] = reports.collect { |r| r.to_s }.join(",")
- retval = nil
- assert_nothing_raised {
- retval = server.send(:process, YAML.dump(report))
- }
+ report = fakereport
- reports.each do |name|
- assert($run.include?(name.intern), "Did not run #{name}")
- end
+ retval = nil
+ assert_nothing_raised {
+ retval = server.send(:process, YAML.dump(report))
+ }
- # Now make sure our server doesn't die on missing reports
- Puppet[:reports] = "fakereport"
- assert_nothing_raised {
- retval = server.send(:process, YAML.dump(report))
- }
+ reports.each do |name|
+ assert($run.include?(name.intern), "Did not run #{name}")
end
- def test_reports
- Puppet[:reports] = "myreport"
+ # Now make sure our server doesn't die on missing reports
+ Puppet[:reports] = "fakereport"
+ assert_nothing_raised {
+ retval = server.send(:process, YAML.dump(report))
+ }
+ end
- # Create a server
- server = Puppet::Network::Handler.report.new
+ def test_reports
+ Puppet[:reports] = "myreport"
- {"myreport" => ["myreport"],
- " fake, another, yay " => ["fake", "another", "yay"]
- }.each do |str, ary|
- Puppet[:reports] = str
- assert_equal(ary, server.send(:reports))
- end
+ # Create a server
+ server = Puppet::Network::Handler.report.new
+
+ {"myreport" => ["myreport"],
+ " fake, another, yay " => ["fake", "another", "yay"]
+ }.each do |str, ary|
+ Puppet[:reports] = str
+ assert_equal(ary, server.send(:reports))
end
+ end
end
diff --git a/test/network/handler/runner.rb b/test/network/handler/runner.rb
index 6bf783b6f..396568b29 100755
--- a/test/network/handler/runner.rb
+++ b/test/network/handler/runner.rb
@@ -6,15 +6,15 @@ require 'puppettest'
require 'puppet/network/handler/runner'
class TestHandlerRunner < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def test_it_calls_agent_runner
- runner = mock 'runner'
- Puppet::Run.expects(:new).with(:tags => "mytags", :ignoreschedules => true, :background => false).returns runner
- runner.expects(:run)
- runner.expects(:status).returns "yay"
+ def test_it_calls_agent_runner
+ runner = mock 'runner'
+ Puppet::Run.expects(:new).with(:tags => "mytags", :ignoreschedules => true, :background => false).returns runner
+ runner.expects(:run)
+ runner.expects(:status).returns "yay"
- assert_equal("yay", Puppet::Network::Handler.runner.new.run("mytags", true, true))
- end
+ assert_equal("yay", Puppet::Network::Handler.runner.new.run("mytags", true, true))
+ end
end
diff --git a/test/network/rights.rb b/test/network/rights.rb
index 80d6ceafe..df032b5a9 100755
--- a/test/network/rights.rb
+++ b/test/network/rights.rb
@@ -6,35 +6,35 @@ require 'puppettest'
require 'puppet/network/rights'
class TestRights < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def setup
- super
- @store = Puppet::Network::Rights.new
- end
+ def setup
+ super
+ @store = Puppet::Network::Rights.new
+ end
- def test_rights
- assert_raise(ArgumentError, "Did not fail on unknown right") {
- @store.allowed?(:write, "host.madstop.com", "0.0.0.0")
- }
+ def test_rights
+ assert_raise(ArgumentError, "Did not fail on unknown right") {
+ @store.allowed?(:write, "host.madstop.com", "0.0.0.0")
+ }
- assert_nothing_raised {
- @store.newright(:write)
- }
+ assert_nothing_raised {
+ @store.newright(:write)
+ }
- assert(
- ! @store.allowed?(:write, "host.madstop.com", "0.0.0.0"),
+ assert(
+ ! @store.allowed?(:write, "host.madstop.com", "0.0.0.0"),
- "Defaulted to allowing access")
+ "Defaulted to allowing access")
- assert_nothing_raised {
- @store[:write].info "This is a log message"
- }
+ assert_nothing_raised {
+ @store[:write].info "This is a log message"
+ }
- assert_logged(:info, /This is a log message/, "did not log from Rights")
- end
+ assert_logged(:info, /This is a log message/, "did not log from Rights")
+ end
end
diff --git a/test/network/server/mongrel_test.rb b/test/network/server/mongrel_test.rb
index 4414097ab..7bb2df150 100755
--- a/test/network/server/mongrel_test.rb
+++ b/test/network/server/mongrel_test.rb
@@ -6,100 +6,100 @@ require 'puppettest'
require 'mocha'
class TestMongrelServer < PuppetTest::TestCase
- confine "Missing mongrel" => Puppet.features.mongrel?
+ confine "Missing mongrel" => Puppet.features.mongrel?
+
+ include PuppetTest::ServerTest
+
+ def mkserver(handlers = nil)
+ handlers ||= { :Status => nil }
+ mongrel = Puppet::Network::HTTPServer::Mongrel.new(handlers)
+ end
+
+ # Make sure client info is correctly extracted.
+ def test_client_info
+ obj = Object.new
+ obj.singleton_class.send(:attr_accessor, :params)
+ params = {}
+ obj.params = params
+
+ mongrel = mkserver
+
+ ip = Facter.value(:ipaddress)
+ params["REMOTE_ADDR"] = ip
+ params[Puppet[:ssl_client_header]] = ""
+ params[Puppet[:ssl_client_verify_header]] = "failure"
+ info = nil
+ Resolv.expects(:getname).with(ip).returns("host.domain.com").times(4)
+ assert_nothing_raised("Could not call client_info") do
+ info = mongrel.send(:client_info, obj)
+ end
+ assert(! info.authenticated?, "Client info object was marked valid even though headers were missing")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
+
+ assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
+
+ # Now pass the X-Forwarded-For header and check it is preferred over REMOTE_ADDR
+ params["REMOTE_ADDR"] = '127.0.0.1'
+ params["HTTP_X_FORWARDED_FOR"] = ip
+ info = nil
+ assert_nothing_raised("Could not call client_info") do
+ info = mongrel.send(:client_info, obj)
+ end
+ assert(! info.authenticated?, "Client info object was marked valid even though headers were missing")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
- include PuppetTest::ServerTest
+ assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
- def mkserver(handlers = nil)
- handlers ||= { :Status => nil }
- mongrel = Puppet::Network::HTTPServer::Mongrel.new(handlers)
+ # Now add a valid auth header.
+ params["REMOTE_ADDR"] = ip
+ params["HTTP_X_FORWARDED_FOR"] = nil
+ params[Puppet[:ssl_client_header]] = "/CN=host.domain.com"
+ assert_nothing_raised("Could not call client_info") do
+ info = mongrel.send(:client_info, obj)
+ end
+ assert(! info.authenticated?, "Client info object was marked valid even though the verify header was fals")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
+ assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
+
+ # Now change the verify header to be true
+ params[Puppet[:ssl_client_verify_header]] = "SUCCESS"
+ assert_nothing_raised("Could not call client_info") do
+ info = mongrel.send(:client_info, obj)
end
- # Make sure client info is correctly extracted.
- def test_client_info
- obj = Object.new
- obj.singleton_class.send(:attr_accessor, :params)
- params = {}
- obj.params = params
-
- mongrel = mkserver
-
- ip = Facter.value(:ipaddress)
- params["REMOTE_ADDR"] = ip
- params[Puppet[:ssl_client_header]] = ""
- params[Puppet[:ssl_client_verify_header]] = "failure"
- info = nil
- Resolv.expects(:getname).with(ip).returns("host.domain.com").times(4)
- assert_nothing_raised("Could not call client_info") do
- info = mongrel.send(:client_info, obj)
- end
- assert(! info.authenticated?, "Client info object was marked valid even though headers were missing")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
-
- assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
-
- # Now pass the X-Forwarded-For header and check it is preferred over REMOTE_ADDR
- params["REMOTE_ADDR"] = '127.0.0.1'
- params["HTTP_X_FORWARDED_FOR"] = ip
- info = nil
- assert_nothing_raised("Could not call client_info") do
- info = mongrel.send(:client_info, obj)
- end
- assert(! info.authenticated?, "Client info object was marked valid even though headers were missing")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
-
- assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
-
- # Now add a valid auth header.
- params["REMOTE_ADDR"] = ip
- params["HTTP_X_FORWARDED_FOR"] = nil
- params[Puppet[:ssl_client_header]] = "/CN=host.domain.com"
- assert_nothing_raised("Could not call client_info") do
- info = mongrel.send(:client_info, obj)
- end
- assert(! info.authenticated?, "Client info object was marked valid even though the verify header was fals")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
- assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
-
- # Now change the verify header to be true
- params[Puppet[:ssl_client_verify_header]] = "SUCCESS"
- assert_nothing_raised("Could not call client_info") do
- info = mongrel.send(:client_info, obj)
- end
-
- assert(info.authenticated?, "Client info object was not marked valid even though all headers were correct")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
- assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
-
- # Now try it with a different header name
- params.delete(Puppet[:ssl_client_header])
- Puppet[:ssl_client_header] = "header_testing"
- params["header_testing"] = "/CN=other.domain.com"
- info = nil
- assert_nothing_raised("Could not call client_info with other header") do
- info = mongrel.send(:client_info, obj)
- end
-
- assert(info.authenticated?, "Client info object was not marked valid even though the header was present")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
- assert_equal("other.domain.com", info.name, "Did not copy over hostname correctly")
-
- # Now make sure it's considered invalid without that header
- params.delete("header_testing")
- info = nil
- assert_nothing_raised("Could not call client_info with no header") do
- info = mongrel.send(:client_info, obj)
- end
-
- assert(! info.authenticated?, "Client info object was marked valid without header")
- assert_equal(ip, info.ip, "Did not copy over ip correctly")
- assert_equal(Resolv.getname(ip), info.name, "Did not look up hostname correctly")
+ assert(info.authenticated?, "Client info object was not marked valid even though all headers were correct")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
+ assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
+
+ # Now try it with a different header name
+ params.delete(Puppet[:ssl_client_header])
+ Puppet[:ssl_client_header] = "header_testing"
+ params["header_testing"] = "/CN=other.domain.com"
+ info = nil
+ assert_nothing_raised("Could not call client_info with other header") do
+ info = mongrel.send(:client_info, obj)
end
- def test_daemonize
- mongrel = mkserver
+ assert(info.authenticated?, "Client info object was not marked valid even though the header was present")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
+ assert_equal("other.domain.com", info.name, "Did not copy over hostname correctly")
- assert(mongrel.respond_to?(:daemonize), "Mongrel server does not respond to daemonize")
+ # Now make sure it's considered invalid without that header
+ params.delete("header_testing")
+ info = nil
+ assert_nothing_raised("Could not call client_info with no header") do
+ info = mongrel.send(:client_info, obj)
end
+
+ assert(! info.authenticated?, "Client info object was marked valid without header")
+ assert_equal(ip, info.ip, "Did not copy over ip correctly")
+ assert_equal(Resolv.getname(ip), info.name, "Did not look up hostname correctly")
+ end
+
+ def test_daemonize
+ mongrel = mkserver
+
+ assert(mongrel.respond_to?(:daemonize), "Mongrel server does not respond to daemonize")
+ end
end
diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb
index cdc682043..e203894d9 100755
--- a/test/network/server/webrick.rb
+++ b/test/network/server/webrick.rb
@@ -7,122 +7,122 @@ require 'puppet/network/http_server/webrick'
require 'mocha'
class TestWebrickServer < Test::Unit::TestCase
- include PuppetTest::ServerTest
+ include PuppetTest::ServerTest
- def setup
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- super
- end
+ def setup
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ super
+ end
- def teardown
- super
- Puppet::Network::HttpPool.clear_http_instances
- end
+ def teardown
+ super
+ Puppet::Network::HttpPool.clear_http_instances
+ end
- # Make sure we can create a server, and that it knows how to create its
- # certs by default.
- def test_basics
- server = nil
- assert_raise(Puppet::Error, "server succeeded with no cert") do
+ # Make sure we can create a server, and that it knows how to create its
+ # certs by default.
+ def test_basics
+ server = nil
+ assert_raise(Puppet::Error, "server succeeded with no cert") do
- server = Puppet::Network::HTTPServer::WEBrick.new(
+ server = Puppet::Network::HTTPServer::WEBrick.new(
- :Port => @@port,
+ :Port => @@port,
- :Handlers => {
- :Status => nil
- }
- )
- end
+ :Handlers => {
+ :Status => nil
+ }
+ )
+ end
- assert_nothing_raised("Could not create simple server") do
+ assert_nothing_raised("Could not create simple server") do
- server = Puppet::Network::HTTPServer::WEBrick.new(
+ server = Puppet::Network::HTTPServer::WEBrick.new(
- :Port => @@port,
+ :Port => @@port,
- :Handlers => {
- :CA => {}, # so that certs autogenerate
- :Status => nil
- }
- )
- end
+ :Handlers => {
+ :CA => {}, # so that certs autogenerate
+ :Status => nil
+ }
+ )
+ end
- assert(server, "did not create server")
+ assert(server, "did not create server")
- assert(server.cert, "did not retrieve cert")
- end
+ assert(server.cert, "did not retrieve cert")
+ end
- # test that we can connect to the server
- # we have to use fork here, because we apparently can't use threads
- # to talk to other threads
- def test_connect_with_fork
- Puppet[:autosign] = true
- serverpid, server = mk_status_server
+ # test that we can connect to the server
+ # we have to use fork here, because we apparently can't use threads
+ # to talk to other threads
+ def test_connect_with_fork
+ Puppet[:autosign] = true
+ serverpid, server = mk_status_server
- # create a status client, and verify it can talk
- client = mk_status_client
+ # create a status client, and verify it can talk
+ client = mk_status_client
- assert(client.cert, "did not get cert for client")
+ assert(client.cert, "did not get cert for client")
- retval = nil
- assert_nothing_raised("Could not connect to server") {
- retval = client.status
- }
- assert_equal(1, retval)
- end
+ retval = nil
+ assert_nothing_raised("Could not connect to server") {
+ retval = client.status
+ }
+ assert_equal(1, retval)
+ end
- def mk_status_client
- client = nil
+ def mk_status_client
+ client = nil
- assert_nothing_raised {
+ assert_nothing_raised {
- client = Puppet::Network::Client.status.new(
+ client = Puppet::Network::Client.status.new(
- :Server => "localhost",
+ :Server => "localhost",
- :Port => @@port
- )
- }
- client
- end
-
- def mk_status_server
- server = nil
- Puppet[:certdnsnames] = "localhost"
- assert_nothing_raised {
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
+ :Port => @@port
+ )
+ }
+ client
+ end
+
+ def mk_status_server
+ server = nil
+ Puppet[:certdnsnames] = "localhost"
+ assert_nothing_raised {
+
+ server = Puppet::Network::HTTPServer::WEBrick.new(
- :Port => @@port,
+ :Port => @@port,
- :Handlers => {
- :CA => {}, # so that certs autogenerate
- :Status => nil
- }
- )
-
+ :Handlers => {
+ :CA => {}, # so that certs autogenerate
+ :Status => nil
}
-
- pid = fork {
- Puppet.run_mode.stubs(:master?).returns true
- assert_nothing_raised {
- trap(:INT) { server.shutdown }
- server.start
- }
- }
- @@tmppids << pid
- [pid, server]
- end
-
- def kill_and_wait(pid, file)
- %x{kill -INT #{pid} 2>/dev/null}
- count = 0
- while count < 30 && File::exist?(file)
- count += 1
- sleep(1)
- end
- assert(count < 30, "Killing server #{pid} failed")
+ )
+
+ }
+
+ pid = fork {
+ Puppet.run_mode.stubs(:master?).returns true
+ assert_nothing_raised {
+ trap(:INT) { server.shutdown }
+ server.start
+ }
+ }
+ @@tmppids << pid
+ [pid, server]
+ end
+
+ def kill_and_wait(pid, file)
+ %x{kill -INT #{pid} 2>/dev/null}
+ count = 0
+ while count < 30 && File::exist?(file)
+ count += 1
+ sleep(1)
end
+ assert(count < 30, "Killing server #{pid} failed")
+ end
end
diff --git a/test/network/xmlrpc/client.rb b/test/network/xmlrpc/client.rb
index 53be5ca07..7e7f36944 100755
--- a/test/network/xmlrpc/client.rb
+++ b/test/network/xmlrpc/client.rb
@@ -7,39 +7,39 @@ require 'puppet/network/xmlrpc/client'
require 'mocha'
class TestXMLRPCClient < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def setup
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- super
- end
+ def setup
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ super
+ end
- def test_set_backtrace
- error = Puppet::Network::XMLRPCClientError.new("An error")
- assert_nothing_raised do
- error.set_backtrace ["caller"]
- end
- assert_equal(["caller"], error.backtrace)
+ def test_set_backtrace
+ error = Puppet::Network::XMLRPCClientError.new("An error")
+ assert_nothing_raised do
+ error.set_backtrace ["caller"]
+ end
+ assert_equal(["caller"], error.backtrace)
+ end
+
+ # Make sure we correctly generate a netclient
+ def test_handler_class
+ # Create a test handler
+ klass = Puppet::Network::XMLRPCClient
+ yay = Class.new(Puppet::Network::Handler) do
+ @interface = XMLRPC::Service::Interface.new("yay") { |iface|
+ iface.add_method("array getcert(csr)")
+ }
+
+ @name = :Yay
end
+ Object.const_set("Yay", yay)
- # Make sure we correctly generate a netclient
- def test_handler_class
- # Create a test handler
- klass = Puppet::Network::XMLRPCClient
- yay = Class.new(Puppet::Network::Handler) do
- @interface = XMLRPC::Service::Interface.new("yay") { |iface|
- iface.add_method("array getcert(csr)")
- }
-
- @name = :Yay
- end
- Object.const_set("Yay", yay)
-
- net = nil
- assert_nothing_raised("Failed when retrieving client for handler") do
- net = klass.handler_class(yay)
- end
-
- assert(net, "did not get net client")
+ net = nil
+ assert_nothing_raised("Failed when retrieving client for handler") do
+ net = klass.handler_class(yay)
end
+
+ assert(net, "did not get net client")
+ end
end
diff --git a/test/network/xmlrpc/processor.rb b/test/network/xmlrpc/processor.rb
index 3bf7b7fa3..0c990c9e8 100755
--- a/test/network/xmlrpc/processor.rb
+++ b/test/network/xmlrpc/processor.rb
@@ -7,73 +7,73 @@ require 'puppet/network/xmlrpc/processor'
require 'mocha'
class TestXMLRPCProcessor < Test::Unit::TestCase
- include PuppetTest
- class BaseProcessor
- def add_handler(interface, handler)
- @handlers ||= {}
- @handlers[interface] = handler
- end
+ include PuppetTest
+ class BaseProcessor
+ def add_handler(interface, handler)
+ @handlers ||= {}
+ @handlers[interface] = handler
end
+ end
- # We use a base class just so super() works with add_handler.
- class Processor < BaseProcessor
- include Puppet::Network::XMLRPCProcessor
+ # We use a base class just so super() works with add_handler.
+ class Processor < BaseProcessor
+ include Puppet::Network::XMLRPCProcessor
- def set_service_hook(&block)
- meta_def(:service, &block)
- end
+ def set_service_hook(&block)
+ meta_def(:service, &block)
end
-
- def setup
- super
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- @processor = Processor.new
+ end
+
+ def setup
+ super
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ @processor = Processor.new
+ end
+
+ def test_handlers
+ ca = Puppet::Network::Handler.ca
+ @processor.send(:setup_processor)
+ assert(! @processor.handler_loaded?(:ca), "already have ca handler loaded")
+ assert_nothing_raised do
+ @processor.add_handler(ca.interface, ca.new)
end
- def test_handlers
- ca = Puppet::Network::Handler.ca
- @processor.send(:setup_processor)
- assert(! @processor.handler_loaded?(:ca), "already have ca handler loaded")
- assert_nothing_raised do
- @processor.add_handler(ca.interface, ca.new)
- end
+ assert(@processor.handler_loaded?(:puppetca), "ca handler not loaded by symbol")
+ assert(@processor.handler_loaded?("puppetca"), "ca handler not loaded by string")
+ end
- assert(@processor.handler_loaded?(:puppetca), "ca handler not loaded by symbol")
- assert(@processor.handler_loaded?("puppetca"), "ca handler not loaded by string")
+ def test_process
+ ca = Puppet::Network::Handler.ca
+ @processor.send(:setup_processor)
+ assert_nothing_raised do
+ @processor.add_handler(ca.interface, ca.new)
end
- def test_process
- ca = Puppet::Network::Handler.ca
- @processor.send(:setup_processor)
- assert_nothing_raised do
- @processor.add_handler(ca.interface, ca.new)
- end
+ fakeparser = Class.new do
+ def parseMethodCall(data)
+ data
+ end
+ end
- fakeparser = Class.new do
- def parseMethodCall(data)
- data
- end
- end
+ request = Puppet::Network::ClientRequest.new("fake", "192.168.0.1", false)
+ request.handler = "myhandler"
+ request.method = "mymethod"
- request = Puppet::Network::ClientRequest.new("fake", "192.168.0.1", false)
- request.handler = "myhandler"
- request.method = "mymethod"
+ @processor.expects(:parser).returns(fakeparser.new)
- @processor.expects(:parser).returns(fakeparser.new)
+ request.expects(:handler=).with("myhandler")
+ request.expects(:method=).with("mymethod")
- request.expects(:handler=).with("myhandler")
- request.expects(:method=).with("mymethod")
+ @processor.stubs(:verify)
+ @processor.expects(:handle).with(request.call, "params", request.name, request.ip)
- @processor.stubs(:verify)
- @processor.expects(:handle).with(request.call, "params", request.name, request.ip)
+ @processor.send(:process, ["myhandler.mymethod", ["params"]], request)
+ end
- @processor.send(:process, ["myhandler.mymethod", ["params"]], request)
- end
-
- def test_setup_processor
- @processor.expects(:set_service_hook)
- @processor.send(:setup_processor)
- end
+ def test_setup_processor
+ @processor.expects(:set_service_hook)
+ @processor.send(:setup_processor)
+ end
end
diff --git a/test/network/xmlrpc/server.rb b/test/network/xmlrpc/server.rb
index 88652a261..a5474b08c 100755
--- a/test/network/xmlrpc/server.rb
+++ b/test/network/xmlrpc/server.rb
@@ -7,20 +7,20 @@ require 'puppet/network/xmlrpc/server'
require 'mocha'
class TestXMLRPCServer < Test::Unit::TestCase
- def setup
- super
- assert_nothing_raised do
- @server = Puppet::Network::XMLRPCServer.new
- end
+ def setup
+ super
+ assert_nothing_raised do
+ @server = Puppet::Network::XMLRPCServer.new
end
+ end
- def test_initialize
- assert(@server.get_service_hook, "no service hook defined")
+ def test_initialize
+ assert(@server.get_service_hook, "no service hook defined")
- assert_nothing_raised("Did not init @loadedhandlers") do
- assert(! @server.handler_loaded?(:puppetca), "server thinks handlers are loaded")
- end
+ assert_nothing_raised("Did not init @loadedhandlers") do
+ assert(! @server.handler_loaded?(:puppetca), "server thinks handlers are loaded")
end
+ end
end
diff --git a/test/network/xmlrpc/webrick_servlet.rb b/test/network/xmlrpc/webrick_servlet.rb
index d3daa4c0d..47bad27c2 100755
--- a/test/network/xmlrpc/webrick_servlet.rb
+++ b/test/network/xmlrpc/webrick_servlet.rb
@@ -8,28 +8,28 @@ require 'puppet/network/xmlrpc/webrick_servlet'
require 'mocha'
class TestXMLRPCWEBrickServlet < Test::Unit::TestCase
- include PuppetTest
- def test_basics
- # Make sure we're doing things as our user info, rather than puppet/puppet
- setme
- set_mygroup
- Puppet[:user] = @me
- Puppet[:group] = @mygroup
- servlet = nil
- ca = Puppet::Network::Handler.ca.new
-
- assert_nothing_raised("Could not create servlet") do
- servlet = Puppet::Network::XMLRPC::WEBrickServlet.new([ca])
- end
+ include PuppetTest
+ def test_basics
+ # Make sure we're doing things as our user info, rather than puppet/puppet
+ setme
+ set_mygroup
+ Puppet[:user] = @me
+ Puppet[:group] = @mygroup
+ servlet = nil
+ ca = Puppet::Network::Handler.ca.new
+
+ assert_nothing_raised("Could not create servlet") do
+ servlet = Puppet::Network::XMLRPC::WEBrickServlet.new([ca])
+ end
- assert(servlet.get_service_hook, "service hook was not set up")
+ assert(servlet.get_service_hook, "service hook was not set up")
- assert(
- servlet.handler_loaded?(:puppetca),
+ assert(
+ servlet.handler_loaded?(:puppetca),
- "Did not load handler")
- end
+ "Did not load handler")
+ end
end