Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 410857
Collapse All | Expand All

(-)a/lib/puppet/network/formats.rb (-27 lines)
Lines 77-109 Puppet::Network::FormatHandler.create_serialized_formats(:b64_zlib_yaml) do Link Here
77
  end
77
  end
78
end
78
end
79
79
80
81
Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do
82
  # Marshal doesn't need the class name; it's serialized.
83
  def intern(klass, text)
84
    Marshal.load(text)
85
  end
86
87
  # Marshal doesn't need the class name; it's serialized.
88
  def intern_multiple(klass, text)
89
    Marshal.load(text)
90
  end
91
92
  def render(instance)
93
    Marshal.dump(instance)
94
  end
95
96
  # Marshal monkey-patches Array, so this works.
97
  def render_multiple(instances)
98
    Marshal.dump(instances)
99
  end
100
101
  # Everything's supported
102
  def supported?(klass)
103
    true
104
  end
105
end
106
107
Puppet::Network::FormatHandler.create(:s, :mime => "text/plain", :extension => "txt")
80
Puppet::Network::FormatHandler.create(:s, :mime => "text/plain", :extension => "txt")
108
81
109
# A very low-weight format so it'll never get chosen automatically.
82
# A very low-weight format so it'll never get chosen automatically.
(-)a/lib/puppet/network/http/api/v1.rb (+1 lines)
Lines 31-36 module Puppet::Network::HTTP::API::V1 Link Here
31
    method = indirection_method(http_method, indirection)
31
    method = indirection_method(http_method, indirection)
32
32
33
    params[:environment] = Puppet::Node::Environment.new(environment)
33
    params[:environment] = Puppet::Node::Environment.new(environment)
34
    params.delete(:bucket_path)
34
35
35
    raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil?
36
    raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil?
36
37
(-)a/lib/puppet/provider/package/appdmg.rb (-13 / +13 lines)
Lines 50-72 Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Packag Link Here
50
50
51
  def self.installpkgdmg(source, name)
51
  def self.installpkgdmg(source, name)
52
    unless source =~ /\.dmg$/i
52
    unless source =~ /\.dmg$/i
53
      self.fail "Mac OS X PKG DMG's must specificy a source string ending in .dmg"
53
      self.fail "Mac OS X PKG DMG's must specify a source string ending in .dmg"
54
    end
54
    end
55
    require 'open-uri'
55
    require 'open-uri'
56
    require 'facter/util/plist'
56
    require 'facter/util/plist'
57
    cached_source = source
57
    cached_source = source
58
    if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
58
    tmpdir = Dir.mktmpdir
59
      cached_source = "/tmp/#{name}"
59
    begin
60
      begin
60
      if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
61
        curl "-o", cached_source, "-C", "-", "-k", "-L", "-s", "--url", source
61
        cached_source = File.join(tmpdir, name)
62
        Puppet.debug "Success: curl transfered [#{name}]"
62
        begin
63
      rescue Puppet::ExecutionFailure
63
          curl "-o", cached_source, "-C", "-", "-k", "-L", "-s", "--url", source
64
        Puppet.debug "curl did not transfer [#{name}].  Falling back to slower open-uri transfer methods."
64
          Puppet.debug "Success: curl transfered [#{name}]"
65
        cached_source = source
65
        rescue Puppet::ExecutionFailure
66
          Puppet.debug "curl did not transfer [#{name}].  Falling back to slower open-uri transfer methods."
67
          cached_source = source
68
        end
66
      end
69
      end
67
    end
68
70
69
    begin
70
      open(cached_source) do |dmg|
71
      open(cached_source) do |dmg|
71
        xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
72
        xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
72
          ptable = Plist::parse_xml xml_str
73
          ptable = Plist::parse_xml xml_str
Lines 87-94 Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Packag Link Here
87
          end
88
          end
88
      end
89
      end
89
    ensure
90
    ensure
90
      # JJM Remove the file if open-uri didn't already do so.
91
      FileUtils.remove_entry_secure(tmpdir, force=true)
91
      File.unlink(cached_source) if File.exist?(cached_source)
92
    end
92
    end
93
  end
93
  end
94
94
(-)a/lib/puppet/provider/package/pkgdmg.rb (-21 / +15 lines)
Lines 39-49 Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag Link Here
39
39
40
  def self.instances
40
  def self.instances
