~ubuntu-branches/ubuntu/quantal/puppet/quantal

« back to all changes in this revision

Viewing changes to .pc/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch/spec/unit/network/http/api/v1_spec.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-14 01:56:30 UTC
  • mfrom: (1.1.29) (3.1.43 sid)
  • Revision ID: package-import@ubuntu.com-20120714015630-ntj41rkvkq4zph4y
Tags: 2.7.18-1ubuntu1
* Resynchronise with Debian. (LP: #1023931) Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
* Dropped upstreamed patches:
  - debian/patches/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch
  - debian/patches/puppet-12844
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch
* Drop Build-Depends on ruby-rspec (in universe):
  - debian/control: remove ruby-rspec from Build-Depends
  - debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
    isn't installed so we can use it in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env rspec
2
 
require 'spec_helper'
3
 
 
4
 
require 'puppet/network/http/api/v1'
5
 
 
6
 
class V1RestApiTester
7
 
  include Puppet::Network::HTTP::API::V1
8
 
end
9
 
 
10
 
describe Puppet::Network::HTTP::API::V1 do
11
 
  before do
12
 
    @tester = V1RestApiTester.new
13
 
  end
14
 
 
15
 
  it "should be able to convert a URI into a request" do
16
 
    @tester.should respond_to(:uri2indirection)
17
 
  end
18
 
 
19
 
  it "should be able to convert a request into a URI" do
20
 
    @tester.should respond_to(:indirection2uri)
21
 
  end
22
 
 
23
 
  describe "when converting a URI into a request" do
24
 
    before do
25
 
      @tester.stubs(:handler).returns "foo"
26
 
    end
27
 
 
28
 
    it "should require the http method, the URI, and the query parameters" do
29
 
      # Not a terribly useful test, but an important statement for the spec
30
 
      lambda { @tester.uri2indirection("/foo") }.should raise_error(ArgumentError)
31
 
    end
32
 
 
33
 
    it "should use the first field of the URI as the environment" do
34
 
      @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].to_s.should == "env"
35
 
    end
36
 
 
37
 
    it "should fail if the environment is not alphanumeric" do
38
 
      lambda { @tester.uri2indirection("GET", "/env ness/foo/bar", {}) }.should raise_error(ArgumentError)
39
 
    end
40
 
 
41
 
    it "should use the environment from the URI even if one is specified in the parameters" do
42
 
      @tester.uri2indirection("GET", "/env/foo/bar", {:environment => "otherenv"})[3][:environment].to_s.should == "env"
43
 
    end
44
 
 
45
 
    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
47
 
    end
48
 
 
49
 
    it "should use the second field of the URI as the indirection name" do
50
 
      @tester.uri2indirection("GET", "/env/foo/bar", {})[0].should == "foo"
51
 
    end
52
 
 
53
 
    it "should fail if the indirection name is not alphanumeric" do
54
 
      lambda { @tester.uri2indirection("GET", "/env/foo ness/bar", {}) }.should raise_error(ArgumentError)
55
 
    end
56
 
 
57
 
    it "should use the remainder of the URI as the indirection key" do
58
 
      @tester.uri2indirection("GET", "/env/foo/bar", {})[2].should == "bar"
59
 
    end
60
 
 
61
 
    it "should support the indirection key being a /-separated file path" do
62
 
      @tester.uri2indirection("GET", "/env/foo/bee/baz/bomb", {})[2].should == "bee/baz/bomb"
63
 
    end
64
 
 
65
 
    it "should fail if no indirection key is specified" do
66
 
      lambda { @tester.uri2indirection("GET", "/env/foo/", {}) }.should raise_error(ArgumentError)
67
 
      lambda { @tester.uri2indirection("GET", "/env/foo", {}) }.should raise_error(ArgumentError)
68
 
    end
69
 
 
70
 
    it "should choose 'find' as the indirection method if the http method is a GET and the indirection name is singular" do
71
 
      @tester.uri2indirection("GET", "/env/foo/bar", {})[1].should == :find
72
 
    end
73
 
 
74
 
    it "should choose 'find' as the indirection method if the http method is a POST and the indirection name is singular" do
75
 
      @tester.uri2indirection("POST", "/env/foo/bar", {})[1].should == :find
76
 
    end
77
 
 
78
 
    it "should choose 'head' as the indirection method if the http method is a HEAD and the indirection name is singular" do
79
 
      @tester.uri2indirection("HEAD", "/env/foo/bar", {})[1].should == :head
80
 
    end
81
 
 
82
 
    it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is plural" do
83
 
      @tester.uri2indirection("GET", "/env/foos/bar", {})[1].should == :search
84
 
    end
85
 
 
86
 
    it "should choose 'find' as the indirection method if the http method is a GET and the indirection name is facts" do
87
 
      @tester.uri2indirection("GET", "/env/facts/bar", {})[1].should == :find
88
 
    end
89
 
 
90
 
    it "should choose 'save' as the indirection method if the http method is a PUT and the indirection name is facts" do
91
 
      @tester.uri2indirection("PUT", "/env/facts/bar", {})[1].should == :save
92
 
    end
93
 
 
94
 
    it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is inventory" do
95
 
      @tester.uri2indirection("GET", "/env/inventory/search", {})[1].should == :search
96
 
    end
