~racb/ubuntu/saucy/puppet/dep8-hiera

« back to all changes in this revision

Viewing changes to .pc/security-mar-2013.patch/spec/unit/indirector/terminus_spec.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-03-11 11:16:08 UTC
  • Revision ID: package-import@ubuntu.com-20130311111608-6gtkc65hikm0p07r
Tags: 2.7.18-1ubuntu2
* SECURITY UPDATE: Multiple security issues
  - debian/patches/security-mar-2013.patch: upstream patch to fix
    multiple security issues.
  - CVE-2013-1640 - Remote code execution on master from authenticated clients
  - CVE-2013-1652 - Insufficient input validation
  - CVE-2013-1653 - Remote code execution
  - CVE-2013-1654 - Protocol downgrade
  - CVE-2013-1655 - Unauthenticated remote code execution risk
  - CVE-2013-2275 - Incorrect default report ACL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env rspec
 
2
require 'spec_helper'
 
3
require 'puppet/defaults'
 
4
require 'puppet/indirector'
 
5
require 'puppet/indirector/memory'
 
6
 
 
7
describe Puppet::Indirector::Terminus, :'fails_on_ruby_1.9.2' => true do
 
8
  before :each do
 
9
    Puppet::Indirector::Terminus.stubs(:register_terminus_class)
 
10
    @indirection = stub 'indirection', :name => :my_stuff, :register_terminus_type => nil
 
11
    Puppet::Indirector::Indirection.stubs(:instance).with(:my_stuff).returns(@indirection)
 
12
    @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
 
13
      def self.to_s
 
14
        "Testing::Abstract"
 
15
      end
 
16
    end
 
17
    @terminus_class = Class.new(@abstract_terminus) do
 
18
      def self.to_s
 
19
        "MyStuff::TermType"
 
20
      end
 
21
    end
 
22
    @terminus = @terminus_class.new
 
23
  end
 
24
 
 
25
  describe Puppet::Indirector::Terminus do
 
26
 
 
27
    it "should provide a method for setting terminus class documentation" do
 
28
      @terminus_class.should respond_to(:desc)
 
29
    end
 
30
 
 
31
    it "should support a class-level name attribute" do
 
32
      @terminus_class.should respond_to(:name)
 
33
    end
 
34
 
 
35
    it "should support a class-level indirection attribute" do
 
36
      @terminus_class.should respond_to(:indirection)
 
37
    end
 
38
 
 
39
    it "should support a class-level terminus-type attribute" do
 
40
      @terminus_class.should respond_to(:terminus_type)
 
41
    end
 
42
 
 
43
    it "should support a class-level model attribute" do
 
44
      @terminus_class.should respond_to(:model)
 
45
    end
 
46
 
 
47
    it "should accept indirection instances as its indirection" do
 
48
      indirection = stub 'indirection', :is_a? => true, :register_terminus_type => nil
 
49
      proc { @terminus_class.indirection = indirection }.should_not raise_error
 
50
      @terminus_class.indirection.should equal(indirection)
 
51
    end
 
52
 
 
53
    it "should look up indirection instances when only a name has been provided" do
 
54
      indirection = mock 'indirection'
 
55
      Puppet::Indirector::Indirection.expects(:instance).with(:myind).returns(indirection)
 
56
      @terminus_class.indirection = :myind
 
57
      @terminus_class.indirection.should equal(indirection)
 
58
    end
 
59
 
 
60
    it "should fail when provided a name that does not resolve to an indirection" do
 
61
      Puppet::Indirector::Indirection.expects(:instance).with(:myind).returns(nil)
 
62
      proc { @terminus_class.indirection = :myind }.should raise_error(ArgumentError)
 
63
 
 
64
      # It shouldn't overwrite our existing one (or, more normally, it shouldn't set
 
65
      # anything).
 
66
      @terminus_class.indirection.should equal(@indirection)
 
67
    end
 
68
  end
 
69
 
 
70
  describe Puppet::Indirector::Terminus, " when creating terminus classes" do
 
71
    it "should associate the subclass with an indirection based on the subclass constant" do
 
72
      @terminus.indirection.should equal(@indirection)
 
