rambulance 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +19 -8
- data/CHANGELOG.md +59 -1
- data/README.md +11 -20
- data/lib/rambulance/exceptions_app.rb +15 -1
- data/lib/rambulance/railtie.rb +20 -7
- data/lib/rambulance/version.rb +1 -1
- data/test/fake_app/rails_app.rb +3 -0
- data/test/requests/error_json_test.rb +41 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82265aa18e23300634878ce073d6b72effb62a3a8326832f603d9b17b7640634
|
4
|
+
data.tar.gz: 67abe21526c25ab05b2faada53dbadafd62bf414638752cdec3450256e326e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97932a0989390b458d8b697cb3be797f0441b623898a34d03e1920ff50f1d298b6ec5c03650b63adf6191a18ed22e66efda0c71686022691e48dab3cd5bcc836
|
7
|
+
data.tar.gz: 2af8602230f377774c17cb1f2ce0e1861a28880f7e5682807d135772fb51d9f69c8613f772866b082efccdfc8e5158971acfeedce16bbfb95c24afc812d77053
|
data/.travis.yml
CHANGED
@@ -11,11 +11,12 @@ before_install:
|
|
11
11
|
|
12
12
|
rvm:
|
13
13
|
- 2.3.8
|
14
|
-
- 2.4.
|
15
|
-
- 2.5.
|
16
|
-
- 2.6.
|
14
|
+
- 2.4.10
|
15
|
+
- 2.5.8
|
16
|
+
- 2.6.6
|
17
|
+
- 2.7.1
|
17
18
|
- ruby-head
|
18
|
-
- jruby-9.2.
|
19
|
+
- jruby-9.2.11.1
|
19
20
|
- jruby-head
|
20
21
|
|
21
22
|
gemfile:
|
@@ -32,20 +33,30 @@ matrix:
|
|
32
33
|
gemfile: gemfiles/rails_60.gemfile
|
33
34
|
- rvm: 2.3.8
|
34
35
|
gemfile: gemfiles/rails_edge.gemfile
|
35
|
-
- rvm: 2.4.
|
36
|
+
- rvm: 2.4.10
|
36
37
|
gemfile: gemfiles/rails_60.gemfile
|
37
|
-
- rvm: 2.4.
|
38
|
+
- rvm: 2.4.10
|
38
39
|
gemfile: gemfiles/rails_edge.gemfile
|
39
|
-
- rvm: 2.6.
|
40
|
+
- rvm: 2.6.6
|
40
41
|
gemfile: gemfiles/rails_42.gemfile
|
42
|
+
- rvm: 2.7.1
|
43
|
+
gemfile: gemfiles/rails_42.gemfile
|
44
|
+
- rvm: 2.7.1
|
45
|
+
gemfile: gemfiles/rails_50.gemfile
|
46
|
+
- rvm: 2.7.1
|
47
|
+
gemfile: gemfiles/rails_51.gemfile
|
48
|
+
- rvm: 2.7.1
|
49
|
+
gemfile: gemfiles/rails_52.gemfile
|
41
50
|
- rvm: ruby-head
|
42
51
|
gemfile: gemfiles/rails_42.gemfile
|
43
52
|
- rvm: ruby-head
|
44
53
|
gemfile: gemfiles/rails_50.gemfile
|
45
54
|
- rvm: ruby-head
|
46
55
|
gemfile: gemfiles/rails_51.gemfile
|
56
|
+
- rvm: ruby-head
|
57
|
+
gemfile: gemfiles/rails_52.gemfile
|
47
58
|
allow_failures:
|
48
59
|
- rvm: ruby-head
|
49
|
-
- rvm: jruby-9.2.
|
60
|
+
- rvm: jruby-9.2.11.1
|
50
61
|
- rvm: jruby-head
|
51
62
|
- gemfile: gemfiles/rails_edge.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,61 @@
|
|
1
|
+
## v1.1.1 (unreleased)
|
2
|
+
|
3
|
+
- Fixes a bug where a malformed `Content-Type` header could break the exceptions app (#55, @gingerlime)
|
4
|
+
|
5
|
+
## [v1.1.0](https://github.com/yuki24/rambulance/tree/v1.1.0)
|
6
|
+
|
7
|
+
_<sup>released at 2020-05-23 02:52:27 UTC</sup>_
|
8
|
+
|
9
|
+
#### Features
|
10
|
+
|
11
|
+
- Add support for Ruby 2.7 ([<tt>718531c</tt>](https://github.com/yuki24/rambulance/commit/718531c45b61d01dce91f401fd81dd6aefdefb31))
|
12
|
+
|
13
|
+
#### Bug fixes
|
14
|
+
|
15
|
+
- Fixes a bug where malformed MIME type in HTTP headers could break the exceptions app ([#53](https://github.com/yuki24/rambulance/issues/53), [#54](https://github.com/yuki24/rambulance/pull/54), [@gingerlime](https://github.com/gingerlime))
|
16
|
+
|
17
|
+
## [v1.0.3](https://github.com/yuki24/rambulance/tree/v1.0.3)
|
18
|
+
|
19
|
+
_<sup>released at 2019-10-03 03:39:17 UTC</sup>_
|
20
|
+
|
21
|
+
#### Fixes
|
22
|
+
|
23
|
+
- Fixes a bug where custom exceptions app can not be loaded properly on Rails 6 and Zeitwerk ([#52](https://github.com/yuki24/rambulance/issues/52), [@sho918](https://github.com/sho918))
|
24
|
+
|
25
|
+
## [v1.0.2](https://github.com/yuki24/rambulance/tree/v1.0.2)
|
26
|
+
|
27
|
+
_<sup>released at 2019-06-06 23:39:38 UTC</sup>_
|
28
|
+
|
29
|
+
#### Fixes
|
30
|
+
|
31
|
+
- Fixes a bug where `ExceptionsApp` is not loaded when action controller is not loaded ([<tt>ec9d9e5</tt>](https://github.com/yuki24/rambulance/commit/ec9d9e5de98eeec501042a0bbb95ae8ac8d7b4e3))
|
32
|
+
|
33
|
+
## [v1.0.1](https://github.com/yuki24/rambulance/tree/v1.0.1)
|
34
|
+
|
35
|
+
_<sup>released at 2019-06-04 16:30:38 UTC</sup>_
|
36
|
+
|
37
|
+
#### Fixes
|
38
|
+
|
39
|
+
- Fixes an issue where `ExceptionsApp` prevents Rails from booting up ([#49](https://github.com/yuki24/rambulance/issues/49))
|
40
|
+
|
41
|
+
## [v1.0.0](https://github.com/yuki24/rambulance/tree/v1.0.0)
|
42
|
+
|
43
|
+
_<sup>released at 2019-06-03 05:01:14 UTC</sup>_
|
44
|
+
|
45
|
+
#### Features
|
46
|
+
|
47
|
+
- Add support for Ruby 2.6
|
48
|
+
- Add support for Rails 6.0
|
49
|
+
|
50
|
+
#### Bug fixes
|
51
|
+
|
52
|
+
- Fixes a bug where POST requests cause the exceptions app to throw an `ActionController::InvalidAuthenticityToken` error on Rails 5.2 ([<tt>d68d677</tt>](https://github.com/yuki24/rambulance/commit/d68d677de75059fa09f70e37c97f4bae95885c53), [#48](https://github.com/yuki24/rambulance/issues/48), [@adrianhuna](https://github.com/adrianhuna))
|
53
|
+
|
54
|
+
#### Breaking Changes
|
55
|
+
|
56
|
+
- Drop support for Ruby \<= 2.2
|
57
|
+
- Drop support for Rails \<= 4.1
|
58
|
+
|
1
59
|
## [v0.6.0](https://github.com/yuki24/rambulance/tree/v0.6.0)
|
2
60
|
|
3
61
|
_<sup>released at 2018-03-08 18:36:16 UTC</sup>_
|
@@ -24,7 +82,7 @@ _released at 2018-01-02 21:36:02 UTC_
|
|
24
82
|
#### Breaking changes & deprecations
|
25
83
|
|
26
84
|
- Drop support for Ruby 1.9.3
|
27
|
-
- Drop support for
|
85
|
+
- Drop support for Haml and Slim templates
|
28
86
|
|
29
87
|
#### Bug fixes
|
30
88
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Rambulance [![Build Status](https://travis-ci.org/yuki24/rambulance.svg?branch=master)](https://travis-ci.org/yuki24/rambulance)
|
1
|
+
# Rambulance [![Build Status](https://travis-ci.org/yuki24/rambulance.svg?branch=master)](https://travis-ci.org/yuki24/rambulance) [![Gem Version](https://badge.fury.io/rb/rambulance.svg)](https://rubygems.org/gems/rambulance)
|
2
2
|
|
3
|
-
|
3
|
+
A simple and safe way to dynamically render error pages for Rails apps.
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
@@ -10,7 +10,7 @@ Rambulance's exceptions app is simple, skinny and well-tested. It inherits from
|
|
10
10
|
|
11
11
|
### Flexible
|
12
12
|
|
13
|
-
You have full control of
|
13
|
+
You have full control of which error page to show for a specific exception. It also json rendering (perfect for API apps). It even provides a way to create a custom exceptions app.
|
14
14
|
|
15
15
|
### Easy installation and development
|
16
16
|
|
@@ -30,7 +30,7 @@ And then execute:
|
|
30
30
|
$ rails g rambulance:install
|
31
31
|
```
|
32
32
|
|
33
|
-
Rambulance
|
33
|
+
Rambulance's generator can only generate `erb` templates. If you want to use haml or slim templates, please see [How to Convert Your `.erb` to `.slim`](https://github.com/slim-template/slim/wiki/Template-Converters-ERB-to-SLIM) or [html2haml](https://github.com/haml/html2haml).
|
34
34
|
|
35
35
|
Now you can start editing templates like `app/views/errors/not_found.html.erb`. Edit, run `rails server` and open [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found)!
|
36
36
|
|
@@ -56,19 +56,10 @@ config.rescue_responses = {
|
|
56
56
|
|
57
57
|
## Local Development
|
58
58
|
|
59
|
-
There are 2 ways of editing the templates.
|
60
|
-
|
61
|
-
<!---
|
62
|
-
### Open [`localhost:3000/rambulance`](http://localhost:3000/rambulance) in Your Browser
|
63
|
-
|
64
|
-
This page tells all the error pages as well as all the pairs of exceptions/corresponding http status. This is useful when you want to edit templates without changing Rails configuration. Click on one of the links in the page to see what the error page looks like.
|
65
|
-
|
66
|
-
**This feature hasn't been implemented yet.**
|
67
|
-
-->
|
68
|
-
|
69
59
|
### Open `localhost:3000/rambulance/***` in Your Browser
|
70
60
|
|
71
|
-
Just
|
61
|
+
Just open one of the error pages via Rambulance:
|
62
|
+
|
72
63
|
* [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found) or
|
73
64
|
* [`localhost:3000/rambulance/internal_server_error`](http://localhost:3000/rambulance/internal_server_error)
|
74
65
|
|
@@ -92,13 +83,13 @@ If you want to do some more things in a exceptions app, you can also write your
|
|
92
83
|
$ rails g rambulance:exceptions_app
|
93
84
|
```
|
94
85
|
|
95
|
-
It
|
86
|
+
It will generate your own custom exceptions app. You can use whatever techniques you want to use in controllers like `before_filter` and `flash[:notice] = "message..."` since it's a grandchild of `ActionController::Base`!
|
96
87
|
|
97
|
-
**
|
88
|
+
**Heavily customizing the exceptions app is strongly discouraged as there would be no guard against bugs that occur in the exceptions app.**
|
98
89
|
|
99
90
|
## Testing
|
100
91
|
|
101
|
-
|
92
|
+
Rambulance ships with a test helper that allows you to test an error page generated by Rails. All you have to do is to `include Rambulance::TestHelper` and you will be able to use the `with_exceptions_app` DSDL:
|
102
93
|
|
103
94
|
Rspec:
|
104
95
|
|
@@ -132,8 +123,8 @@ Note that testing error pages is not encouraged in Rails as it leads to overuse
|
|
132
123
|
|
133
124
|
## Supported Versions
|
134
125
|
|
135
|
-
* Ruby 2.3, 2,4, 2,5, trunk, JRuby 9.
|
136
|
-
* Rails 4.2, 5.0, 5
|
126
|
+
* Ruby 2.3, 2,4, 2,5, 2.6, trunk, JRuby 9.2, and JRuby head
|
127
|
+
* Rails 4.2, 5.0, 5.1, 5.2, 6.0 and edge
|
137
128
|
|
138
129
|
Rambulance doesn't work with Rails 3.1 and below since they don't provide a way to use a custom exceptions app.
|
139
130
|
|
@@ -12,8 +12,10 @@ module Rambulance
|
|
12
12
|
class ExceptionsApp < ActionController::Base
|
13
13
|
layout :layout_name
|
14
14
|
|
15
|
-
|
15
|
+
begin
|
16
16
|
skip_forgery_protection
|
17
|
+
rescue
|
18
|
+
# ignore errors from #skip_forgery_protection since older Rails adds this method later.
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.call(env)
|
@@ -53,6 +55,12 @@ module Rambulance
|
|
53
55
|
private
|
54
56
|
|
55
57
|
def process_action(*)
|
58
|
+
begin
|
59
|
+
request.content_mime_type
|
60
|
+
rescue Mime::Type::InvalidMimeType
|
61
|
+
request.env["MALFORMED_CONTENT_TYPE"], request.env["CONTENT_TYPE"] = request.env["CONTENT_TYPE"], "text/plain"
|
62
|
+
end
|
63
|
+
|
56
64
|
begin
|
57
65
|
request.GET
|
58
66
|
rescue ActionController::BadRequest
|
@@ -65,6 +73,12 @@ module Rambulance
|
|
65
73
|
request.env["MALFORMED_BODY"], request.env["rack.input"] = request.env["rack.input"], StringIO.new
|
66
74
|
end
|
67
75
|
|
76
|
+
begin
|
77
|
+
request.accepts
|
78
|
+
rescue Mime::Type::InvalidMimeType
|
79
|
+
request.env["MALFORMED_HTTP_ACCEPT"], request.env["HTTP_ACCEPT"] = request.env["HTTP_ACCEPT"], "*/*"
|
80
|
+
end
|
81
|
+
|
68
82
|
# The #formats method needs to be called after the sanitization above.
|
69
83
|
request.formats << Mime::Type.lookup('text/plain')
|
70
84
|
|
data/lib/rambulance/railtie.rb
CHANGED
@@ -5,14 +5,27 @@ module Rambulance
|
|
5
5
|
require "rambulance/exceptions_app"
|
6
6
|
end
|
7
7
|
|
8
|
-
app.config.exceptions_app =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
app.config.exceptions_app =
|
9
|
+
if app.config.respond_to?(:autoloader) && app.config.autoloader == :classic
|
10
|
+
->(env) {
|
11
|
+
begin
|
12
|
+
ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
|
13
|
+
::ExceptionsApp.call(env)
|
14
|
+
rescue NameError
|
15
|
+
require "rambulance/exceptions_app" if !defined?(::Rambulance::ExceptionsApp)
|
16
|
+
::Rambulance::ExceptionsApp.call(env)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
else
|
20
|
+
->(env) {
|
21
|
+
begin
|
22
|
+
::ExceptionsApp.call(env)
|
23
|
+
rescue NameError
|
24
|
+
require "rambulance/exceptions_app" if !defined?(::Rambulance::ExceptionsApp)
|
25
|
+
::Rambulance::ExceptionsApp.call(env)
|
26
|
+
end
|
27
|
+
}
|
14
28
|
end
|
15
|
-
}
|
16
29
|
|
17
30
|
ActiveSupport.on_load(:after_initialize) do
|
18
31
|
Rails.application.routes.append do
|
data/lib/rambulance/version.rb
CHANGED
data/test/fake_app/rails_app.rb
CHANGED
@@ -8,6 +8,7 @@ class TestApp < Rails::Application
|
|
8
8
|
config.eager_load = false
|
9
9
|
config.root = File.dirname(__FILE__)
|
10
10
|
config.autoload_paths += ["#{config.root}/lib"] if ENV["CUSTOM_EXCEPTIONS_APP"]
|
11
|
+
config.hosts = "www.example.com"
|
11
12
|
|
12
13
|
if Rails::VERSION::STRING >= "5.2"
|
13
14
|
config.action_controller.default_protect_from_forgery = true
|
@@ -50,6 +51,7 @@ class ApplicationController < ActionController::Base
|
|
50
51
|
raise "This is a bad filter."
|
51
52
|
end
|
52
53
|
end
|
54
|
+
|
53
55
|
class UsersController < ApplicationController
|
54
56
|
if self.respond_to? :skip_before_action
|
55
57
|
skip_before_action :bad_filter, except: :show
|
@@ -79,6 +81,7 @@ class UsersController < ApplicationController
|
|
79
81
|
raise ForbiddenException
|
80
82
|
end
|
81
83
|
end
|
84
|
+
|
82
85
|
class ProjectsController < ApplicationController
|
83
86
|
if self.respond_to?(:skip_forgery_protection)
|
84
87
|
skip_forgery_protection
|
@@ -36,6 +36,44 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
|
|
36
36
|
assert_equal "Something went wrong", json_response['message']
|
37
37
|
end
|
38
38
|
|
39
|
+
test 'returns an appropriate status based on the rails version when the HTTP Accept header is malformed' do
|
40
|
+
if Rails::VERSION::STRING >= '5.1.0'
|
41
|
+
post '/users', headers: { "HTTP_ACCEPT" => "image/apng*/*" }
|
42
|
+
else
|
43
|
+
post '/users', nil, "HTTP_ACCEPT" => "image/apng*/*"
|
44
|
+
end
|
45
|
+
|
46
|
+
if Rails::VERSION::STRING >= '6.0.0'
|
47
|
+
assert_equal 406, response.status
|
48
|
+
assert_equal "The requested content type is not acceptable.\n", response.body
|
49
|
+
elsif Rails::VERSION::STRING >= '5.2.0'
|
50
|
+
assert_equal 422, response.status
|
51
|
+
elsif Rails::VERSION::STRING >= '5.1.0'
|
52
|
+
assert_equal 500, response.status
|
53
|
+
elsif Rails::VERSION::STRING >= '4.2.0'
|
54
|
+
assert_equal 201, response.status
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'returns an appropriate status based on the rails version when the HTTP Content-type header is malformed' do
|
59
|
+
if Rails::VERSION::STRING >= '5.1.0'
|
60
|
+
post '/users', headers: { "CONTENT_TYPE" => "charset=gbk" }
|
61
|
+
else
|
62
|
+
post '/users', nil, "CONTENT_TYPE" => "charset=gbk"
|
63
|
+
end
|
64
|
+
|
65
|
+
if Rails::VERSION::STRING >= '6.0.0'
|
66
|
+
assert_equal 406, response.status
|
67
|
+
assert_equal "The requested content type is not acceptable.\n", response.body
|
68
|
+
elsif Rails::VERSION::STRING >= '5.2.0'
|
69
|
+
assert_equal 422, response.status
|
70
|
+
elsif Rails::VERSION::STRING >= '5.1.0'
|
71
|
+
assert_equal 500, response.status
|
72
|
+
elsif Rails::VERSION::STRING >= '4.2.0'
|
73
|
+
assert_equal 201, response.status
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
39
77
|
private
|
40
78
|
|
41
79
|
def without_layouts
|
@@ -48,12 +86,12 @@ class ErrorJsonTest < ActionDispatch::IntegrationTest
|
|
48
86
|
`mv error.html.erb test/fake_app/app/views/layouts/`
|
49
87
|
end
|
50
88
|
|
51
|
-
def get(path)
|
89
|
+
def get(path, params: {}, headers: {})
|
52
90
|
without_layouts do
|
53
91
|
if Rails::VERSION::STRING >= '5.1.0'
|
54
|
-
super path, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }
|
92
|
+
super path, params: params, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
|
55
93
|
else
|
56
|
-
super path,
|
94
|
+
super path, params, { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers)
|
57
95
|
end
|
58
96
|
end
|
59
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rambulance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.1.3
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Simple and safe way to dynamically generate error pages
|