41
    instance_by_name.collect do |name|
41
    instance_by_name.collect do |name|
42
      new(
42
      new(:name => name, :provider => :pkgdmg, :ensure => :installed)
43
        :name     => name,
44
        :provider => :pkgdmg,
45
        :ensure   => :installed
46
      )
47
    end
43
    end
48
  end
44
  end
49
45
Lines 58-79 Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag Link Here
58
54
59
  def self.installpkgdmg(source, name)
55
  def self.installpkgdmg(source, name)
60
    unless source =~ /\.dmg$/i || source =~ /\.pkg$/i
56
    unless source =~ /\.dmg$/i || source =~ /\.pkg$/i
61
      raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg or flat .pkg file")
57
      raise Puppet::Error.new("Mac OS X PKG DMG's must specify a source string ending in .dmg or flat .pkg file")
62
    end
58
    end
63
    require 'open-uri'
59
    require 'open-uri'
64
    cached_source = source
60
    cached_source = source
65
    if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
61
    tmpdir = Dir.mktmpdir
66
      cached_source = "/tmp/#{name}"
62
    begin
67
      begin
63
      if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
68
        curl "-o", cached_source, "-C", "-", "-k", "-L", "-s", "--url", source
64
        cached_source = File.join(tmpdir, name)
69
        Puppet.debug "Success: curl transfered [#{name}]"
65
        begin
70
      rescue Puppet::ExecutionFailure
66
          curl "-o", cached_source, "-C", "-", "-k", "-L", "-s", "--url", source
71
        Puppet.debug "curl did not transfer [#{name}].  Falling back to slower open-uri transfer methods."
67
          Puppet.debug "Success: curl transfered [#{name}]"
72
        cached_source = source
68
        rescue Puppet::ExecutionFailure
69
          Puppet.debug "curl did not transfer [#{name}].  Falling back to slower open-uri transfer methods."
70
          cached_source = source
71
        end
73
      end
72
      end
74
    end
75
73
76
    begin
77
      if source =~ /\.dmg$/i
74
      if source =~ /\.dmg$/i
78
        File.open(cached_source) do |dmg|
75
        File.open(cached_source) do |dmg|
79
          xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
76
          xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
Lines 96-109 Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag Link Here
96
            end
93
            end
97
          end
94
          end
98
        end
95
        end
99
      elsif source =~ /\.pkg$/i
100
        installpkg(cached_source, name, source)
101
      else
96
      else
102
        raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg or flat .pkg file")
97
        installpkg(cached_source, name, source)
103
      end
98
      end
104
    ensure
99
    ensure
105
      # JJM Remove the file if open-uri didn't already do so.
100
      FileUtils.remove_entry_secure(tmpdir, force=true)
106
      File.unlink(cached_source) if File.exist?(cached_source)
107
    end
101
    end
108
  end
102
  end
109
103
(-)a/lib/puppet/util/network_device/transport/telnet.rb (-2 / +2 lines)
Lines 15-21 class Puppet::Util::NetworkDevice::Transport::Telnet < Puppet::Util::NetworkDevi Link Here
15
    def connect
15
    def connect
16
      @telnet = Net::Telnet::new("Host" => host, "Port" => port || 23,
16
      @telnet = Net::Telnet::new("Host" => host, "Port" => port || 23,
17
                                 "Timeout" => 10,
17
                                 "Timeout" => 10,
18
                                 "Prompt" => default_prompt, "Output_log" => "/tmp/out.log")
18
                                 "Prompt" => default_prompt)
19
    end
19
    end
20
20
21
    def close
21
    def close
Lines 39-42 class Puppet::Util::NetworkDevice::Transport::Telnet < Puppet::Util::NetworkDevi Link Here
39
    def send(line)
39
    def send(line)
40
      @telnet.puts(line)
40
      @telnet.puts(line)
41
    end
41
    end
42
end
42
end
(-)a/spec/unit/network/formats_spec.rb (-43 lines)
Lines 162-210 describe "Puppet Network Format" do Link Here
162
162
163
  end
163
  end
164
164
165
  it "should include a marshal format" do
166
    Puppet::Network::FormatHandler.format(:marshal).should_not be_nil
167
  end
168
169
  describe "marshal" do
170
    before do
171
      @marshal = Puppet::Network::FormatHandler.format(:marshal)
172
    end
173
174
    it "should have its mime type set to text/marshal" do