97
 
 
98
 
    it "should choose 'find' as the indirection method if the http method is a GET and the indirection name is facts" do
99
 
      @tester.uri2indirection("GET", "/env/facts/bar", {})[1].should == :find
100
 
    end
101
 
 
102
 
    it "should choose 'save' as the indirection method if the http method is a PUT and the indirection name is facts" do
103
 
      @tester.uri2indirection("PUT", "/env/facts/bar", {})[1].should == :save
104
 
    end
105
 
 
106
 
    it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is inventory" do
107
 
      @tester.uri2indirection("GET", "/env/inventory/search", {})[1].should == :search
108
 
    end
109
 
 
110
 
    it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is facts_search" do
111
 
      @tester.uri2indirection("GET", "/env/facts_search/bar", {})[1].should == :search
112
 
    end
113
 
 
114
 
    it "should change indirection name to 'facts' if the http method is a GET and the indirection name is facts_search" do
115
 
      @tester.uri2indirection("GET", "/env/facts_search/bar", {})[0].should == 'facts'
116
 
    end
117
 
 
118
 
    it "should not change indirection name from 'facts' if the http method is a GET and the indirection name is facts" do
119
 
      @tester.uri2indirection("GET", "/env/facts/bar", {})[0].should == 'facts'
120
 
    end
121
 
 
122
 
    it "should change indirection name to 'status' if the http method is a GET and the indirection name is statuses" do
123
 
      @tester.uri2indirection("GET", "/env/statuses/bar", {})[0].should == 'status'
124
 
    end
125
 
 
126
 
    it "should change indirection name to 'probe' if the http method is a GET and the indirection name is probes" do
127
 
      @tester.uri2indirection("GET", "/env/probes/bar", {})[0].should == 'probe'
128
 
    end
129
 
 
130
 
    it "should choose 'delete' as the indirection method if the http method is a DELETE and the indirection name is singular" do
131
 
      @tester.uri2indirection("DELETE", "/env/foo/bar", {})[1].should == :destroy
132
 
    end
133
 
 
134
 
    it "should choose 'save' as the indirection method if the http method is a PUT and the indirection name is singular" do
135
 
      @tester.uri2indirection("PUT", "/env/foo/bar", {})[1].should == :save
136
 
    end
137
 
 
138
 
    it "should fail if an indirection method cannot be picked" do
139
 
      lambda { @tester.uri2indirection("UPDATE", "/env/foo/bar", {}) }.should raise_error(ArgumentError)
140
 
    end
141
 
 
142
 
    it "should URI unescape the indirection key" do
143
 
      escaped = URI.escape("foo bar")
144
 
      indirection_name, method, key, params = @tester.uri2indirection("GET", "/env/foo/#{escaped}", {})
145
 
      key.should == "foo bar"
146
 
    end
147
 
  end
148
 
 
149
 
  describe "when converting a request into a URI" do
150
 
    before do
151
 
      @request = Puppet::Indirector::Request.new(:foo, :find, "with spaces", :foo => :bar, :environment => "myenv")
152
 
    end
153
 
 
154
 
    it "should use the environment as the first field of the URI" do
155
 
      @tester.indirection2uri(@request).split("/")[1].should == "myenv"
156
 
    end
157
 
 
158
 
    it "should use the indirection as the second field of the URI" do
159
 
      @tester.indirection2uri(@request).split("/")[2].should == "foo"
160
 
    end
161
 
 
162
 
    it "should pluralize the indirection name if the method is 'search'" do
163
 
      @request.stubs(:method).returns :search
164
 
      @tester.indirection2uri(@request).split("/")[2].should == "foos"
165
 
    end
166
 
 
167
 
    it "should use the escaped key as the remainder of the URI" do
168
 
      escaped = URI.escape("with spaces")
169
 
      @tester.indirection2uri(@request).split("/")[3].sub(/\?.+/, '').should == escaped
170
 
    end
171
 
 
172
 
    it "should add the query string to the URI" do
173
 
      @request.expects(:query_string).returns "?query"
174
 
      @tester.indirection2uri(@request).should =~ /\?query$/
175
 
    end
176
 
  end
177
 
 
178
 
  describe "when converting a request into a URI with body" do
179
 
    before :each do
180
 
      @request = Puppet::Indirector::Request.new(:foo, :find, "with spaces", :foo => :bar, :environment => "myenv")
181
 
    end
182
 
 
183
 
    it "should use the environment as the first field of the URI" do
184
 
      @tester.request_to_uri_and_body(@request).first.split("/")[1].should == "myenv"
185
 
    end
186
 
 
187
 
    it "should use the indirection as the second field of the URI" do
188
 
      @tester.request_to_uri_and_body(@request).first.split("/")[2].should == "foo"
189
 
    end
190
 
 
191
 
    it "should use the escaped key as the remainder of the URI" do
192
 
      escaped = URI.escape("with spaces")
193
 
      @tester.request_to_uri_and_body(@request).first.split("/")[3].sub(/\?.+/, '').should == escaped
194
 
    end
195
 
 
196
 
    it "should return the URI and body separately" do
197
 
      @tester.request_to_uri_and_body(@request).should == ["/myenv/foo/with%20spaces", "foo=bar"]
198
 
    end
199
 
  end
200
 
end