projectlocker_errata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +908 -0
- data/Gemfile +3 -0
- data/Guardfile +6 -0
- data/INSTALL +20 -0
- data/MIT-LICENSE +23 -0
- data/README.md +460 -0
- data/README_FOR_HEROKU_ADDON.md +94 -0
- data/Rakefile +223 -0
- data/SUPPORTED_RAILS_VERSIONS +38 -0
- data/TESTING.md +41 -0
- data/features/metal.feature +18 -0
- data/features/rack.feature +60 -0
- data/features/rails.feature +272 -0
- data/features/rails_with_js_notifier.feature +97 -0
- data/features/rake.feature +27 -0
- data/features/sinatra.feature +29 -0
- data/features/step_definitions/file_steps.rb +10 -0
- data/features/step_definitions/metal_steps.rb +23 -0
- data/features/step_definitions/rack_steps.rb +23 -0
- data/features/step_definitions/rails_application_steps.rb +478 -0
- data/features/step_definitions/rake_steps.rb +17 -0
- data/features/support/env.rb +18 -0
- data/features/support/matchers.rb +35 -0
- data/features/support/projectlocker_errata_shim.rb.template +16 -0
- data/features/support/rails.rb +201 -0
- data/features/support/rake/Rakefile +68 -0
- data/features/support/terminal.rb +107 -0
- data/features/user_informer.feature +63 -0
- data/generators/projectlocker_errata/lib/insert_commands.rb +34 -0
- data/generators/projectlocker_errata/lib/rake_commands.rb +24 -0
- data/generators/projectlocker_errata/projectlocker_errata_generator.rb +94 -0
- data/generators/projectlocker_errata/templates/capistrano_hook.rb +6 -0
- data/generators/projectlocker_errata/templates/initializer.rb +6 -0
- data/generators/projectlocker_errata/templates/projectlocker_errata_tasks.rake +25 -0
- data/install.rb +1 -0
- data/lib/projectlocker_errata/backtrace.rb +108 -0
- data/lib/projectlocker_errata/capistrano.rb +43 -0
- data/lib/projectlocker_errata/configuration.rb +305 -0
- data/lib/projectlocker_errata/notice.rb +390 -0
- data/lib/projectlocker_errata/rack.rb +54 -0
- data/lib/projectlocker_errata/rails/action_controller_catcher.rb +30 -0
- data/lib/projectlocker_errata/rails/controller_methods.rb +85 -0
- data/lib/projectlocker_errata/rails/error_lookup.rb +33 -0
- data/lib/projectlocker_errata/rails/javascript_notifier.rb +47 -0
- data/lib/projectlocker_errata/rails/middleware/exceptions_catcher.rb +33 -0
- data/lib/projectlocker_errata/rails.rb +40 -0
- data/lib/projectlocker_errata/rails3_tasks.rb +98 -0
- data/lib/projectlocker_errata/railtie.rb +48 -0
- data/lib/projectlocker_errata/rake_handler.rb +65 -0
- data/lib/projectlocker_errata/sender.rb +128 -0
- data/lib/projectlocker_errata/shared_tasks.rb +47 -0
- data/lib/projectlocker_errata/tasks.rb +83 -0
- data/lib/projectlocker_errata/user_informer.rb +27 -0
- data/lib/projectlocker_errata/utils/blank.rb +53 -0
- data/lib/projectlocker_errata/version.rb +3 -0
- data/lib/projectlocker_errata.rb +159 -0
- data/lib/projectlocker_errata_tasks.rb +64 -0
- data/lib/rails/generators/projectlocker_errata/projectlocker_errata_generator.rb +100 -0
- data/lib/templates/javascript_notifier.erb +15 -0
- data/lib/templates/rescue.erb +91 -0
- data/projectlocker_errata.gemspec +39 -0
- data/rails/init.rb +1 -0
- data/resources/README.md +34 -0
- data/resources/ca-bundle.crt +3376 -0
- data/script/integration_test.rb +38 -0
- data/test/airbrake_2_3.xsd +88 -0
- data/test/backtrace_test.rb +162 -0
- data/test/capistrano_test.rb +34 -0
- data/test/catcher_test.rb +333 -0
- data/test/configuration_test.rb +236 -0
- data/test/helper.rb +263 -0
- data/test/javascript_notifier_test.rb +51 -0
- data/test/logger_test.rb +79 -0
- data/test/notice_test.rb +490 -0
- data/test/notifier_test.rb +276 -0
- data/test/projectlocker_errata_tasks_test.rb +170 -0
- data/test/rack_test.rb +58 -0
- data/test/rails_initializer_test.rb +36 -0
- data/test/recursion_test.rb +10 -0
- data/test/sender_test.rb +288 -0
- data/test/user_informer_test.rb +29 -0
- metadata +440 -0
data/test/sender_test.rb
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class SenderTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
reset_config
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_sender(opts = {})
|
10
|
+
ProjectlockerErrata.configure do |conf|
|
11
|
+
opts.each {|opt, value| conf.send(:"#{opt}=", value) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_exception(args = {})
|
16
|
+
notice = args.delete(:notice) || build_notice_data
|
17
|
+
notice.stubs(:to_xml)
|
18
|
+
sender = args.delete(:sender) || build_sender(args)
|
19
|
+
sender.send_to_projectlocker_errata(notice)
|
20
|
+
end
|
21
|
+
|
22
|
+
def stub_http(options = {})
|
23
|
+
response = stub(:body => options[:body] || 'body')
|
24
|
+
http = stub(:post => response,
|
25
|
+
:read_timeout= => nil,
|
26
|
+
:open_timeout= => nil,
|
27
|
+
:ca_file= => nil,
|
28
|
+
:verify_mode= => nil,
|
29
|
+
:use_ssl= => nil)
|
30
|
+
Net::HTTP.stubs(:new => http)
|
31
|
+
http
|
32
|
+
end
|
33
|
+
|
34
|
+
should "post to ProjectlockerErrata with XML passed" do
|
35
|
+
xml_notice = ProjectlockerErrata::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar").to_xml
|
36
|
+
|
37
|
+
http = stub_http
|
38
|
+
|
39
|
+
sender = build_sender
|
40
|
+
sender.send_to_projectlocker_errata(xml_notice)
|
41
|
+
|
42
|
+
assert_received(http, :post) do |expect|
|
43
|
+
expect.with(anything, xml_notice, ProjectlockerErrata::HEADERS)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
should "post to ProjectlockerErrata with a Notice instance passed" do
|
48
|
+
notice = ProjectlockerErrata::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar")
|
49
|
+
|
50
|
+
http = stub_http
|
51
|
+
|
52
|
+
sender = build_sender
|
53
|
+
sender.send_to_projectlocker_errata(notice)
|
54
|
+
|
55
|
+
assert_received(http, :post) do |expect|
|
56
|
+
expect.with(anything, notice.to_xml, ProjectlockerErrata::HEADERS)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
should "post to ProjectlockerErrata when using an HTTP proxy" do
|
61
|
+
response = stub(:body => 'body')
|
62
|
+
http = stub(:post => response,
|
63
|
+
:read_timeout= => nil,
|
64
|
+
:open_timeout= => nil,
|
65
|
+
:use_ssl= => nil)
|
66
|
+
proxy = stub(:new => http)
|
67
|
+
Net::HTTP.stubs(:Proxy => proxy)
|
68
|
+
|
69
|
+
url = "http://api.projectlocker_errata.io:80#{ProjectlockerErrata::Sender::NOTICES_URI}"
|
70
|
+
uri = URI.parse(url)
|
71
|
+
|
72
|
+
proxy_host = 'some.host'
|
73
|
+
proxy_port = 88
|
74
|
+
proxy_user = 'login'
|
75
|
+
proxy_pass = 'passwd'
|
76
|
+
|
77
|
+
send_exception(:proxy_host => proxy_host,
|
78
|
+
:proxy_port => proxy_port,
|
79
|
+
:proxy_user => proxy_user,
|
80
|
+
:proxy_pass => proxy_pass)
|
81
|
+
assert_received(http, :post) do |expect|
|
82
|
+
expect.with(uri.path, anything, ProjectlockerErrata::HEADERS)
|
83
|
+
end
|
84
|
+
assert_received(Net::HTTP, :Proxy) do |expect|
|
85
|
+
expect.with(proxy_host, proxy_port, proxy_user, proxy_pass)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
should "return the created group's id on successful posting" do
|
90
|
+
http = stub_http(:body => '<id type="integer">3799307</id>')
|
91
|
+
assert_equal "3799307", send_exception(:secure => false)
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when encountering exceptions: " do
|
95
|
+
context "HTTP connection setup problems" do
|
96
|
+
should "not be rescued" do
|
97
|
+
proxy = stub()
|
98
|
+
proxy.stubs(:new).raises(NoMemoryError)
|
99
|
+
Net::HTTP.stubs(:Proxy => proxy)
|
100
|
+
|
101
|
+
assert_raise NoMemoryError do
|
102
|
+
build_sender.send(:setup_http_connection)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
should "be logged" do
|
107
|
+
proxy = stub()
|
108
|
+
proxy.stubs(:new).raises(RuntimeError)
|
109
|
+
Net::HTTP.stubs(:Proxy => proxy)
|
110
|
+
|
111
|
+
sender = build_sender
|
112
|
+
sender.expects(:log)
|
113
|
+
|
114
|
+
assert_raise RuntimeError do
|
115
|
+
sender.send(:setup_http_connection)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "unexpected exception sending problems" do
|
122
|
+
should "be logged" do
|
123
|
+
sender = build_sender
|
124
|
+
sender.stubs(:setup_http_connection).raises(RuntimeError.new)
|
125
|
+
|
126
|
+
sender.expects(:log)
|
127
|
+
send_exception(:sender => sender)
|
128
|
+
end
|
129
|
+
|
130
|
+
should "return nil no matter what" do
|
131
|
+
sender = build_sender
|
132
|
+
sender.stubs(:setup_http_connection).raises(LocalJumpError)
|
133
|
+
|
134
|
+
assert_nothing_thrown do
|
135
|
+
assert_nil sender.send_to_projectlocker_errata(build_notice_data)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
should "return nil on failed posting" do
|
141
|
+
http = stub_http
|
142
|
+
http.stubs(:post).raises(Errno::ECONNREFUSED)
|
143
|
+
assert_equal nil, send_exception(:secure => false)
|
144
|
+
end
|
145
|
+
|
146
|
+
should "not fail when posting and a timeout exception occurs" do
|
147
|
+
http = stub_http
|
148
|
+
http.stubs(:post).raises(TimeoutError)
|
149
|
+
assert_nothing_thrown do
|
150
|
+
send_exception(:secure => false)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
should "not fail when posting and a connection refused exception occurs" do
|
155
|
+
http = stub_http
|
156
|
+
http.stubs(:post).raises(Errno::ECONNREFUSED)
|
157
|
+
assert_nothing_thrown do
|
158
|
+
send_exception(:secure => false)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
should "not fail when posting any http exception occurs" do
|
163
|
+
http = stub_http
|
164
|
+
ProjectlockerErrata::Sender::HTTP_ERRORS.each do |error|
|
165
|
+
http.stubs(:post).raises(error)
|
166
|
+
assert_nothing_thrown do
|
167
|
+
send_exception(:secure => false)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context "SSL" do
|
174
|
+
should "post to the right url for non-ssl" do
|
175
|
+
http = stub_http
|
176
|
+
url = "http://api.projectlocker_errata.io:80#{ProjectlockerErrata::Sender::NOTICES_URI}"
|
177
|
+
uri = URI.parse(url)
|
178
|
+
send_exception(:secure => false)
|
179
|
+
assert_received(http, :post) {|expect| expect.with(uri.path, anything, ProjectlockerErrata::HEADERS) }
|
180
|
+
end
|
181
|
+
|
182
|
+
should "post to the right path for ssl" do
|
183
|
+
http = stub_http
|
184
|
+
send_exception(:secure => true)
|
185
|
+
assert_received(http, :post) {|expect| expect.with(ProjectlockerErrata::Sender::NOTICES_URI, anything, ProjectlockerErrata::HEADERS) }
|
186
|
+
end
|
187
|
+
|
188
|
+
should "verify the SSL peer when the use_ssl option is set to true" do
|
189
|
+
url = "https://api.projectlocker_errata.io#{ProjectlockerErrata::Sender::NOTICES_URI}"
|
190
|
+
uri = URI.parse(url)
|
191
|
+
|
192
|
+
real_http = Net::HTTP.new(uri.host, uri.port)
|
193
|
+
real_http.stubs(:post => nil)
|
194
|
+
proxy = stub(:new => real_http)
|
195
|
+
Net::HTTP.stubs(:Proxy => proxy)
|
196
|
+
File.stubs(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).returns(false)
|
197
|
+
|
198
|
+
send_exception(:secure => true)
|
199
|
+
assert(real_http.use_ssl?)
|
200
|
+
assert_equal(OpenSSL::SSL::VERIFY_PEER, real_http.verify_mode)
|
201
|
+
assert_equal(ProjectlockerErrata.configuration.local_cert_path, real_http.ca_file)
|
202
|
+
end
|
203
|
+
|
204
|
+
should "use the default DEFAULT_CERT_FILE if asked to" do
|
205
|
+
config = ProjectlockerErrata::Configuration.new
|
206
|
+
config.use_system_ssl_cert_chain = true
|
207
|
+
sender = ProjectlockerErrata::Sender.new(config)
|
208
|
+
|
209
|
+
assert(sender.use_system_ssl_cert_chain?)
|
210
|
+
|
211
|
+
http = sender.send(:setup_http_connection)
|
212
|
+
assert_not_equal http.ca_file, config.local_cert_path
|
213
|
+
end
|
214
|
+
|
215
|
+
should "verify the connection when the use_ssl option is set (VERIFY_PEER)" do
|
216
|
+
sender = build_sender(:secure => true)
|
217
|
+
http = sender.send(:setup_http_connection)
|
218
|
+
assert_equal(OpenSSL::SSL::VERIFY_PEER, http.verify_mode)
|
219
|
+
end
|
220
|
+
|
221
|
+
should "use the default cert (OpenSSL::X509::DEFAULT_CERT_FILE) only if explicitly told to" do
|
222
|
+
sender = build_sender(:secure => true)
|
223
|
+
http = sender.send(:setup_http_connection)
|
224
|
+
|
225
|
+
assert_equal(ProjectlockerErrata.configuration.local_cert_path, http.ca_file)
|
226
|
+
|
227
|
+
File.stubs(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).returns(true)
|
228
|
+
sender = build_sender(:secure => true, :use_system_ssl_cert_chain => true)
|
229
|
+
http = sender.send(:setup_http_connection)
|
230
|
+
|
231
|
+
assert_not_equal(ProjectlockerErrata.configuration.local_cert_path, http.ca_file)
|
232
|
+
assert_equal(OpenSSL::X509::DEFAULT_CERT_FILE, http.ca_file)
|
233
|
+
end
|
234
|
+
|
235
|
+
should "connect to the right port for ssl" do
|
236
|
+
stub_http
|
237
|
+
send_exception(:secure => true)
|
238
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with("api.projectlocker_errata.io", 443) }
|
239
|
+
end
|
240
|
+
|
241
|
+
should "connect to the right port for non-ssl" do
|
242
|
+
stub_http
|
243
|
+
send_exception(:secure => false)
|
244
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with("api.projectlocker_errata.io", 80) }
|
245
|
+
end
|
246
|
+
|
247
|
+
should "use ssl if secure" do
|
248
|
+
stub_http
|
249
|
+
send_exception(:secure => true, :host => 'example.org')
|
250
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 443) }
|
251
|
+
end
|
252
|
+
|
253
|
+
should "not use ssl if not secure" do
|
254
|
+
stub_http
|
255
|
+
send_exception(:secure => false, :host => 'example.org')
|
256
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 80) }
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
context "network timeouts" do
|
263
|
+
should "default the open timeout to 2 seconds" do
|
264
|
+
http = stub_http
|
265
|
+
send_exception
|
266
|
+
assert_received(http, :open_timeout=) {|expect| expect.with(2) }
|
267
|
+
end
|
268
|
+
|
269
|
+
should "default the read timeout to 5 seconds" do
|
270
|
+
http = stub_http
|
271
|
+
send_exception
|
272
|
+
assert_received(http, :read_timeout=) {|expect| expect.with(5) }
|
273
|
+
end
|
274
|
+
|
275
|
+
should "allow override of the open timeout" do
|
276
|
+
http = stub_http
|
277
|
+
send_exception(:http_open_timeout => 4)
|
278
|
+
assert_received(http, :open_timeout=) {|expect| expect.with(4) }
|
279
|
+
end
|
280
|
+
|
281
|
+
should "allow override of the read timeout" do
|
282
|
+
http = stub_http
|
283
|
+
send_exception(:http_read_timeout => 10)
|
284
|
+
assert_received(http, :read_timeout=) {|expect| expect.with(10) }
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class UserInformerTest < Test::Unit::TestCase
|
4
|
+
should "modify output if there is an projectlocker_errata id" do
|
5
|
+
main_app = lambda do |env|
|
6
|
+
env['projectlocker_errata.error_id'] = 1
|
7
|
+
[200, {}, ["<!-- PROJECTLOCKER_ERRATA ERROR -->"]]
|
8
|
+
end
|
9
|
+
informer_app = ProjectlockerErrata::UserInformer.new(main_app)
|
10
|
+
|
11
|
+
ShamRack.mount(informer_app, "example.com")
|
12
|
+
|
13
|
+
response = Net::HTTP.get_response(URI.parse("http://example.com/"))
|
14
|
+
assert_equal "ProjectlockerErrata Error 1", response.body
|
15
|
+
assert_equal 16, response["Content-Length"].to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not modify output if there is no projectlocker_errata id" do
|
19
|
+
main_app = lambda do |env|
|
20
|
+
[200, {}, ["<!-- PROJECTLOCKER_ERRATA ERROR -->"]]
|
21
|
+
end
|
22
|
+
informer_app = ProjectlockerErrata::UserInformer.new(main_app)
|
23
|
+
|
24
|
+
ShamRack.mount(informer_app, "example.com")
|
25
|
+
|
26
|
+
response = Net::HTTP.get_response(URI.parse("http://example.com/"))
|
27
|
+
assert_equal "<!-- PROJECTLOCKER_ERRATA ERROR -->", response.body
|
28
|
+
end
|
29
|
+
end
|