175
      Puppet::Network::FormatHandler.format(:marshal).mime.should == "text/marshal"
176
    end
177
178
    it "should be supported on Strings" do
179
      @marshal.should be_supported(String)
180
    end
181
182
    it "should render by calling 'Marshal.dump' on the instance" do
183
      instance = mock 'instance'
184
      Marshal.expects(:dump).with(instance).returns "foo"
185
      @marshal.render(instance).should == "foo"
186
    end
187
188
    it "should render multiple instances by calling 'to_marshal' on the array" do
189
      instances = [mock('instance')]
190
191
      Marshal.expects(:dump).with(instances).returns "foo"
192
      @marshal.render_multiple(instances).should == "foo"
193
    end
194
195
    it "should intern by calling 'Marshal.load'" do
196
      text = "foo"
197
      Marshal.expects(:load).with("foo").returns "bar"
198
      @marshal.intern(String, text).should == "bar"
199
    end
200
201
    it "should intern multiples by calling 'Marshal.load'" do
202
      text = "foo"
203
      Marshal.expects(:load).with("foo").returns "bar"
204
      @marshal.intern_multiple(String, text).should == "bar"
205
    end
206
  end
207
208
  describe "plaintext" do
165
  describe "plaintext" do
209
    before do
166
    before do
210
      @text = Puppet::Network::FormatHandler.format(:s)
167
      @text = Puppet::Network::FormatHandler.format(:s)
(-)a/spec/unit/network/http/api/v1_spec.rb (+8 lines)
Lines 42-47 describe Puppet::Network::HTTP::API::V1 do Link Here
42
      @tester.uri2indirection("GET", "/env/foo/bar", {:environment => "otherenv"})[3][:environment].to_s.should == "env"
42
      @tester.uri2indirection("GET", "/env/foo/bar", {:environment => "otherenv"})[3][:environment].to_s.should == "env"
43
    end
43
    end
44
44
45
    it "should not pass a buck_path parameter through (See Bugs #13553, #13518, #13511)" do
46
      @tester.uri2indirection("GET", "/env/foo/bar", { :bucket_path => "/malicious/path" })[3].should_not include({ :bucket_path => "/malicious/path" })
47
    end
48
49
    it "should pass allowed parameters through" do
50
      @tester.uri2indirection("GET", "/env/foo/bar", { :allowed_param => "value" })[3].should include({ :allowed_param => "value" })
51
    end
52
45
    it "should return the environment as a Puppet::Node::Environment" do
53
    it "should return the environment as a Puppet::Node::Environment" do
46
      @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].should be_a Puppet::Node::Environment
54
      @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].should be_a Puppet::Node::Environment
47
    end
55
    end
(-)a/spec/unit/provider/package/appdmg_spec.rb (+42 lines)
Line 0 Link Here
1
#!/usr/bin/env rspec
2
require 'spec_helper'
3
4
describe Puppet::Type.type(:package).provider(:appdmg) do
5
  let(:resource) { Puppet::Type.type(:package).new(:name => 'foo', :provider => :appdmg) }
6
  let(:provider) { described_class.new(resource) }
7
8
  describe "when installing an appdmg" do
9
    let(:fake_mountpoint) { "/tmp/dmg.foo" }
10
    let(:empty_hdiutil_plist) { Plist::Emit.dump({}) }
11
    let(:fake_hdiutil_plist) { Plist::Emit.dump({"system-entities" => [{"mount-point" => fake_mountpoint}]}) }
12
13
    before do
14
      fh = mock 'filehandle'
15
      fh.stubs(:path).yields "/tmp/foo"
16
      resource[:source] = "foo.dmg"
17
      described_class.stubs(:open).yields fh
18
      Dir.stubs(:mktmpdir).returns "/tmp/testtmp123"
19
      FileUtils.stubs(:remove_entry_secure)
20
    end
21
22
    describe "from a remote source" do
23
      let(:tmpdir) { "/tmp/good123" }
24
25
      before :each do
26
        resource[:source] = "http://fake.puppetlabs.com/foo.dmg"
27
      end
28
29
      it "should call tmpdir and use the returned directory" do
30
        Dir.expects(:mktmpdir).returns tmpdir
31
        Dir.stubs(:entries).returns ["foo.app"]
32
        described_class.expects(:curl).with do |*args|
