~lynxman/ubuntu/precise/puppet/puppetlabsfixbug12844

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3872.patch/test/lib/puppettest/servertest.rb

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-10-24 15:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20111024150512-yxqwfdp6hcs6of5l
Tags: 2.7.1-1ubuntu3.2
* SECURITY UPDATE: puppet master impersonation via incorrect certificates
  - debian/patches/CVE-2011-3872.patch: refactor certificate handling.
  - Thanks to upstream for providing the patch.
  - CVE-2011-3872

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppettest'
 
2
require 'puppet/network/http_server/webrick'
 
3
 
 
4
module PuppetTest::ServerTest
 
5
  include PuppetTest
 
6
  def setup
 
7
    super
 
8
 
 
9
    if defined?(@@port)
 
10
      @@port += 1
 
11
    else
 
12
      @@port = 20000
 
13
    end
 
14
  end
 
15
 
 
16
  # create a simple manifest that just creates a file
 
17
  def mktestmanifest
 
18
    file = File.join(Puppet[:confdir], "#{(self.class.to_s + "test")}site.pp")
 
19
    #@createdfile = File.join(tmpdir, self.class.to_s + "manifesttesting" +
 
20
    #    "_#{@method_name}")
 
21
    @createdfile = tempfile
 
22
 
 
23
    File.open(file, "w") { |f|
 
24
      f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % @createdfile
 
25
    }
 
26
 
 
27
    @@tmpfiles << @createdfile
 
28
    @@tmpfiles << file
 
29
 
 
30
    file
 
31
  end
 
32
 
 
33
  # create a server, forked into the background
 
34
  def mkserver(handlers = nil)
 
35
    Puppet[:name] = "puppetmasterd"
 
36
    # our default handlers
 
37
    unless handlers
 
38
      handlers = {
 
39
        :CA => {}, # so that certs autogenerate
 
40
        :Master => {
 
41
          :Manifest => mktestmanifest,
 
42
          :UseNodes => false
 
43
        },
 
44
      }
 
45
    end
 
46
 
 
47
    # then create the actual server
 
48
    server = nil
 
49
    assert_nothing_raised {
 
50
 
 
51
            server = Puppet::Network::HTTPServer::WEBrick.new(
 
52
                
 
53
        :Port => @@port,
 
54
        
 
55
        :Handlers => handlers
 
56
      )
 
57
    }
 
58
 
 
59
    # fork it
 
60
    spid = fork {
 
61
      trap(:INT) { server.shutdown }
 
62
      server.start
 
63
    }
 
64
 
 
65
    # and store its pid for killing
 
66
    @@tmppids << spid
 
67
 
 
68
    # give the server a chance to do its thing
 
69
    sleep 1
 
70
    spid
 
71
  end
 
72
 
 
73
end
 
74