3
require File.dirname(__FILE__) + '/../../lib/puppettest'
8
class TestMongrelServer < PuppetTest::TestCase
9
confine "Missing mongrel" => Puppet.features.mongrel?
11
include PuppetTest::ServerTest
13
def mkserver(handlers = nil)
14
handlers ||= { :Status => nil }
15
mongrel = Puppet::Network::HTTPServer::Mongrel.new(handlers)
18
# Make sure client info is correctly extracted.
21
obj.metaclass.send(:attr_accessor, :params)
27
ip = Facter.value(:ipaddress)
28
params["REMOTE_ADDR"] = ip
29
params[Puppet[:ssl_client_header]] = ""
30
params[Puppet[:ssl_client_verify_header]] = "failure"
32
Resolv.expects(:getname).with(ip).returns("host.domain.com").times(3)
33
assert_nothing_raised("Could not call client_info") do
34
info = mongrel.send(:client_info, obj)
36
assert(! info.authenticated?, "Client info object was marked valid even though headers were missing")
37
assert_equal(ip, info.ip, "Did not copy over ip correctly")
39
assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
41
# Now add a valid auth header.
42
params[Puppet[:ssl_client_header]] = "/CN=host.domain.com"
43
assert_nothing_raised("Could not call client_info") do
44
info = mongrel.send(:client_info, obj)
46
assert(! info.authenticated?, "Client info object was marked valid even though the verify header was fals")
47
assert_equal(ip, info.ip, "Did not copy over ip correctly")
48
assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
50
# Now change the verify header to be true
51
params[Puppet[:ssl_client_verify_header]] = "SUCCESS"
52
assert_nothing_raised("Could not call client_info") do
53
info = mongrel.send(:client_info, obj)
56
assert(info.authenticated?, "Client info object was not marked valid even though all headers were correct")
57
assert_equal(ip, info.ip, "Did not copy over ip correctly")
58
assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
60
# Now try it with a different header name
61
params.delete(Puppet[:ssl_client_header])
62
Puppet[:ssl_client_header] = "header_testing"
63
params["header_testing"] = "/CN=other.domain.com"
65
assert_nothing_raised("Could not call client_info with other header") do
66
info = mongrel.send(:client_info, obj)
69
assert(info.authenticated?, "Client info object was not marked valid even though the header was present")
70
assert_equal(ip, info.ip, "Did not copy over ip correctly")
71
assert_equal("other.domain.com", info.name, "Did not copy over hostname correctly")
73
# Now make sure it's considered invalid without that header
74
params.delete("header_testing")
76
assert_nothing_raised("Could not call client_info with no header") do
77
info = mongrel.send(:client_info, obj)
80
assert(! info.authenticated?, "Client info object was marked valid without header")
81
assert_equal(ip, info.ip, "Did not copy over ip correctly")
82
assert_equal(Resolv.getname(ip), info.name, "Did not look up hostname correctly")
88
assert(mongrel.respond_to?(:daemonize), "Mongrel server does not respond to daemonize")