33
          args[0] == "-o" and args[1].include? tmpdir
34
        end
35
        described_class.stubs(:hdiutil).returns fake_hdiutil_plist
36
        described_class.expects(:installapp)
37
38
        provider.install
39
      end
40
    end
41
  end
42
end
(-)a/spec/unit/provider/package/pkgdmg_spec.rb (-48 / +54 lines)
Lines 1-83 Link Here
1
#!/usr/bin/env rspec
1
#!/usr/bin/env rspec
2
require 'spec_helper'
2
require 'spec_helper'
3
3
4
provider = Puppet::Type.type(:package).provider(:pkgdmg)
4
describe Puppet::Type.type(:package).provider(:pkgdmg) do
5
  let(:resource) { Puppet::Type.type(:package).new(:name => 'foo', :provider => :pkgdmg) }
6
  let(:provider) { described_class.new(resource) }
5
7
6
describe provider do
8
  it { should_not be_versionable }
7
  before do
9
  it { should_not be_uninstallable }
8
    @resource = stub 'resource', :[] => "dummypkgdmg"
9
    @provider = provider.new(@resource)
10
11
    @fakemountpoint   = "/tmp/dmg.foo"
12
    @fakepkgfile      = "/tmp/test.pkg"
13
    @fakehdiutilinfo  = {"system-entities" => [{"mount-point" => @fakemountpoint}] }
14
    @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo)
15
16
    @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly",
17
      "-noidme", "-mountrandom", "/tmp"]
18
  end
19
20
  it "should not be versionable" do
21
    provider.versionable?.should be_false
22
  end
23
24
  it "should not be uninstallable" do
25
    provider.uninstallable?.should be_false
26
  end
27
10
28
  describe "when installing it should fail when" do
11
  describe "when installing it should fail when" do
29
    it "no source is specified" do
12
    before :each do
30
      @resource.stubs(:[]).with(:source).returns nil
13
      Puppet::Util.expects(:execute).never
31
      lambda { @provider.install }.should raise_error(Puppet::Error)
32
    end
14
    end
33
15
34
    it "no name is specified" do
16
    it "no source is specified" do
35
      @resource.stubs(:[]).with(:name).returns nil
17
      expect { provider.install }.should raise_error(Puppet::Error, /must specify a package source/)
36
      lambda { @provider.install }.should raise_error(Puppet::Error)
37
    end
18
    end
38
19
39
    it "the source does not end in .dmg or .pkg" do
20
    it "the source does not end in .dmg or .pkg" do
40
      @resource.stubs(:[]).with(:source).returns "notendingindotdmgorpkg"
21
      resource[:source] = "bar"
41
      lambda { @provider.install }.should raise_error(Puppet::Error)
22
      expect { provider.install }.should raise_error(Puppet::Error, /must specify a source string ending in .*dmg.*pkg/)
42
    end
43
44
    it "a disk image with no system entities is mounted" do
45
      @provider.stubs(:[]).with(:hdiutil).returns ""
46
      lambda { @provider.install }.should raise_error(Puppet::Error)
47
    end
23
    end
48
  end
24
  end
49
25
50
  # These tests shouldn't be this messy. The pkgdmg provider needs work...
26
  # These tests shouldn't be this messy. The pkgdmg provider needs work...
51
  describe "when installing a pkgdmg" do
27
  describe "when installing a pkgdmg" do
28
    let(:fake_mountpoint) { "/tmp/dmg.foo" }
29
    let(:empty_hdiutil_plist) { Plist::Emit.dump({}) }
30
    let(:fake_hdiutil_plist) { Plist::Emit.dump({"system-entities" => [{"mount-point" => fake_mountpoint}]}) }
31
52
    before do
32
    before do
53
      fh = mock 'filehandle'
33
      fh = mock 'filehandle'
54
      fh.stubs(:path).yields "/tmp/foo"
34
      fh.stubs(:path).yields "/tmp/foo"
55
      @resource.stubs(:[]).with(:source).returns "foo.dmg"
35
      resource[:source] = "foo.dmg"
56
      File.stubs(:open).yields fh
36
      File.stubs(:open).yields fh
37
      Dir.stubs(:mktmpdir).returns "/tmp/testtmp123"
38
      FileUtils.stubs(:remove_entry_secure)
39
    end
40
41
    it "should fail when a disk image with no system entities is mounted" do
