~lynxman/ubuntu/precise/puppet/puppetlabsfixbug12844

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3872.patch/test/lib/puppettest/exetest.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/servertest'
 
2
 
 
3
module PuppetTest::ExeTest
 
4
  include PuppetTest::ServerTest
 
5
 
 
6
  def setup
 
7
    super
 
8
    setbindir
 
9
    setlibdir
 
10
  end
 
11
 
 
12
  def bindir
 
13
    File.join(basedir, "bin")
 
14
  end
 
15
 
 
16
  def sbindir
 
17
    File.join(basedir, "sbin")
 
18
  end
 
19
 
 
20
  def setbindir
 
21
    ENV["PATH"] = [bindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(bindir)
 
22
    ENV["PATH"] = [sbindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(sbindir)
 
23
  end
 
24
 
 
25
  def setlibdir
 
26
    ENV["RUBYLIB"] = $LOAD_PATH.find_all { |dir|
 
27
      dir =~ /puppet/ or dir =~ /\.\./
 
28
    }.join(":")
 
29
  end
 
30
 
 
31
  # Run a ruby command.  This explicitly uses ruby to run stuff, since we
 
32
  # don't necessarily know where our ruby binary is, dernit.
 
33
  # Currently unused, because I couldn't get it to work.
 
34
  def rundaemon(*cmd)
 
35
    @ruby ||= %x{which ruby}.chomp
 
36
    cmd = cmd.unshift(@ruby).join(" ")
 
37
 
 
38
    out = nil
 
39
    Dir.chdir(bindir) {
 
40
      out = %x{#{@ruby} #{cmd}}
 
41
    }
 
42
    out
 
43
  end
 
44
 
 
45
  def startmasterd(args = "")
 
46
    output = nil
 
47
 
 
48
    manifest = mktestmanifest
 
49
    args += " --manifest #{manifest}"
 
50
    args += " --confdir #{Puppet[:confdir]}"
 
51
    args += " --rundir #{File.join(Puppet[:vardir], "run")}"
 
52
    args += " --vardir #{Puppet[:vardir]}"
 
53
    args += " --certdnsnames #{Puppet[:certdnsnames]}"
 
54
    args += " --masterport #{@@port}"
 
55
    args += " --user #{Puppet::Util::SUIDManager.uid}"
 
56
    args += " --group #{Puppet::Util::SUIDManager.gid}"
 
57
    args += " --autosign true"
 
58
 
 
59
    #if Puppet[:debug]
 
60
    #    args += " --debug"
 
61
    #end
 
62
 
 
63
    cmd = "puppetmasterd #{args}"
 
64
 
 
65
 
 
66
    assert_nothing_raised {
 
67
      output = %x{#{cmd}}.chomp
 
68
    }
 
69
    assert_equal("", output, "Puppetmasterd produced output #{output}")
 
70
    assert($CHILD_STATUS == 0, "Puppetmasterd exit status was #{$CHILD_STATUS}")
 
71
    sleep(1)
 
72
 
 
73
    cleanup do
 
74
      stopmasterd
 
75
      sleep(1)
 
76
    end
 
77
 
 
78
    manifest
 
79
  end
 
80
 
 
81
  def stopmasterd(running = true)
 
82
    ps = Facter["ps"].value || "ps -ef"
 
83
 
 
84
    pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
 
85
 
 
86
    pid = nil
 
87
    if FileTest.exists?(pidfile)
 
88
      pid = File.read(pidfile).chomp.to_i
 
89
      File.unlink(pidfile)
 
90
    end
 
91
 
 
92
    return unless running
 
93
    if running or pid
 
94
      runningpid = nil
 
95
      %x{#{ps}}.chomp.split(/\n/).each { |line|
 
96
        if line =~ /ruby.+puppetmasterd/
 
97
          next if line =~ /\.rb/ # skip the test script itself
 
98
          next if line =~ /^puppet/ # skip masters running as 'puppet'
 
99
          ary = line.sub(/^\s+/, '').split(/\s+/)
 
100
          pid = ary[1].to_i
 
101
        end
 
102
      }
 
103
 
 
104
    end
 
105
 
 
106
    # we default to mandating that it's running, but teardown
 
107
    # doesn't require that
 
108
    if pid
 
109
      if pid == $PID
 
110
        raise Puppet::Error, "Tried to kill own pid"
 
111
      end
 
112
      begin
 
113
        Process.kill(:INT, pid)
 
114
      rescue
 
115
        # ignore it
 
116
      end
 
117
    end
 
118
  end
 
119
 
 
120
  def teardown
 
121
    stopmasterd(false)
 
122
    super
 
123
  end
 
124
end
 
125