summaryrefslogtreecommitdiffstats
path: root/test/network/server
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/server
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/server')
-rwxr-xr-xtest/network/server/mongrel_test.rb174
-rwxr-xr-xtest/network/server/webrick.rb184
2 files changed, 179 insertions, 179 deletions
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