42
      described_class.stubs(:hdiutil).returns(empty_hdiutil_plist)
43
      expect { provider.install }.should raise_error(Puppet::Error, /No disk entities/)
57
    end
44
    end
58
45
59
    it "should call hdiutil to mount and eject the disk image" do
46
    it "should call hdiutil to mount and eject the disk image" do
60
      Dir.stubs(:entries).returns []
47
      Dir.stubs(:entries).returns []
61
      @provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0
48
      provider.class.expects(:hdiutil).with("eject", fake_mountpoint).returns 0
62
      @provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist
49
      provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns fake_hdiutil_plist
63
      @provider.install
50
      provider.install
64
    end
51
    end
65
52
66
    it "should call installpkg if a pkg/mpkg is found on the dmg" do
53
    it "should call installpkg if a pkg/mpkg is found on the dmg" do
67
      Dir.stubs(:entries).returns ["foo.pkg"]
54
      Dir.stubs(:entries).returns ["foo.pkg"]
68
      @provider.class.stubs(:hdiutil).returns @fakehdiutilplist
55
      provider.class.stubs(:hdiutil).returns fake_hdiutil_plist
69
      @provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns ""
56
      provider.class.expects(:installpkg).with("#{fake_mountpoint}/foo.pkg", resource[:name], "foo.dmg").returns ""
70
      @provider.install
57
      provider.install
58
    end
59
60
    describe "from a remote source" do
61
      let(:tmpdir) { "/tmp/good123" }
62
63
      before :each do
64
        resource[:source] = "http://fake.puppetlabs.com/foo.dmg"
65
      end
66
67
      it "should call tmpdir and use the returned directory" do
68
        Dir.expects(:mktmpdir).returns tmpdir
69
        Dir.stubs(:entries).returns ["foo.pkg"]
70
        described_class.expects(:curl).with do |*args|
71
          args[0] == "-o" and args[1].include? tmpdir
72
        end
73
        described_class.stubs(:hdiutil).returns fake_hdiutil_plist
74
        described_class.expects(:installpkg)
75
76
        provider.install
77
      end
71
    end
78
    end
72
  end
79
  end
73
80
74
  describe "when installing flat pkg file" do
81
  describe "when installing flat pkg file" do
75
    it "should call installpkg if a flat pkg file is found instead of a .dmg image" do
82
    it "should call installpkg if a flat pkg file is found instead of a .dmg image" do
76
      @resource.stubs(:[]).with(:source).returns "/tmp/test.pkg"
83
      resource[:source] = "/tmp/test.pkg"
77
      @resource.stubs(:[]).with(:name).returns "testpkg"
84
      resource[:name] = "testpkg"
78
        @provider.class.expects(:installpkgdmg).with("#{@fakepkgfile}", "testpkg").returns ""
85
      provider.class.expects(:installpkgdmg).with("/tmp/test.pkg", "testpkg").returns ""
79
        @provider.install
86
      provider.install
80
        end
87
    end
81
  end
88
  end
82
83
end
89
end
(-)a/spec/unit/util/network_device/transport/telnet_spec.rb (-1 / +9 lines)
Lines 6-11 require 'puppet/util/network_device/transport/telnet' Link Here
6
describe Puppet::Util::NetworkDevice::Transport::Telnet do
6
describe Puppet::Util::NetworkDevice::Transport::Telnet do
7
7
8
  before(:each) do
8
  before(:each) do
9
    TCPSocket.stubs(:open).returns stub_everything('tcp')
9
    @transport = Puppet::Util::NetworkDevice::Transport::Telnet.new()
10
    @transport = Puppet::Util::NetworkDevice::Transport::Telnet.new()
10
  end
11
  end
11
12
Lines 13-18 describe Puppet::Util::NetworkDevice::Transport::Telnet do Link Here
13
    @transport.should_not be_handles_login
14
    @transport.should_not be_handles_login
14
  end
15
  end
15
16
17
  it "should not open any files" do
18
    File.expects(:open).never
19
    @transport.host = "localhost"
20
    @transport.port = 23
21
22
    @transport.connect
23
  end
24
16
  it "should connect to the given host and port" do
25
  it "should connect to the given host and port" do
17
    Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything
26
    Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything
18
    @transport.host = "localhost"
27
    @transport.host = "localhost"
19
- 

Return to bug 410857