73
    end
 
74
 
 
75
    it "should set the subclass's type to the abstract terminus name" do
 
76
      @terminus.terminus_type.should == :abstract
 
77
    end
 
78
 
 
79
    it "should set the subclass's name to the indirection name" do
 
80
      @terminus.name.should == :term_type
 
81
    end
 
82
 
 
83
    it "should set the subclass's model to the indirection model" do
 
84
      @indirection.expects(:model).returns :yay
 
85
      @terminus.model.should == :yay
 
86
    end
 
87
  end
 
88
 
 
89
  describe Puppet::Indirector::Terminus, " when a terminus instance" do
 
90
 
 
91
    it "should return the class's name as its name" do
 
92
      @terminus.name.should == :term_type
 
93
    end
 
94
 
 
95
    it "should return the class's indirection as its indirection" do
 
96
      @terminus.indirection.should equal(@indirection)
 
97
    end
 
98
 
 
99
    it "should set the instances's type to the abstract terminus type's name" do
 
100
      @terminus.terminus_type.should == :abstract
 
101
    end
 
102
 
 
103
    it "should set the instances's model to the indirection's model" do
 
104
      @indirection.expects(:model).returns :yay
 
105
      @terminus.model.should == :yay
 
106
    end
 
107
  end
 
108
end
 
109
 
 
110
# LAK: This could reasonably be in the Indirection instances, too.  It doesn't make
 
111
# a whole heckuva lot of difference, except that with the instance loading in
 
112
# the Terminus base class, we have to have a check to see if we're already
 
113
# instance-loading a given terminus class type.
 
114
describe Puppet::Indirector::Terminus, " when managing terminus classes" do
 
115
  it "should provide a method for registering terminus classes" do
 
116
    Puppet::Indirector::Terminus.should respond_to(:register_terminus_class)
 
117
  end
 
118
 
 
119
  it "should provide a method for returning terminus classes by name and type" do
 
120
    terminus = stub 'terminus_type', :name => :abstract, :indirection_name => :whatever
 
121
    Puppet::Indirector::Terminus.register_terminus_class(terminus)
 
122
    Puppet::Indirector::Terminus.terminus_class(:whatever, :abstract).should equal(terminus)
 
123
  end
 
124
 
 
125
  it "should set up autoloading for any terminus class types requested" do
 
126
    Puppet::Indirector::Terminus.expects(:instance_load).with(:test2, "puppet/indirector/test2")
 
127
    Puppet::Indirector::Terminus.terminus_class(:test2, :whatever)
 
128
  end
 
129
 
 
130
  it "should load terminus classes that are not found" do
 
131
    # Set up instance loading; it would normally happen automatically
 
132
    Puppet::Indirector::Terminus.instance_load :test1, "puppet/indirector/test1"
 
133
 
 
134
    Puppet::Indirector::Terminus.instance_loader(:test1).expects(:load).with(:yay)
 
135
    Puppet::Indirector::Terminus.terminus_class(:test1, :yay)
 
136
  end
 
137
 
 
138
  it "should fail when no indirection can be found", :'fails_on_ruby_1.9.2' => true do
 
139
    Puppet::Indirector::Indirection.expects(:instance).with(:my_indirection).returns(nil)
 
140
 
 
141
    @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
 
142
      def self.to_s
 
143
        "Abstract"
 
144
      end
 
145
    end
 
146
    proc {
 
147
      @terminus = Class.new(@abstract_terminus) do
 
148
        def self.to_s
 
149
          "MyIndirection::TestType"
 
150
        end
 
151
      end
 
152
    }.should raise_error(ArgumentError)
 
153
  end
 
154
 
 
155
  it "should register the terminus class with the terminus base class", :'fails_on_ruby_1.9.2' => true do
 
156
    Puppet::Indirector::Terminus.expects(:register_terminus_class).with do |type|
 
157
      type.indirection_name == :my_indirection and type.name == :test_terminus
 
158
    end
 
159
    @indirection = stub 'indirection', :name => :my_indirection, :register_terminus_type => nil
 
