~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to test/network/server/mongrel_test.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../lib/puppettest'
 
4
 
 
5
require 'puppettest'
 
6
require 'mocha'
 
7
 
 
8
class TestMongrelServer < PuppetTest::TestCase
 
9
    confine "Missing mongrel" => Puppet.features.mongrel?
 
10
 
 
11
    include PuppetTest::ServerTest
 
12
 
 
13
    def mkserver(handlers = nil)
 
14
        handlers ||= { :Status => nil }
 
15
        mongrel = Puppet::Network::HTTPServer::Mongrel.new(handlers)
 
16
    end
 
17
 
 
18
    # Make sure client info is correctly extracted.
 
19
    def test_client_info
 
20
        obj = Object.new
 
21
        obj.metaclass.send(:attr_accessor, :params)
 
22
        params = {}
 
23
        obj.params = params
 
24
 
 
25
        mongrel = mkserver
 
26
 
 
27
        ip = Facter.value(:ipaddress)
 
28
        params["REMOTE_ADDR"] = ip
 
29
        params[Puppet[:ssl_client_header]] = ""
 
30
        params[Puppet[:ssl_client_verify_header]] = "failure"
 
31
        info = nil
 
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)
 
35
        end
 
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")
 
38
 
 
39
        assert_equal("host.domain.com", info.name, "Did not copy over hostname correctly")
 
40
 
 
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)
 
45
        end
 
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")
 
49
 
 
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)
 
54
        end
 
55
 
 
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")
 
59
 
 
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"
 
64
        info = nil
 
65
        assert_nothing_raised("Could not call client_info with other header") do
 
66
            info = mongrel.send(:client_info, obj)
 
67
        end
 
68
 
 
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")
 
72
 
 
73
        # Now make sure it's considered invalid without that header
 
74
        params.delete("header_testing")
 
75
        info = nil
 
76
        assert_nothing_raised("Could not call client_info with no header") do
 
77
            info = mongrel.send(:client_info, obj)
 
78
        end
 
79
 
 
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")
 
83
    end
 
84
 
 
85
    def test_daemonize
 
86
        mongrel = mkserver
 
87
 
 
88
        assert(mongrel.respond_to?(:daemonize), "Mongrel server does not respond to daemonize")
 
89
    end
 
90
end
 
91