hanami 2.3.2 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -19
- data/LICENSE +20 -0
- data/README.md +18 -35
- data/hanami.gemspec +36 -37
- data/lib/hanami/config/db.rb +2 -0
- data/lib/hanami/config/i18n.rb +138 -0
- data/lib/hanami/config/logger.rb +15 -7
- data/lib/hanami/config/null_config.rb +1 -1
- data/lib/hanami/config/views.rb +17 -0
- data/lib/hanami/config.rb +66 -22
- data/lib/hanami/errors.rb +6 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/extensions/action.rb +2 -2
- data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
- data/lib/hanami/extensions/mailer.rb +28 -0
- data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
- data/lib/hanami/extensions/view/context.rb +26 -4
- data/lib/hanami/extensions/view/part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions.rb +6 -1
- data/lib/hanami/helpers/assets_helper.rb +0 -4
- data/lib/hanami/helpers/form_helper.rb +1 -1
- data/lib/hanami/helpers/i18n_helper.rb +176 -0
- data/lib/hanami/logger/rack_formatter.rb +73 -0
- data/lib/hanami/logger/sql_formatter.rb +80 -0
- data/lib/hanami/logger/sql_logger.rb +48 -0
- data/lib/hanami/middleware/render_errors.rb +2 -2
- data/lib/hanami/providers/db.rb +7 -2
- data/lib/hanami/providers/db_logging.rb +4 -7
- data/lib/hanami/providers/i18n/backend.rb +369 -0
- data/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/lib/hanami/providers/i18n.rb +114 -0
- data/lib/hanami/providers/mailers.rb +101 -0
- data/lib/hanami/routes.rb +1 -0
- data/lib/hanami/settings/composite_store.rb +53 -0
- data/lib/hanami/settings.rb +4 -4
- data/lib/hanami/slice/router.rb +15 -10
- data/lib/hanami/slice.rb +71 -11
- data/lib/hanami/slice_registrar.rb +2 -2
- data/lib/hanami/universal_logger.rb +250 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +2 -80
- data/lib/hanami/web/welcome.html.erb +443 -58
- data/lib/hanami.rb +4 -2
- metadata +28 -276
- data/CODE_OF_CONDUCT.md +0 -74
- data/FEATURES.md +0 -269
- data/LICENSE.md +0 -22
- data/spec/integration/action/cookies_spec.rb +0 -58
- data/spec/integration/action/csrf_protection_spec.rb +0 -54
- data/spec/integration/action/format_config_spec.rb +0 -129
- data/spec/integration/action/routes_spec.rb +0 -71
- data/spec/integration/action/sessions_spec.rb +0 -50
- data/spec/integration/action/slice_configuration_spec.rb +0 -284
- data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
- data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
- data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
- data/spec/integration/action/view_rendering_spec.rb +0 -89
- data/spec/integration/assets/assets_spec.rb +0 -155
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
- data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
- data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
- data/spec/integration/container/application_routes_helper_spec.rb +0 -48
- data/spec/integration/container/auto_injection_spec.rb +0 -53
- data/spec/integration/container/auto_registration_spec.rb +0 -86
- data/spec/integration/container/autoloader_spec.rb +0 -82
- data/spec/integration/container/imports_spec.rb +0 -253
- data/spec/integration/container/prepare_container_spec.rb +0 -125
- data/spec/integration/container/provider_environment_spec.rb +0 -52
- data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
- data/spec/integration/container/shutdown_spec.rb +0 -91
- data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
- data/spec/integration/container/standard_providers_spec.rb +0 -124
- data/spec/integration/db/auto_registration_spec.rb +0 -39
- data/spec/integration/db/commands_spec.rb +0 -80
- data/spec/integration/db/db_inflector_spec.rb +0 -57
- data/spec/integration/db/db_slices_spec.rb +0 -398
- data/spec/integration/db/db_spec.rb +0 -245
- data/spec/integration/db/gateways_spec.rb +0 -361
- data/spec/integration/db/logging_spec.rb +0 -301
- data/spec/integration/db/mappers_spec.rb +0 -84
- data/spec/integration/db/provider_config_spec.rb +0 -88
- data/spec/integration/db/provider_spec.rb +0 -35
- data/spec/integration/db/relations_spec.rb +0 -60
- data/spec/integration/db/repo_spec.rb +0 -300
- data/spec/integration/db/slices_importing_from_parent.rb +0 -130
- data/spec/integration/dotenv_loading_spec.rb +0 -138
- data/spec/integration/logging/exception_logging_spec.rb +0 -120
- data/spec/integration/logging/notifications_spec.rb +0 -68
- data/spec/integration/logging/request_logging_spec.rb +0 -202
- data/spec/integration/operations/extension_spec.rb +0 -122
- data/spec/integration/rack_app/body_parser_spec.rb +0 -108
- data/spec/integration/rack_app/method_override_spec.rb +0 -97
- data/spec/integration/rack_app/middleware_spec.rb +0 -720
- data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
- data/spec/integration/rack_app/rack_app_spec.rb +0 -442
- data/spec/integration/rake_tasks_spec.rb +0 -107
- data/spec/integration/router/resource_routes_spec.rb +0 -281
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
- data/spec/integration/settings/access_to_constants_spec.rb +0 -46
- data/spec/integration/settings/loading_from_env_spec.rb +0 -188
- data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
- data/spec/integration/settings/slice_registration_spec.rb +0 -145
- data/spec/integration/settings/using_types_spec.rb +0 -80
- data/spec/integration/setup_spec.rb +0 -165
- data/spec/integration/slices/external_slice_spec.rb +0 -91
- data/spec/integration/slices/slice_configuration_spec.rb +0 -42
- data/spec/integration/slices/slice_loading_spec.rb +0 -171
- data/spec/integration/slices/slice_registrations_spec.rb +0 -80
- data/spec/integration/slices/slice_routing_spec.rb +0 -219
- data/spec/integration/slices_spec.rb +0 -471
- data/spec/integration/view/config/default_context_spec.rb +0 -149
- data/spec/integration/view/config/inflector_spec.rb +0 -57
- data/spec/integration/view/config/part_class_spec.rb +0 -147
- data/spec/integration/view/config/part_namespace_spec.rb +0 -103
- data/spec/integration/view/config/paths_spec.rb +0 -119
- data/spec/integration/view/config/scope_class_spec.rb +0 -147
- data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
- data/spec/integration/view/config/template_spec.rb +0 -38
- data/spec/integration/view/context/assets_spec.rb +0 -79
- data/spec/integration/view/context/inflector_spec.rb +0 -40
- data/spec/integration/view/context/request_spec.rb +0 -57
- data/spec/integration/view/context/routes_spec.rb +0 -84
- data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
- data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
- data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
- data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
- data/spec/integration/view/slice_configuration_spec.rb +0 -289
- data/spec/integration/view/views_spec.rb +0 -103
- data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
- data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
- data/spec/integration/web/render_errors_spec.rb +0 -242
- data/spec/integration/web/welcome_view_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -28
- data/spec/support/app_integration.rb +0 -157
- data/spec/support/coverage.rb +0 -1
- data/spec/support/matchers.rb +0 -32
- data/spec/support/rspec.rb +0 -27
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
- data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
- data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
- data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
- data/spec/unit/hanami/config/actions_spec.rb +0 -52
- data/spec/unit/hanami/config/base_url_spec.rb +0 -25
- data/spec/unit/hanami/config/console_spec.rb +0 -22
- data/spec/unit/hanami/config/db_spec.rb +0 -38
- data/spec/unit/hanami/config/inflector_spec.rb +0 -35
- data/spec/unit/hanami/config/logger_spec.rb +0 -195
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/router_spec.rb +0 -44
- data/spec/unit/hanami/config/slices_spec.rb +0 -34
- data/spec/unit/hanami/config/views_spec.rb +0 -80
- data/spec/unit/hanami/env_spec.rb +0 -37
- data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
- data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
- data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
- data/spec/unit/hanami/port_spec.rb +0 -117
- data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
- data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
- data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
- data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
- data/spec/unit/hanami/settings_spec.rb +0 -111
- data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
- data/spec/unit/hanami/slice_name_spec.rb +0 -47
- data/spec/unit/hanami/slice_spec.rb +0 -99
- data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Hanami view integration", :app_integration do
|
|
4
|
-
specify "Views take their configuration from their slice in which they are defined" do
|
|
5
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
require "hanami"
|
|
8
|
-
|
|
9
|
-
module TestApp
|
|
10
|
-
class App < Hanami::App
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
RUBY
|
|
14
|
-
|
|
15
|
-
write "app/view.rb", <<~RUBY
|
|
16
|
-
# auto_register: false
|
|
17
|
-
require "hanami/view"
|
|
18
|
-
|
|
19
|
-
module TestApp
|
|
20
|
-
class View < Hanami::View
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/views/users/show.rb", <<~RUBY
|
|
26
|
-
module TestApp
|
|
27
|
-
module Views
|
|
28
|
-
module Users
|
|
29
|
-
class Show < TestApp::View
|
|
30
|
-
expose :name
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
RUBY
|
|
36
|
-
|
|
37
|
-
write "app/templates/layouts/app.html.slim", <<~SLIM
|
|
38
|
-
html
|
|
39
|
-
body
|
|
40
|
-
== yield
|
|
41
|
-
SLIM
|
|
42
|
-
|
|
43
|
-
write "app/templates/users/show.html.slim", <<~'SLIM'
|
|
44
|
-
h1 Hello, #{name}
|
|
45
|
-
SLIM
|
|
46
|
-
|
|
47
|
-
require "hanami/prepare"
|
|
48
|
-
|
|
49
|
-
rendered = TestApp::App["views.users.show"].(name: "Jennifer")
|
|
50
|
-
expect(rendered.to_s).to eq "<html><body><h1>Hello, Jennifer</h1></body></html>"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
specify "Views can also take configuration from the app when defined in the top-level app module" do
|
|
55
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
56
|
-
write "config/app.rb", <<~RUBY
|
|
57
|
-
require "hanami"
|
|
58
|
-
|
|
59
|
-
module TestApp
|
|
60
|
-
class App < Hanami::App
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
RUBY
|
|
64
|
-
|
|
65
|
-
write "app/view.rb", <<~RUBY
|
|
66
|
-
# auto_register: false
|
|
67
|
-
require "hanami/view"
|
|
68
|
-
|
|
69
|
-
module TestApp
|
|
70
|
-
class View < Hanami::View
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
RUBY
|
|
74
|
-
|
|
75
|
-
write "app/views/users/show.rb", <<~RUBY
|
|
76
|
-
module TestApp
|
|
77
|
-
module Views
|
|
78
|
-
module Users
|
|
79
|
-
class Show < TestApp::View
|
|
80
|
-
expose :name
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
RUBY
|
|
86
|
-
|
|
87
|
-
write "app/templates/layouts/app.html.slim", <<~SLIM
|
|
88
|
-
html
|
|
89
|
-
body
|
|
90
|
-
== yield
|
|
91
|
-
SLIM
|
|
92
|
-
|
|
93
|
-
write "app/templates/users/show.html.slim", <<~'SLIM'
|
|
94
|
-
h1 Hello, #{name}
|
|
95
|
-
SLIM
|
|
96
|
-
|
|
97
|
-
require "hanami/prepare"
|
|
98
|
-
|
|
99
|
-
rendered = TestApp::App["views.users.show"].(name: "Jennifer")
|
|
100
|
-
expect(rendered.to_s).to eq "<html><body><h1>Hello, Jennifer</h1></body></html>"
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "Web / Content security policy nonce", :app_integration do
|
|
6
|
-
include Rack::Test::Methods
|
|
7
|
-
|
|
8
|
-
let(:app) { Hanami.app }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
with_directory(@dir = make_tmp_directory) do
|
|
12
|
-
write "config/routes.rb", <<~RUBY
|
|
13
|
-
module TestApp
|
|
14
|
-
class Routes < Hanami::Routes
|
|
15
|
-
get "index", to: "index"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
RUBY
|
|
19
|
-
|
|
20
|
-
write "app/actions/index.rb", <<~RUBY
|
|
21
|
-
module TestApp
|
|
22
|
-
module Actions
|
|
23
|
-
class Index < Hanami::Action
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
RUBY
|
|
28
|
-
|
|
29
|
-
write "app/views/index.rb", <<~RUBY
|
|
30
|
-
module TestApp
|
|
31
|
-
module Views
|
|
32
|
-
class Index < Hanami::View
|
|
33
|
-
config.layout = false
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
RUBY
|
|
38
|
-
|
|
39
|
-
write "app/templates/index.html.erb", <<~HTML
|
|
40
|
-
<!DOCTYPE html>
|
|
41
|
-
<html lang="en">
|
|
42
|
-
<head>
|
|
43
|
-
<%= stylesheet_tag "app", class: "nonce-true", nonce: true %>
|
|
44
|
-
<%= stylesheet_tag "app", class: "nonce-false", nonce: false %>
|
|
45
|
-
<%= stylesheet_tag "app", class: "nonce-explicit", nonce: "explicit" %>
|
|
46
|
-
<%= stylesheet_tag "app", class: "nonce-generated" %>
|
|
47
|
-
<%= stylesheet_tag "https://example.com/app.css", class: "nonce-absolute" %>
|
|
48
|
-
</head>
|
|
49
|
-
<body>
|
|
50
|
-
<style nonce="<%= content_security_policy_nonce %>"></style>
|
|
51
|
-
<%= javascript_tag "app", class: "nonce-true", nonce: true %>
|
|
52
|
-
<%= javascript_tag "app", class: "nonce-false", nonce: false %>
|
|
53
|
-
<%= javascript_tag "app", class: "nonce-explicit", nonce: "explicit" %>
|
|
54
|
-
<%= javascript_tag "app", class: "nonce-generated" %>
|
|
55
|
-
<%= javascript_tag "https://example.com/app.js", class: "nonce-absolute" %>
|
|
56
|
-
</body>
|
|
57
|
-
</html>
|
|
58
|
-
HTML
|
|
59
|
-
|
|
60
|
-
write "package.json", <<~JSON
|
|
61
|
-
{
|
|
62
|
-
"type": "module"
|
|
63
|
-
}
|
|
64
|
-
JSON
|
|
65
|
-
|
|
66
|
-
write "config/assets.js", <<~JS
|
|
67
|
-
import * as assets from "hanami-assets";
|
|
68
|
-
await assets.run();
|
|
69
|
-
JS
|
|
70
|
-
|
|
71
|
-
write "app/assets/js/app.js", <<~JS
|
|
72
|
-
import "../css/app.css";
|
|
73
|
-
JS
|
|
74
|
-
|
|
75
|
-
write "app/assets/css/app.css", ""
|
|
76
|
-
|
|
77
|
-
before_prepare if respond_to?(:before_prepare)
|
|
78
|
-
require "hanami/prepare"
|
|
79
|
-
compile_assets!
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe "HTML request" do
|
|
84
|
-
context "CSP enabled" do
|
|
85
|
-
def before_prepare
|
|
86
|
-
write "config/app.rb", <<~RUBY
|
|
87
|
-
require "hanami"
|
|
88
|
-
|
|
89
|
-
module TestApp
|
|
90
|
-
class App < Hanami::App
|
|
91
|
-
config.actions.content_security_policy[:script_src] = "'self' 'nonce'"
|
|
92
|
-
|
|
93
|
-
config.logger.stream = File::NULL
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
RUBY
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "sets unique and per-request hanami.content_security_policy_nonce in Rack env" do
|
|
100
|
-
previous_nonces = []
|
|
101
|
-
3.times do
|
|
102
|
-
get "/index"
|
|
103
|
-
nonce = last_request.env["hanami.content_security_policy_nonce"]
|
|
104
|
-
|
|
105
|
-
expect(nonce).to match(/\A[A-Za-z0-9\-_]{22}\z/)
|
|
106
|
-
expect(previous_nonces).not_to include nonce
|
|
107
|
-
|
|
108
|
-
previous_nonces << nonce
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "accepts custom nonce generator proc without arguments" do
|
|
113
|
-
Hanami.app.config.actions.content_security_policy_nonce_generator = -> { "foobar" }
|
|
114
|
-
|
|
115
|
-
get "/index"
|
|
116
|
-
|
|
117
|
-
expect(last_request.env["hanami.content_security_policy_nonce"]).to eql("foobar")
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "accepts custom nonce generator proc with Rack request as argument" do
|
|
121
|
-
Hanami.app.config.actions.content_security_policy_nonce_generator = ->(request) { request }
|
|
122
|
-
|
|
123
|
-
get "/index"
|
|
124
|
-
|
|
125
|
-
expect(last_request.env["hanami.content_security_policy_nonce"]).to be_a(Rack::Request)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it "substitutes 'nonce' in the CSP header" do
|
|
129
|
-
get "/index"
|
|
130
|
-
nonce = last_request.env["hanami.content_security_policy_nonce"]
|
|
131
|
-
|
|
132
|
-
expect(last_response.get_header("Content-Security-Policy")).to match(/script-src 'self' 'nonce-#{nonce}'/)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it "behaves the same with explicitly added middleware" do
|
|
136
|
-
Hanami.app.config.middleware.use Hanami::Middleware::ContentSecurityPolicyNonce
|
|
137
|
-
get "/index"
|
|
138
|
-
|
|
139
|
-
expect(last_request.env["hanami.content_security_policy_nonce"]).to match(/\A[A-Za-z0-9\-_]{22}\z/)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
describe "content_security_policy_nonce" do
|
|
143
|
-
it "renders the current nonce" do
|
|
144
|
-
get "/index"
|
|
145
|
-
nonce = last_request.env["hanami.content_security_policy_nonce"]
|
|
146
|
-
|
|
147
|
-
expect(last_response.body).to include(%(<style nonce="#{nonce}">))
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe "stylesheet_tag" do
|
|
152
|
-
it "renders the correct nonce unless remote URL or nonce set to false" do
|
|
153
|
-
get "/index"
|
|
154
|
-
nonce = last_request.env["hanami.content_security_policy_nonce"]
|
|
155
|
-
|
|
156
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" nonce="#{nonce}" class="nonce-true">))
|
|
157
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" class="nonce-false">))
|
|
158
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" nonce="explicit" class="nonce-explicit">))
|
|
159
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" nonce="#{nonce}" class="nonce-generated">))
|
|
160
|
-
expect(last_response.body).to include(%(<link href="https://example.com/app.css" type="text/css" rel="stylesheet" class="nonce-absolute">))
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
describe "javascript_tag" do
|
|
165
|
-
it "renders the correct nonce unless remote URL or nonce set to false" do
|
|
166
|
-
get "/index"
|
|
167
|
-
nonce = last_request.env["hanami.content_security_policy_nonce"]
|
|
168
|
-
|
|
169
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" nonce="#{nonce}" class="nonce-true"></script>))
|
|
170
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" class="nonce-false"></script>))
|
|
171
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" nonce="explicit" class="nonce-explicit"></script>))
|
|
172
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" nonce="#{nonce}" class="nonce-generated"></script>))
|
|
173
|
-
expect(last_response.body).to include(%(<script src="https://example.com/app.js" type="text/javascript" class="nonce-absolute"></script>))
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
context "CSP disabled" do
|
|
179
|
-
def before_prepare
|
|
180
|
-
write "config/app.rb", <<~RUBY
|
|
181
|
-
require "hanami"
|
|
182
|
-
|
|
183
|
-
module TestApp
|
|
184
|
-
class App < Hanami::App
|
|
185
|
-
config.actions.content_security_policy = false
|
|
186
|
-
|
|
187
|
-
config.logger.stream = File::NULL
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
RUBY
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it "does not set hanami.content_security_policy_nonce in Rack env" do
|
|
194
|
-
get "/index"
|
|
195
|
-
|
|
196
|
-
expect(last_request.env).to_not have_key "hanami.content_security_policy_nonce"
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
it "does not produce a CSP header" do
|
|
200
|
-
get "/index"
|
|
201
|
-
|
|
202
|
-
expect(last_response.headers).to_not have_key "Content-Security-Policy"
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
it "disables the content_security_policy_nonce helper" do
|
|
206
|
-
get "/index"
|
|
207
|
-
|
|
208
|
-
expect(last_response.body).to match(/<style nonce="">/)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it "behaves the same with explicitly added middleware" do
|
|
212
|
-
Hanami.app.config.middleware.use Hanami::Middleware::ContentSecurityPolicyNonce
|
|
213
|
-
get "/index"
|
|
214
|
-
|
|
215
|
-
expect(last_response.headers).to_not have_key "Content-Security-Policy"
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
describe "content_security_policy_nonce" do
|
|
219
|
-
it "renders nothing" do
|
|
220
|
-
get "/index"
|
|
221
|
-
|
|
222
|
-
expect(last_response.body).to include(%(<style nonce="">))
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe "stylesheet_tag" do
|
|
227
|
-
it "renders the correct explicit nonce only" do
|
|
228
|
-
get "/index"
|
|
229
|
-
|
|
230
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" class="nonce-true">))
|
|
231
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" class="nonce-false">))
|
|
232
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" nonce="explicit" class="nonce-explicit">))
|
|
233
|
-
expect(last_response.body).to include(%(<link href="/assets/app-KUHJPSX7.css" type="text/css" rel="stylesheet" class="nonce-generated">))
|
|
234
|
-
expect(last_response.body).to include(%(<link href="https://example.com/app.css" type="text/css" rel="stylesheet" class="nonce-absolute">))
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
describe "javascript_tag" do
|
|
239
|
-
it "renders the correct explicit nonce only" do
|
|
240
|
-
get "/index"
|
|
241
|
-
|
|
242
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" class="nonce-true"></script>))
|
|
243
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" class="nonce-false"></script>))
|
|
244
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" nonce="explicit" class="nonce-explicit"></script>))
|
|
245
|
-
expect(last_response.body).to include(%(<script src="/assets/app-LSLFPUMX.js" type="text/javascript" class="nonce-generated"></script>))
|
|
246
|
-
expect(last_response.body).to include(%(<script src="https://example.com/app.js" type="text/javascript" class="nonce-absolute"></script>))
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "json"
|
|
4
|
-
require "rack/test"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Web / Rendering detailed errors", :app_integration do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
|
|
9
|
-
let(:app) { Hanami.app }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
with_directory(@dir = make_tmp_directory) do
|
|
13
|
-
write "config/app.rb", <<~RUBY
|
|
14
|
-
require "hanami"
|
|
15
|
-
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
18
|
-
config.logger.stream = File.new("/dev/null", "w")
|
|
19
|
-
config.render_detailed_errors = true
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "config/routes.rb", <<~RUBY
|
|
25
|
-
module TestApp
|
|
26
|
-
class Routes < Hanami::Routes
|
|
27
|
-
get "error", to: "error"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
RUBY
|
|
31
|
-
|
|
32
|
-
write "app/actions/error.rb", <<~RUBY
|
|
33
|
-
module TestApp
|
|
34
|
-
module Actions
|
|
35
|
-
class Error < Hanami::Action
|
|
36
|
-
def handle(*)
|
|
37
|
-
raise "oops"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
RUBY
|
|
43
|
-
|
|
44
|
-
before_prepare if respond_to?(:before_prepare)
|
|
45
|
-
require "hanami/prepare"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "HTML request" do
|
|
50
|
-
it "renders a detailed HTML error page" do
|
|
51
|
-
get "/error", {}, "HTTP_ACCEPT" => "text/html"
|
|
52
|
-
|
|
53
|
-
expect(last_response.status).to eq 500
|
|
54
|
-
|
|
55
|
-
html = Capybara.string(last_response.body)
|
|
56
|
-
expect(html).to have_selector("header", text: "RuntimeError at /error")
|
|
57
|
-
expect(html).to have_selector("ul.frames li.application", text: "app/actions/error.rb")
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "renders a detailed HTML error page and returns a 404 status for a not found error" do
|
|
61
|
-
get "/__not_found__", {}, "HTTP_ACCEPT" => "text/html"
|
|
62
|
-
|
|
63
|
-
expect(last_response.status).to eq 404
|
|
64
|
-
|
|
65
|
-
html = Capybara.string(last_response.body)
|
|
66
|
-
expect(html).to have_selector("header", text: "Hanami::Router::NotFoundError at /__not_found__")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe "Other request types" do
|
|
71
|
-
it "renders a detailed error page in text" do
|
|
72
|
-
get "/error", {}, "HTTP_ACCEPT" => "application/json"
|
|
73
|
-
|
|
74
|
-
expect(last_response.status).to eq 500
|
|
75
|
-
|
|
76
|
-
expect(last_response.body).to include "RuntimeError at /error"
|
|
77
|
-
expect(last_response.body).to match %r{App backtrace.+app/actions/error.rb}m
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "renders a detailed error page in text and returns a 404 status for a not found error" do
|
|
81
|
-
get "/__not_found__", {}, "HTTP_ACCEPT" => "text/html"
|
|
82
|
-
|
|
83
|
-
expect(last_response.status).to eq 404
|
|
84
|
-
|
|
85
|
-
expect(last_response.body).to include "Hanami::Router::NotFoundError at /__not_found__"
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe "render_detailed_errors config disabled" do
|
|
90
|
-
def before_prepare
|
|
91
|
-
write "config/app.rb", <<~RUBY
|
|
92
|
-
require "hanami"
|
|
93
|
-
|
|
94
|
-
module TestApp
|
|
95
|
-
class App < Hanami::App
|
|
96
|
-
config.logger.stream = File.new("/dev/null", "w")
|
|
97
|
-
config.render_detailed_errors = false
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
RUBY
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "raises errors from within the app" do
|
|
104
|
-
expect { get "/error" }.to raise_error(RuntimeError, "oops")
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|