160
    Puppet::Indirector::Indirection.expects(:instance).with(:my_indirection).returns(@indirection)
 
161
 
 
162
    @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
 
163
      def self.to_s
 
164
        "Abstract"
 
165
      end
 
166
    end
 
167
 
 
168
    @terminus = Class.new(@abstract_terminus) do
 
169
      def self.to_s
 
170
        "MyIndirection::TestTerminus"
 
171
      end
 
172
    end
 
173
  end
 
174
end
 
175
 
 
176
describe Puppet::Indirector::Terminus, " when parsing class constants for indirection and terminus names" do
 
177
  before do
 
178
    @subclass = mock 'subclass'
 
179
    @subclass.stubs(:to_s).returns("TestInd::OneTwo")
 
180
    @subclass.stubs(:mark_as_abstract_terminus)
 
181
    Puppet::Indirector::Terminus.stubs(:register_terminus_class)
 
182
  end
 
183
 
 
184
  it "should fail when anonymous classes are used" do
 
185
    proc { Puppet::Indirector::Terminus.inherited(Class.new) }.should raise_error(Puppet::DevError)
 
186
  end
 
187
 
 
188
  it "should use the last term in the constant for the terminus class name" do
 
189
    @subclass.expects(:name=).with(:one_two)
 
190
    @subclass.stubs(:indirection=)
 
191
    Puppet::Indirector::Terminus.inherited(@subclass)
 
192
  end
 
193
 
 
194
  it "should convert the terminus name to a downcased symbol" do
 
195
    @subclass.expects(:name=).with(:one_two)
 
196
    @subclass.stubs(:indirection=)
 
197
    Puppet::Indirector::Terminus.inherited(@subclass)
 
198
  end
 
199
 
 
200
  it "should use the second to last term in the constant for the indirection name" do
 
201
    @subclass.expects(:indirection=).with(:test_ind)
 
202
    @subclass.stubs(:name=)
 
203
    @subclass.stubs(:terminus_type=)
 
204
    Puppet::Indirector::Memory.inherited(@subclass)
 
205
  end
 
206
 
 
207
  it "should convert the indirection name to a downcased symbol" do
 
208
    @subclass.expects(:indirection=).with(:test_ind)
 
209
    @subclass.stubs(:name=)
 
210
    @subclass.stubs(:terminus_type=)
 
211
    Puppet::Indirector::Memory.inherited(@subclass)
 
212
  end
 
213
 
 
214
  it "should convert camel case to lower case with underscores as word separators" do
 
215
    @subclass.expects(:name=).with(:one_two)
 
216
    @subclass.stubs(:indirection=)
 
217
 
 
218
    Puppet::Indirector::Terminus.inherited(@subclass)
 
219
  end
 
220
end
 
221
 
 
222
describe Puppet::Indirector::Terminus, " when creating terminus class types", :'fails_on_ruby_1.9.2' => true do
 
223
  before do
 
224
    Puppet::Indirector::Terminus.stubs(:register_terminus_class)
 
225
    @subclass = Class.new(Puppet::Indirector::Terminus) do
 
226
      def self.to_s
 
227
        "Puppet::Indirector::Terminus::MyTermType"
 
228
      end
 
229
    end
 
230
  end
 
231
 
 
232
  it "should set the name of the abstract subclass to be its class constant" do
 
233
    @subclass.name.should equal(:my_term_type)
 
234
  end
 
235
 
 
236
  it "should mark abstract terminus types as such" do
 
237
    @subclass.should be_abstract_terminus
 
238
  end
 
239
 
 
240
  it "should not allow instances of abstract subclasses to be created" do
 
241
    proc { @subclass.new }.should raise_error(Puppet::DevError)
 
242
  end
 
243
end
 
244
 
 
245
describe Puppet::Indirector::Terminus, " when listing terminus classes" do
 
246
  it "should list the terminus files available to load" do
 
247
    Puppet::Util::Autoload.any_instance.stubs(:files_to_load).returns ["/foo/bar/baz", "/max/runs/marathon"]
 
248
    Puppet::Indirector::Terminus.terminus_classes('my_stuff').should == [:baz, :marathon]
 
249
  end
 
250
end