Commit Graph

15969 Commits

Author SHA1 Message Date
Rafael Mendonça França f2b1ff4eec
Bump dynamic controller and action segments yet again 2023-09-09 19:30:53 +00:00
Akhil G Krishnan 61a9c1a92a Ruby code block indentation issue fix
[skip ci] indentation fix

[skip ci] review changes added

[skip ci] indentation fix
2023-09-07 01:14:48 +05:30
Ryuta Kamizono 5415d3a19a Remove "proc to update web drivers." [ci-skip]
Follow-up to #48847.

This was originally "The webdrivers gem uses this proc to update web
drivers.".
2023-09-06 13:23:14 +09:00
euglena1215 9d2a7f89ee
Prevent `NoMethodError` in extract_value when specifying non-existent keys
Introduced in https://github.com/rails/rails/pull/49042, the method `ActionController::Parameters#extract_value` promises to replace utility methods that were previously defined as private methods in controllers.
However, it currently throws a `NoMethodError` when passed a non-existent key.

`params` is dependent on client requests and is thus beyond the application's control.
Rather than throwing a `NoMethodError`, it would be more convenient for the method to return `nil`.
2023-08-31 22:31:24 +09:00
Nikita Vasilevsky da7a6da4e7
Add `extract_value` method to `ActionController::Parameters`
This commit adds `extract_value` method to `ActionController::Parameters`
as a primary way to extract composite `id` values serialized from
`ActiveRecord::Base#to_param` called on a model with a composite primary key.
2023-08-25 22:34:10 +00:00
Rafael Mendonça França 4df85d7089
Merge pull request #49029 from technicalpickles/abstractcontroller_base-action_methods-performance
Improve performance of AbstractController::Base#action_methods
2023-08-24 11:41:04 -04:00
Rafael Mendonça França dc3da021ee
Fix comments and indentation 2023-08-24 15:22:34 +00:00
Josh Nichols b2afa8b3fb
Improve performance of AbstractController::Base#action_methods
I was benchmarking some specs in my app, and saw this code come up in the
memory_profiler. It is by no means the biggest memory allocation, but it
is straightforward to make a slight improvement.

Primarily, this saves allocating one array by using concat instead of +
to add public_instance_methods(false).

That ends up being 10% less memory for my benchmark (3 actions), and 6%
faster.

```
Calculating -------------------------------------
            original     8.352k memsize (   208.000  retained)
                        22.000  objects (     2.000  retained)
                         6.000  strings (     0.000  retained)
         refactored3     7.616k memsize (   408.000  retained)
                        11.000  objects (     7.000  retained)
                         3.000  strings (     3.000  retained)

Comparison:
         refactored3:       7616 allocated
            original:       8352 allocated - 1.10x more
Warming up --------------------------------------
            original     2.326k i/100ms
         refactored3     2.441k i/100ms
Calculating -------------------------------------
            original     23.336k (± 0.7%) i/s -    118.626k in   5.083658s
         refactored3     24.692k (± 1.2%) i/s -    124.491k in   5.042345s

Comparison:
            original:    23336.0 i/s
         refactored3:    24692.5 i/s - 1.06x  faster
```

Benchmark and results are also posted to https://gist.github.com/technicalpickles/4a4ae6a9e2c42963af43a89f75e768fe
2023-08-24 09:30:50 -04:00
Jean Boussier 6beb15c04a Add some :nodoc: to SyntaxErrorProxy and friends
None of this is public API.
2023-08-24 09:52:18 +02:00
Rafael Mendonça França 818bfc269a
Remove deprecation messages from actionpack test suite
The 6.1 cache format that is the default is deprecated.
2023-08-23 18:43:35 +00:00
Sean Doyle 0f4ab82082 Ensure `response.parsed_body` support for pattern matching
Both `Nokogiri` and `Minitest` have merged the PRs mentioned to
integrate support for Ruby's Pattern matching
(https://github.com/sparklemotion/nokogiri/pull/2523 and
https://github.com/minitest/minitest/pull/936, respectively).

This commit adds coverage for those new assertions, and incorporates
examples into the documentation for the `response.parsed_body` method.

In order to incorporate pattern-matching support for JSON responses,
this commit changes the response parser to call `JSON.parse` with
[object_class: ActiveSupport::HashWithIndifferentAccess][object_class],
since String instances for `Hash` keys are incompatible with Ruby's
syntactically pattern matching.

For example:

```ruby
irb(main):001:0> json = {"key" => "value"}
=> {"key"=>"value"}
irb(main):002:0> json in {key: /value/}
=> false

irb(main):001:0> json = {"key" => "value"}
=> {"key"=>"value"}
irb(main):002:0> json in {"key" => /value/}
.../3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/lib/irb/workspace.rb:113:in `eval': (irb):2: syntax error, unexpected terminator, expecting literal content or tSTRING_DBEG or tSTRING_DVAR or tLABEL_END (SyntaxError)
json in {"key" => /value/}
             ^

        .../ruby/3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/exe/irb:9:in `<top (required)>'
        .../ruby/3.2.0/bin/irb:25:in `load'
        .../ruby/3.2.0/bin/irb:25:in `<main>'
```

When the Hash maps String keys to Symbol keys, it's able to be pattern
matched:

```ruby
irb(main):005:0> json = {"key" => "value"}.with_indifferent_access
=> {"key"=>"value"}
irb(main):006:0> json in {key: /value/}
=> true
```

[object_class]: https://docs.ruby-lang.org/en/3.2/JSON.html#module-JSON-label-Parsing+Options
2023-08-23 13:28:02 -04:00
Rafael Mendonça França 24876e6a79
Merge PR #48950 2023-08-21 19:27:53 +00:00
Rafael Mendonça França 3642668935
Merge pull request #48941 from skipkayhil/hm-show-correct-blocked-hosts
Fix host display when X_FORWARDED_HOST authorized
2023-08-21 15:05:44 -04:00
Guillermo Iguaran 5a21634407
Merge pull request #48956 from skipkayhil/hm-rack-lint-show-exceptions-failsafe
Add test coverage for ShowExceptions failsafe
2023-08-18 16:08:41 -07:00
Guillermo Iguaran 4ec3a986d5
Merge pull request #48959 from skipkayhil/hm-clean-filters-requires
Remove uneeded requires of core_ext/string/filters
2023-08-18 16:03:44 -07:00
Rafael Mendonça França c82d624ea1
Fix documentation of with_routing in the class level
There is no assertions inside it.
2023-08-18 22:21:06 +00:00
Rafael Mendonça França 08cd280866
Use class method module instead of DSL
This will make sure documentation is generated for the module.
2023-08-18 22:11:48 +00:00
Hartley McGuire ff6e885d59
Remove uneeded requires of core_ext/string/filters
`actionpack/lib/action_dispatch/routing.rb`
- added: 013745151b
- removed: 93034ad7fe

`activejob/lib/active_job/log_subscriber.rb`
- added: b314ab555e
- removed: 5ab2034730

`activemodel/lib/active_model/errors.rb`
- added: cf7fac7e29
- removed: 9de6457ab0

`activerecord/lib/active_record/core.rb`
- added: b3bfa361c5
- removed: e1066f450d

`activesupport/lib/active_support/core_ext/module/introspection.rb`
- added: 358ac36edf
- removed: 167b4153ca

`activesupport/lib/active_support/duration.rb`
- added: 75924c4517
- removed: a91ea1d510

`railties/lib/rails/commands/server/server_command.rb`
- added: f217364893
- removed: 553b86fc75

`railties/lib/rails/command/base.rb`
- added: 6813edc7d9
- removed: b617a561d8
2023-08-16 17:39:25 -04:00
Hartley McGuire 6bf2ee09f7
Add test coverage for ShowExceptions failsafe
This adds additional test coverage to ShowExceptions, since one of the
possible responses it creates was not previously tested. Because of the
previous [addition][1] of Rack::Lint, this also demonstrates that the
Content-Type header needed to be fixed.

[1]: 339dda4a82
2023-08-16 16:00:25 -04:00
Akira Matsuda 5cf742ef51
ERB is no longer in use here since c2e756a944 2023-08-17 04:46:35 +09:00
Yuki Nishijima 72c5270e45 Add support for Playwright as a driver for system tests 2023-08-16 16:28:28 +09:00
Hartley McGuire 11ef3cecf0
Fix host display when X_FORWARDED_HOST authorized
Previously, when a Request had a non-authorized HTTP_HOST but an
authorized HTTP_X_FORWARDED_HOST, the HTTP_X_FORWARDED_HOST value would
be displayed as the one being blocked. However, this could be confusing
for users since that value would already be added to `config.hosts`.

This commit addresses the issue by tweaking how the blocked host is
displayed. Instead of always displaying Request#host (which will return
X_FORWARDED_HOST when present whether or not that's the host being
blocked), each host being blocked will be displayed on its own.

Co-authored-by: Daniel Schlosser <Eusebius1920@users.noreply.github.com>
2023-08-15 03:27:13 -04:00
Matija Čupić eed1ac1782
Use relative path for screenshot metadata 2023-08-05 15:20:01 +02:00
Rafael Mendonça França 2df0e5fa0c
Merge pull request #48857 from seanpdoyle/fixture-file-upload-rename
Rename `fixture_file_upload` method to `file_fixture_upload`
2023-08-04 17:08:40 -04:00
Sean Doyle 6cafc49d2c Rename `fixture_file_upload` method to `file_fixture_upload`
The naming difference between the test harness' [file_fixture][] helper
made available through Active Support (along with the
`file_fixture_path` configuration value) and the integration test
harness' [fixture_file_upload][] is a constant source of confusion and
surprise.

Since Active Support is more ubiquitous, this commit renames the
`fixture_file_upload` method to `file_fixture_upload` to match the order
of words in `file_fixture` and `file_fixture_path`.

To preserve backwards compatibility, declare a `fixture_file_upload`
alias to be preserved into the future (or removed at a future point in
time).

[file_fixture]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
[fixture_file_upload]: https://edgeapi.rubyonrails.org/classes/ActionDispatch/TestProcess/FixtureFile.html#method-i-fixture_file_upload
2023-08-04 12:40:17 -04:00
Bryan Traywick a4633725d2 Fix NoMethodError when request Content-Type is blank. 2023-08-04 12:36:11 -04:00
Mike Dalessio 8a57ba8c0e
Update Action View and Dispatch to use Rails::Dom::Testing helpers
Use the helpers introduced in rails-dom-testing 2.2.0 instead of
managing the HTML parsers as was done in #48523.

See also related #47144 / ad79ed0e
2023-08-03 11:17:38 -04:00
Jean Boussier ee3117ba8a
Merge pull request #48863 from matteeyah/main
Save screenshot path on system test failure
2023-08-03 16:35:29 +02:00
Eugene Kenny 797a7c5a62 Fix typos in RequestForgeryProtection docs [ci-skip] 2023-08-03 13:58:26 +01:00
Matija Čupić a962fc3c9c
Save failure screenshot path in test metadata 2023-08-03 14:43:49 +02:00
Rafael Mendonça França e980f158a4
Merge pull request #48847 from seanpdoyle/omit-webdrivers-from-gemfile-template
Omit `webdrivers` gem from `Gemfile` template
2023-08-02 13:49:28 -04:00
Guillermo Iguaran 4c9a990ffd
Merge pull request #48855 from akhilgkrishnan/add-rack-link-to-debug-exception-missing-test
Add Rack::Lint to DebugExceptions missing test
2023-08-01 10:38:33 -07:00
Sean Doyle 9a53234695 Omit `webdrivers` gem from `Gemfile` template
As of Selenium 4.6, [the Selenium Manager is capable of managing Chrome
Driver installations and integrations][readme]. As of Selenium 4.11, the
Selenium Manager is capable of [capable of resolving the Chrome for
Testing installation][] path.

By omitting the `gem` declaration from the `Gemfile.tt`, newly generated
applications and applications updating their `Gemfile` in lockstep with
newer Rails versions can shed the dependency and avoid test failures
introduced by newly released Chrome versions (like, for example,
[titusfortner/webdrivers#247][]).

[readme]: 43f8ac436c (update-selenium-manager)
[titusfortner/webdrivers#247]: https://github.com/titusfortner/webdrivers/issues/247
[capable of resolving the Chrome for Testing installation]: https://github.com/rails/rails/pull/48847#issuecomment-1656756862

Co-authored-by: Titus Fortner <titusfortner@users.noreply.github.com>
2023-08-01 09:22:08 -04:00
Adrianna Chang 339dda4a82
Add `Rack::Lint` to `ActionDispatch::ShowExceptions` tests
This wraps test coverage for `ActionDispatch::ShowExpections` in
`Rack::Lint` middleware in order to validate that both
`ActionDispatch::ShowExceptions` and `ActionDispatch::PublicExceptions`
conform to the Rack SPEC.

It also ensures that the response headers returned by the *Exceptions
middleware respect casing (mixed case for Rack 2, lower case for Rack 3)
2023-08-01 09:18:59 -04:00
Nuno Silva 613e8fd0a1
Add Rack::Lint to `ActionDispatch::RemoteIp` tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

This adds additional test coverage to
`ActionDispatch::RemoteIp` to validate that its input and
output follow the Rack SPEC.

The only code testing this middleware are the ones for
`ActionDispatch::Request`.

Several changes were required to make the tests pass:

- `CONTENT_LENGTH` must be a string
- `SERVER_PORT` must be a string
- `HTTP_HOST` must be a string
- `rack.input` must be an IO object, with ASCII-8BIT encoding
     - By leveraging `Rack::MockRequest`, we can pass the symbol :input,
       and the string value, and it will be converted to an IO object
       with the correct encoding.
     - See [definition here](444dc8a130/lib/rack/mock_request.rb (L89-L97))
- using `Rack::MockRequest` also means that any symbol keys being passed
to setup the env, will be discarded. [Only string keys are copied.]444dc8a130/lib/rack/mock_request.rb (L156)
2023-07-31 08:13:04 +00:00
Akhil G Krishnan 7df276f938 Add Rack::Lint to DebugExceptions missing test 2023-07-31 13:19:32 +05:30
Guillermo Iguaran ad790cb2f6
Merge pull request #48837 from skipkayhil/hm-rack-lint-debug-exceptions
Add Rack::Lint to DebugExceptions tests
2023-07-30 23:58:34 -07:00
Hartley McGuire ac7ee278fd
Add Rack::Lint to DebugExceptions tests
This adds additional test coverage to DebugExceptions to validate that
its behavior conforms to the Rack SPEC.

The only changes necessary were to use dynamic header casing for
Content-Type and Content-Length
2023-07-29 16:49:10 -04:00
Akhil G Krishnan 15bca6e94d Add Rack::Lint to ActionDispatch::Reloader tests 2023-07-29 14:18:49 +05:30
Adrianna Chang 2401b336fb
Use expected casing for x-cascade headers in router
This commit changes the router to use the expected casing for the
x-cascade header: in Rack 2, this is mixed-case, and in Rack 3, this is
lower case.

This also fixes https://github.com/rails/rails/issues/47096.
2023-07-28 16:17:08 -04:00
Adrianna Chang 9d840a1719
Make ActionDispatch::SSL compatible with Rack 3.0
Rack 3 now allows response header values to be an Array when handling
multiple values. Newline encoded headers are no longer supported.

This commit updates `ActionDispatch::SSL#flag_cookies_as_secure!` to
be Rack-3 compliant by setting the `set-cookie` header to an Array
rather than a newline-separated String if the current Rack version is
3+.

Additionally, this commit adds `Rack::Lint` to the Rack app in the
middleware test suite so that we can ensure all of the tests are
compliant with the Rack SPEC.
2023-07-28 14:23:25 -04:00
Eileen M. Uchitelle 43be5c4dc4
Merge pull request #48839 from skipkayhil/hm-rack-lint-test-request
Fix TestRequest coercing SERVER_PORT to be an int
2023-07-28 14:08:47 -04:00
Guillermo Iguaran 1788f67431
Merge pull request #48812 from nunosilva800/ns-rack-lint-content-security-policy-middleware
Add Rack::Lint to ContentSecurityPolicy::Middleware tests
2023-07-28 10:27:26 -07:00
Guillermo Iguaran 0a39604161
Merge pull request #48805 from skipkayhil/hm-rack-lint-request-id
Add Rack::Lint to RequestId tests
2023-07-28 10:25:50 -07:00
Hartley McGuire 70335e0793
Fix TestRequest coercing SERVER_PORT to be an int
In both Rack 2 and Rack 3, all headers must be strings. SERVER_PORT has
an additional requirement that it must be an Integer (represented as a
string).

When using #port= on a TestRequest, the value passed has been coerced
into an integer since it was [introduced][1]. Since this is explicitly
incorrect per both Rack 2 and Rack SPEC, the coercion is removed.

This does have the potential to change the value for users who are
checking TestRequest#headers directly, but if they are using
Request#port the value will not change because #port also coerces values
to ints.

[1]: 61960e7b37
2023-07-28 13:02:27 -04:00
Nuno Silva 04c61163bf
Add Rack::Lint to `ActionDispatch::ServerTiming` tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

This adds additional test coverage to `ActionDispatch::ServerTiming` to
validate that its input and output follow the Rack SPEC.

The `Server-Timing` header definition was moved to
`ActionDispatch::Constants` and is now downcased to match the Rack 3
SPEC.

The tests that rely on a `Concurrent::CyclicBarrier` ("events are
tracked by thread") were changed since passing the required proc in the
env is not compatible with the SPEC:

```
Rack::Lint::LintError: env variable proc has non-string value
```

The same can be achieved by invoking the proc as a child Rack app.
2023-07-28 15:24:32 +00:00
Hartley McGuire b2da0053aa
Add Rack::Lint to RequestId tests
This adds additional test coverage to RequestId to validate that its
input and output follow the Rack SPEC.

In this case, the only changes necessary were to the Request tests. This
is due to the fact that the Request and Response tests use different
classes for their Response headers. The Response tests simulate a Rails
app, where the Response headers will be a Rack::Headers object for
compatbility with both Rack 2 and 3. However, since the Request tests
are only using the Hash returned by the test app, the tests must use a
downcased header to support both Rack 2 and Rack 3.
2023-07-28 10:29:31 -04:00
Eileen M. Uchitelle dda937fa62
Merge pull request #48819 from skipkayhil/hm-doc-integration-tweaks
Add and remove some links in IntegrationTest docs [ci skip]
2023-07-28 08:54:53 -04:00
Eileen M. Uchitelle 924a371e38
Merge pull request #48788 from ylecuyer/fix-selenium-tests-yle
Fix: Do not execute selenium driver_path if it is a string.
2023-07-28 08:53:25 -04:00
Nuno Silva d1381dc654
Add Rack::Lint to ContentSecurityPolicy::Middleware tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

This adds additional test coverage to
`ContentSecurityPolicy::Middleware` to validate that its input and
output follow the Rack SPEC.

The changes made are because of:
- [Response Headers must be lower case](6d16306192/UPGRADE-GUIDE.md (response-headers-must-be-lower-case))

Added tests to ensure that CSP headers set by an app are not overridden,
regardless of the casing.
An example of this is Sidekiq: https://github.com/sidekiq/sidekiq/blob/b3225ce/lib/sidekiq/web/application.rb#L353
2023-07-28 09:37:23 +00:00
Guillermo Iguaran ff232b1190 Move X-Request-Id header name to ActionDispatch::Constants 2023-07-27 16:03:52 -07:00
Guillermo Iguaran 5b45803984 Use constants defined in ActionDispatch::Constants instead of conditional assignments 2023-07-27 15:21:18 -07:00
Guillermo Iguaran 1fd79abb54 Define constants for headers in ActionDispatch::Constants to avoid conditional checks around multiple classes 2023-07-27 15:20:33 -07:00
Guillermo Iguaran 71ce2fd309
Merge pull request #48825 from nunosilva800/ns-rack-lint-executor
Add Rack::Lint to ActionDispatch::Executor tests
2023-07-27 14:43:00 -07:00
Yoann Lecuyer bd8a6778a0 Fix: Do not execute selenium driver_path if it is a string. 2023-07-27 22:57:49 +02:00
Guillermo Iguaran 034cae80a9
Merge pull request #48818 from skipkayhil/hm-rack-list-permissions-policy
Add Rack::Lint to PermissionsPolicy tests
2023-07-27 13:56:03 -07:00
Eileen M. Uchitelle c9a104008f
Merge pull request #48832 from skipkayhil/hm-rack-lint-debug-locks
Add Rack::Lint to DebugLocks tests
2023-07-27 16:51:53 -04:00
Eileen M. Uchitelle 6f396113d0
Merge pull request #48810 from nunosilva800/ns-rack-lint-callbacks
Add Rack::Lint to ActionDispatch::Callbacks tests
2023-07-27 16:51:20 -04:00
Hartley McGuire fe5eb3d0fb
Add Rack::Lint to DebugLocks tests
This adds additional test coverage to HostAuthorization to validate that
its behavior conforms to Rack SPEC.

This fixes the following two issues in the reponse returned by
DebugLocks:
- Rack::Lint::Error: uppercase character in header name
  Content-{Type/Length}
- Rack::Lint::Error: a header value must be a String or Array of
  Strings, but the value of 'content-length' is an Integer
2023-07-27 16:33:41 -04:00
Guillermo Iguaran d835023f1b
Merge pull request #48831 from skipkayhil/hm-rack-lint-static
Add Rack::Lint to Static tests
2023-07-27 13:26:28 -07:00
Guillermo Iguaran 4b3172035c
Merge pull request #48813 from skipkayhil/hm-rack-lint-actionable-actionable-exceptions
Add Rack::Lint to ActionableExceptions tests
2023-07-27 13:22:47 -07:00
Guillermo Iguaran 546dad9904
Merge pull request #48829 from nunosilva800/ns-rack-lint-middleware-stack
Add Rack::Lint to ActionDispatch::MiddlewareStack tests
2023-07-27 13:12:42 -07:00
Guillermo Iguaran 1d34845e3f
Merge pull request #48811 from nunosilva800/ns-rack-lint-assume-ssl
Add Rack::Lint to AssumeSSL middleware tests
2023-07-27 12:56:44 -07:00
Guillermo Iguaran 3d3585bd5e
Merge pull request #48814 from skipkayhil/hm-rack-lint-host-authorization
Add Rack::Lint to HostAuthorization tests
2023-07-27 12:49:09 -07:00
Hartley McGuire b580df616b
Add Rack::Lint to Static tests
This adds additional test coverage to Static to validate that its
behavior conforms to the Rack SPEC.

The test changes are just downcasing headers where appropriate:
- the Static `headers` params is purely user configured headers, so its
  reasonable to expect these shoud be correct for an application's Rack
  version
- header assertions can use downcased headers because Rack::MockRequest
  returns a Rack::Response, which uses Rack::Headers internally (so
  either casing will work)

Additionally, the unconditionally downcased headers in the Static
middleware were updated to be conditional based on the Rack version to
ensure that this middleware remains fully compatible with other Rack 2
middleware.
2023-07-27 15:48:43 -04:00
Nuno Silva 180cd9f5ac
Add Rack::Lint to ActionDispatch::MiddlewareStack tests
To ensure Rails is and remains compliant with [the Rack 3 spec](6d16306192/UPGRADE-GUIDE.md) we can add `Rack::Lint` to the Rails middleware tests.

This adds additional test coverage to `ActionDispatch::MiddlewareStack` to validate that its input and output follow the Rack SPEC.

In this case, no changes are required, and the additional test
will ensure this middleware remains compliant with the Rack SPEC.
2023-07-27 17:24:08 +00:00
Hartley McGuire f880da0f24
Refactor StaticTests to use single app builder
This commit refactors the StaticTests class in preparation for adding
Rack::Lint to the tests.

The first change is inlining the StaticTests module into the StaticTest
class. It was originally extracted into a module when Static was
[changed][1] to support passing multiple root paths, but support for
multiple paths has since been [removed][2].

The second change is to move all Rack App creation into a single method.
This will make it extremely easy to add Rack::Lint to the App in a
followup commit.

[1]: 401cd97923
[2]: d5ad92ced1
2023-07-27 12:10:32 -04:00
Nuno Silva 41365ae953
Add Rack::Lint to ActionDispatch::Executor tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

This adds additional test coverage to `ActionDispatch::Executor` to
validate that its input and output follow the Rack SPEC.

This also removes some tests that were asserting the body object
passed to `ActionDispatch::Executor` and not the Rack SPEC.
See also https://github.com/rack/rack/issues/2100.
2023-07-27 15:38:06 +00:00
Adrianna Chang cef3109856
Add ActionDispatch::Cookies middleware test with Rack::Lint
This adds an additional test to the ActionDispatch::Cookies middleware
test suite to ensure that the middleware sets the expected cookie header
when the request contains a cookie jar. Additionally, the test wraps the
Cookies middleware in Rack::Lint to ensure that ActionDispatch::Cookies
complies with the Rack SPEC.
2023-07-27 11:18:47 -04:00
Hartley McGuire 34947521d9
Add and remove some links in IntegrationTest docs
Add direct links to #get, #post, #parsed_body, and #open_session.

Remove links to Session when already on the Session page.
2023-07-26 18:14:07 -04:00
Hartley McGuire 4991525abb
Add Rack::Lint to PermissionsPolicy tests
This adds additional test coverage to PermissionsPolicy::Middleware to
validate that it conforms to the Rack SPEC.

The only changes necessary were to use the appropriate header casing for
Content-Type and Feature-Policy. Since this was the only usage of the
CONTENT_TYPE constant, I opted to remove it, but I can replace it with a
DeprecatedConstantProxy if that's more desirable.
2023-07-26 13:34:14 -04:00
Hartley McGuire 0c92013158
Add Rack::Lint to ActionableExceptions tests
This adds additional test coverage to ActionableExceptions to validate
that its behavior conforms to the Rack SPEC.

The changes neccesary were to ensure that Response headers are downcased
when using Rack 3. For Content-Type and Content-Length, this is trivial
because Rack provides constants who's casing is dependent on the version
(Rack 2 is mixed, and Rack 3 is downcased). Since Rack does not include
a LOCATION constant, the Response::LOCATION constant was updated to
have a downcased value when using Rack 3.

Additionally, there was some missing coverage for invalid redirect URLs
which was addressed as well.
2023-07-26 10:13:57 -04:00
Hartley McGuire 37522f1596
Add Rack::Lint to HostAuthorization tests
This adds additional test coverage to HostAuthorization to validate that
its behavior conforms to the Rack SPEC.

By using Rack:: constants for Content-Type and Content-Length, we are
able to use the "correct" versions of the headers for applications using
each Rack version.

Additionally, two tests had to be updated that use an ipv6 address
without brackets in the HOST header because Rack::Lint warned that these
addresses were not valid HOST values. Rack::Lint checks HOST headers using
`URI.parse("http://#{HOST}/")`, and from what I could find, this
requirement follows RFC 3986 Section 3.2.2:

```
host        = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture  ) "]"
IPvFuture  = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
```
2023-07-26 09:50:06 -04:00
Nuno Silva df2616e20b
Add Rack::Lint to AssumeSSL middleware tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

There was no test file for ActionDispatch::AssumeSSL, so this change
adds one and validating that its input and output follow the Rack SPEC.
2023-07-26 11:08:43 +00:00
Nuno Silva 425decee6f
Add Rack::Lint to ActionDispatch::Callbacks tests
This adds additional test coverage for ActionDispatch::Callbacks by
validating that its input and output follow the Rack SPEC.

The `"rack.input" => StringIO.new("")` header value raised the following error:

```
Rack::Lint::LintError: rack.input #<StringIO:0x00007fd7513fe550> does not have ASCII-8BIT as its external encoding
```

Since this header is not required for the test, it is now removed.
2023-07-26 08:52:23 +00:00
Ufuk Kayserilioglu c2b195e1e3
Change load error messages to use `Kernel#warn` instead of `$stderr.puts`
When development tools try to load Rails components, they sometimes end up loading files that will error out since a dependency is missing. In these cases, the tooling can catch the error and change its behaviour.

However, since the warning is printed directly to `$stderr`, the tooling cannot catch and suppress it easily, which ends up causing noise in the output of the tool.

This change makes Rails print these warnings using `Kernel#warn` instead, which can be suppressed by the tooling.
2023-07-21 00:38:12 +03:00
Samuel Williams 8fbf70c889
Improve cookie attribute assertions. 2023-07-19 15:36:57 +12:00
Samuel Williams b505e2358c
The JavaScript mime-type was updated in Rack 3.1 to `text/javascript`. 2023-07-19 15:36:57 +12:00
Samuel Williams 56c416e7c3
The request `rack.input` is optional. 2023-07-19 15:36:57 +12:00
Henrik Nyh cf166fb13c Doc and spec cookies.delete returning value 2023-07-12 12:08:35 +01:00
Kamil Gwóźdź 2c3504bdf1
AbstractController#internal_methods: ignore action_methods
xref https://github.com/rails/rails/pull/48559#issuecomment-1624321279
2023-07-09 21:05:58 +02:00
Guillermo Iguaran 1c0aeed2fb
Merge pull request #48575 from skipkayhil/hm-config-exception-level
Make the log level in DebugExceptions configurable
2023-06-27 10:17:45 -07:00
Xavier Noria 9294a55187 Fix indentation in ActionDispatch::Routing::RouteSet::Dispatcher 2023-06-27 16:15:09 +02:00
Carlos Antonio da Silva d9af9f1023 Avoid creating match object when checking for illegal header value
We can use `match?` to check against the illegal header value regexp,
since we don't need the match data result.
2023-06-27 09:40:35 -03:00
Guillermo Iguaran 10b4bd597f
Merge branch 'main' into hm-config-exception-level 2023-06-26 19:07:08 -07:00
John Hawthorn f1cdfc037f Fix rubocop warning 2023-06-26 15:17:43 -07:00
Zack Deveau 69e37c84e3 Added check for illegal HTTP header value in redirect_to
The set of legal characters for an HTTP header value is described
in https://datatracker.ietf.org/doc/html/rfc7230\#section-3.2.6.

This commit adds a check to redirect_to that ensures the
provided URL does not contain any of the illegal characters.

Downstream consumers of the resulting Location response header
may accidentally remove the header if it does not comply with the RFC
resulting in unexpected behavior.

Related to [CVE-2023-28362].
2023-06-26 14:51:39 -07:00
Hartley McGuire 519577ecc3
Make the log level in DebugExceptions configurable
This middleware has been logging at a FATAL level since the first
[commit][1] in Rails (the code originally lived in
actionpack/lib/action_controller/rescue.rb). However, FATAL is
documented in the Ruby Logger [docs][2] as being for "An unhandleable
error that results in a program crash.", which does not really apply to
this case since DebugExceptions is handling the error. A more
appropriate level would be ERROR, which the Ruby Logger docs describe as
"A handleable error condition."

This commit introduces a new configuration for the DebugExceptions log
level so that new apps will have it set to ERROR by default and ERROR
can eventually be made the default.

[1]: db045dbbf6
[2]: https://ruby-doc.org/3.2.1/stdlibs/logger/Logger/Severity.html
2023-06-25 23:11:39 -04:00
zzak dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
Guillermo Iguaran c20f8eb6b6
Merge pull request #48471 from mdh/improve-naming-of-local-secret-generation
Improve naming of local secret generation
2023-06-21 00:04:32 -07:00
Mike Dalessio 2362f57cd8
Update Action View and Action Dispatch to use HTML5 when available 2023-06-19 16:34:33 -04:00
Marek de Heus f75934f80d Improve naming of local secret generation
For local environments (def and test), we create a secret file. However this file is called development_secret.txt, which imho is confusing as it is used by both dev and test environments.

This commit renames the file and related code to local_secret.
2023-06-19 11:59:17 +02:00
zzak 9cfeedb718
💅 Wrap the AC::Meta::Streaming doc links
This way they look good on page, and in your editor.
2023-06-19 09:33:36 +09:00
zzak fd2ac22b54
Fixes to AC::Streaming docs
* Unlink the Rails module automatically
* Inline the documentation links for unicorn and passenger
* Use RDoc fixed-width for passenger_buffer_response instead of markdown
* TIL: about linking to headings, so fixed that for "Middlewares" section
2023-06-16 16:36:53 +09:00
Guillermo Iguaran 84540a6289
Merge pull request #48455 from rails/action_controller-streaming-body
Remove dependency on deprecated Rack::Chunked
2023-06-12 15:55:18 -07:00
Guillermo Iguaran af68c31d7f Remove dependency on deprecated Rack::Chunked
Import the used Rack::Chunked::Body as private AC::Streaming::Body
class and use it instead.
2023-06-11 20:48:37 -07:00
Joé Dupuis 7c3fc67c31 Test respond_to? :to_ary directly on RackBody
RackBody is the final body object returned by the Rack app
(`Rails.application`). This test that it conforms to the spec
instead of testing on the underlying response.
2023-06-11 19:42:22 -07:00
Guillermo Iguaran 0174283901 Undefine #to_ary in ActionController::Live::Buffer
ActionDispatch::Response delegates #to_ary to the internal ActionDispatch::Response::Buffer,
defining #to_ary is an indicator that the response body can be buffered and/or cached by
Rack middlewares, this is not the case for Live responses so we undefine it for this Buffer subclass.

Puma raises an exception trying to call #to_ary in Live::Buffer
expecting it to return an array if defined:

188f5da192/lib/puma/request.rb (L183-L186)
2023-06-11 04:07:48 -07:00
Joé Dupuis 45c90b7bd3 Rack spec requires mutable headers
The rack spec requires the header object to be an unfrozen hash.
c8e9822183/SPEC.rdoc?plain=1#L240

Rack::ETag was buffering and making a copy of the response,
so the freeze was not effective anyway.

Plus we are freezing the hash too early, preventing middlewares
from modifying it. It causes crash with gems like rack-livereload.
I started having crashes on some pages (like the internal
http://localhost:3000/rails/info/routes) because of rack-livereload
hitting the frozen hash after the rack 3 upgrade.

Also we're not consistent with the protection. We're not preventing
users from adding cookies. The cookie jar is already flushed,
therefore it doesn't try to change the headers and never triggers the
frozen hash error.
2023-06-11 01:32:31 -07:00
Hartley McGuire f7c6e2c8aa
Fix duplicate Content-Type header with Rack 2
Previously, `ActionDispatch::Static` would always merge a "content-type"
header into the headers returned from `Rack::Files`. However, this would
potentially lead to both a "Content-Type" header and a "content-type"
header when using Rack 2.

This commit fixes the issue by using `Rack::CONTENT_TYPE` to determine
which version of the header to set in `ActionDispatch::Static`. In both
versions of Rack it will use the same version of the header as
`Rack::Files`.

The tests added have to use `@app.call` instead of
`get()`/`Rack::MockRequest` because `Rack::Response` actually does the
correct thing already by using `Rack::Util::HeaderHash` so it covers up
the issue in tests.
2023-06-09 18:49:37 -04:00
Joé Dupuis efce114dde Force turbo reload on error.
Turbo frames on turbo-rails 1.4 (current default in Rails 7) don't
break out of the frame to load the error response from the DebugView
middleware like they used to. It requires the turbo-visit-control meta set to reload or it
fails silently.
2023-06-06 22:01:35 -07:00
Andrew Novoselac 37f3ce9930 Create a class level #with_routing helper.
Before each test, the helper creates a new RouteSet instance and yields it to the passed black. The routes are then reset after the test is completed.
2023-06-06 14:13:24 -04:00
Rafael Mendonça França 0e1800396d
Merge pull request #48397 from ThunderKey/improve-mime-regex
improve quoted parameters in mime types
2023-06-05 12:56:17 -04:00
Nicolas Erni 1071a39020 improve quoted parameters in mime types
Accept headers allow parameters to be passed. They can contain quotes
that need to be handled differently. These quoted strings can contain
commas, which are not considered as delimiters of accept headers.

Additionally, all parameters before the q-parameter should be used to
lookup the media-type as well. If no media-type with the parameters is
found, a fallback is introduced to the media-type without any parameters
to keep the same functionality as before.

Fix #48052
2023-06-05 12:53:08 +02:00
Petrik de Heus a84ef12221
Merge pull request #48383 from p8/fix/link-to-cookies
Fix link to ActionController::Cookies#cookies [ci-skip]
2023-06-02 18:13:54 +02:00
Petrik f492d51795 Fix link to ActionController::Cookies#cookies
The `cookies` method was not defined on ActionController::Base making the
permalink to the method not work.
Changing it to ActionController::Cookies make the reference a link.
2023-06-02 16:53:38 +02:00
Marek de Heus 39156c8812
Update actionpack/lib/action_controller/metal.rb
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-06-02 15:10:49 +02:00
Marek de Heus 0da0fc8979 Add missing docs for request.session 2023-06-02 15:04:21 +02:00
Jeremy Beker c34d1f0a68
Base case with our checks last in conditional 2023-05-30 20:49:45 +00:00
Jeremy Beker d00843aa13
Test case with our checks first in conditional 2023-05-30 20:49:44 +00:00
Jeremy Beker f1889f139d
Indentation correction via rubocop. 2023-05-30 20:49:41 +00:00
Jason Meller 1904a3031a
Re-order conditional for maybe better perf 2023-05-30 20:48:11 +00:00
Jason Meller afb847f1b7
Fix spelling error 2023-05-30 20:48:08 +00:00
Jason Meller 1bca0dc586
PR feedback 2023-05-30 20:47:52 +00:00
Jason Meller 4370293a68
Implement PR suggestions 2023-05-30 20:47:30 +00:00
Jason Meller e388ebe0f2
Attempt to fix rubocop warnings 2023-05-30 20:47:29 +00:00
Jason Meller a78d3e3207
Enable `bind_params` option in url_for helper
The url_for helper now supports a new option called `bind_params`.
This is very useful in situations where you only want to add a required
param that is part of the route's URL but for other route not append an
extraneous query param.

Given the following router...
```ruby
Rails.application.routes.draw do
  scope ":account_id" do
    get 'dashboard' => 'pages#dashboard', as: :dashboard
    get 'search/:term' => 'search#search', as: :search
  end
  delete 'signout' => 'sessions#destroy', as: :signout
end
```

And given the following `ApplicationController`
```ruby
  class ApplicationController < ActionController::Base
    def default_url_options
      { bind_params: { account_id: "foo" } }
    end
  end
```

The standard URLHelpers will now behave as follows:

```ruby
dashboard_path # => /foo/dashboard
dashboard_path(account_id: "bar") # => /bar/dashboard
signout_path # => /signout
signout_path(account_id: "bar") # => /signout?account_id=bar
search_path("quin") # => /foo/search/quin
```
2023-05-30 20:47:26 +00:00
Rafael Mendonça França 7eeaadb7fc
Merge pull request #48199 from JoeDupuis/remove-url-rewriter-tests
Remove UrlRewriter tests
2023-05-30 16:03:43 -04:00
Rafael Mendonça França 54de0cb2ee
Merge pull request #48293 from flavorjones/flavorjones-support-html5-sanitizer
Update Action View to use HTML5 standards-compliant sanitizers
2023-05-30 16:00:13 -04:00
zzak 7a014c07e2
Add a tiny more detail about the middleware stack 2023-05-29 16:43:34 +09:00
zzak 2b637b6850
Fix RDoc autolinks in ActionController::Metal 2023-05-29 16:01:00 +09:00
zzak 722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak 7765a693ee
Fix links for Renderers.add and Renderers.remove 2023-05-29 14:24:10 +09:00
Mike Dalessio 500ccaaeea
Update dependency on rails-html-sanitizer to ~>1.6
for HTML5 sanitizer support
2023-05-28 14:00:35 -04:00
Joé Dupuis acdfef2097 Remove UrlRewriter tests
UrlRewriter has been deleted in 2010 e68bfaf1fe
The url_rewriter_test is really testing url_for. Most of the tests are
identical.

This also move a couple tests that were not present in
`url_for_test.rb`.
2023-05-27 17:01:21 -07:00
Aaron Patterson 861795ed92
Refactor error highlight detection
Before this commit, some calls to render were hard-coding error
highlight as "not available".  This was causing some error pages to show
the "you should install error highlight" message even though the right
version of error highlight was installed.

This commit adds a delegate method to the DebugView class so that the
debugging related templates can just ask whether or not error highlight
is available via a method call.  That way we don't need to rely on
passing locals everywhere.  The down side is that this change requires
all "rescue" templates to be rendered within the context of a DebugView
class (but I think that's OK)
2023-05-25 09:27:35 -07:00
zzak 073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
zzak e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Rafael Mendonça França 61accb7dea
Merge pull request #45867 from jdufresne/show-rescuable-exceptions
Make the test environment show rescuable exceptions in responses
2023-05-24 13:45:45 -04:00
Rafael Mendonça França 5e34a9297b
Test behavior in unit test 2023-05-24 17:01:38 +00:00
Zeke Gabrielse 7d8cb154d4 Fix issue with empty values within delimited authorization header
When the Authorization header would contain a set of delimited values
where one or more values were blank, an ArgumentError would be raised.
This resolves that by removing blank values during parsing of the
Authorization header.
2023-05-22 15:27:03 -05:00
Jonathan Hefner 117c2b47b3 Add missing comma [ci-skip] 2023-05-21 16:24:02 -05:00
Guillermo Iguaran b44b881112 Register Mime type for image/webp automatically.
Although we rarely update this list now WebP can be considered
popular enough to be included.
2023-05-20 18:30:26 -07:00
Hartley McGuire d028c14b03
Link rescue_from from modules including Rescuable
Also add some additional words to make it clear that the modules also
implement handling the exceptions configured with rescue_from, because
it was not immediately clear that happened without reading the code.
2023-05-18 12:54:16 -04:00
Jonathan Hefner 4d240e0da3
Merge pull request #48251 from skipkayhil/hm-rm-explicit-alias-doc
Remove explicit "aliased as" documentation [ci skip]
2023-05-18 10:17:14 -05:00
Hartley McGuire b3c6a9adf0
Remove explicit "aliased as" documentation
Most of these are redundant because rdoc handles these itself, but
`titlecase` on `ActiveSupport::Inflector` does not exist so that one is
just incorrect.
2023-05-18 11:04:04 -04:00
Hartley McGuire 5cd144e7fb
Update and fixup ActionController::Parameters docs
- Small wording tweaks for grammar or consistency
- Add links to methods/classes when possible, and fix some cases where
  there were links but shouldn't be (`API`, `Testing`, etc.)
- Fixed `call-seq` for `each_key`
- Change `has_key?`, `key?`, and `member?` to aliases instead of
  delegates so that they are documented as aliases (This is how the
  methods are documented for Hash in Ruby)
- Remove explicit "also aliased as" docs because rdoc does this already
- Add `:nodoc:` to `EMPTY_ARRAY` and `EMPTY_HASH` constants since these
  are internal optimizations
2023-05-18 10:35:42 -04:00
Petrik 72c5a69b5f Clarify X-Cascade header in ShowExceptions middleware [ci-skip]
Clarify that the middleware looks at the `X-Cascade` header in the
response.

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-17 17:19:10 +02:00
Jon Dufresne e28f147329 Make the test environment show rescuable exceptions in responses
Background
----------

During integration tests, it is desirable for the application to respond
as closely as possible to the way it would in production. This improves
confidence that the application behavior acts as it should.

In Rails tests, one major mismatch between the test and production
environments is that exceptions raised during an HTTP request (e.g.
`ActiveRecord::RecordNotFound`) are re-raised within the test rather
than rescued and then converted to a 404 response.

Setting `config.action_dispatch.show_exceptions` to `true` will make the
test environment act like production, however, when an unexpected
internal server error occurs, the test will be left with a opaque 500
response rather than presenting a useful stack trace. This makes
debugging more difficult.

This leaves the developer with choosing between higher quality
integration tests or an improved debugging experience on a failure.

I propose that we can achieve both.

Solution
--------

Change the configuration option `config.action_dispatch.show_exceptions`
from a boolean to one of 3 values: `:all`, `:rescuable`, `:none`. The
values `:all` and `:none` behaves the same as the previous `true` and
`false` respectively. What was previously `true` (now `:all`) continues
to be the default for non-test environments.

The new `:rescuable` value is the new default for the test environment.
It will show exceptions in the response only for rescuable exceptions as
defined by `ActionDispatch::ExceptionWrapper.rescue_responses`. In the
event of an unexpected internal server error, the exception that caused
the error will still be raised within the test so as to provide a useful
stack trace and a good debugging experience.
2023-05-17 06:30:28 -07:00
Hartley McGuire 781a4a0159
Update and fixup ShowExceptions documentation
This commit adds documentation to ShowExceptions explaining how it
should be configured in Rails applications. In addition, it adds more
`<code>` blocks to fix the formatting of some code snippets and prevent
the page from linking to itself.
2023-05-16 14:06:54 -04:00
Igor S. Morozov 300b8e32c2
Content Security Policy: add `:unsafe_hashes` mapping 2023-05-13 01:48:13 +03:00
Joé Dupuis 4fd27842b8 Remove redundant protocol test for url_for
test_protocol_with_and_without_separators already has the same assertion.
2023-05-11 21:15:03 -07:00
Eileen M. Uchitelle 1769487bc2
Merge pull request #48123 from cpjmcquillan/cm/remove-redundant-test-setup
Remove redundant test
2023-05-09 09:28:36 -04:00
Connor McQuillan db8f573ada
Remove redundant test
This test was introduced in #19904.

In #21368 a bunch of test setup was removed, but the assignment
of `@set` was duplicated.

Removing the extraneous test setup means the test is identical to the
`test_cart_inspect` test.

This removes the test entirely.
2023-05-09 08:33:35 +01:00
Jonathan Hefner c924ba0df9 Support :message_pack as cookies serializer
This commit adds support for `:message_pack` and `:message_pack_allow_marshal`
as serializers for `config.action_dispatch.cookies_serializer`, just
like `config.active_support.message_serializer`.

The `:message_pack` serializer can fall back to deserializing with
`AS::JSON`, and the `:message_pack_allow_marshal` serializer can fall
back to deserializing with `AS::JSON` or `Marshal`.  Additionally, the
`:marshal`, `:json`, and `:hybrid` / `:json_allow_marshal` serializers
can now fall back to deserializing with `AS::MessagePack`.  These
behaviors make it easier to migrate between cookies serializers.
2023-05-08 15:00:08 -05:00
Guillermo Iguaran 06c219710a
Merge pull request #48148 from tindron/arbitrary-hash-arrays
[Fix #38698] Fix nested Arrays when permitting arbitrary Hashes
2023-05-07 22:42:26 -07:00
Guillermo Iguaran 15b662abb5
Merge pull request #48158 from JoeDupuis/fix-rack-3-body-stream-test
Fix failing buildkite build - action_pack [rack-3]
2023-05-07 20:34:55 -07:00
Jean Boussier 583afa1404 Optimize mime types validation in ActionView::LookupContext
Fix: https://github.com/rails/rails/issues/48156

The assumption here is that in the overwhelming majority of
cases, all formats are valid.

So we first check if any of the formats is invalid before duping
the details hash and filtering them.

Additonally, by exposing a (non-public) `valid_symbols?` method, we
can check symbols are valid without resporting to `Array#%` which
would needlessly duplicate the `formats` array.
2023-05-08 10:34:55 +09:00
Jean Boussier 06d2c2d15b Refactor ActionView::Template::Types to avoid delegation
The `Type` class was introduced in https://github.com/rails/rails/pull/23085
for the sole purpose of breaking the dependency of Action View on Action Dispatch.

Unless you are somehow running Action View standalone, this is actually
never used.

So instead of delegating, we can use constant swapping, this saves us
a useless layer.

Ultimately we could consider moving `Mime::Types` into Active Support
but it requires some more thoughts.
2023-05-08 10:34:46 +09:00
Joe Dupuis 5216400529 Fix body stream test on Rack 3.0 by rewinding the body stream.
Since 3.0, Rack doesn't guarantee rewindable request body streams.
Therefore Rack doesn't rewind the body after parsing the POST params
like it use to.
Since this is a test request, we can guarantee the stream is rewindable
and do it in the test.
2023-05-07 17:14:18 -07:00
Randy Stoller 8ed86b7e21
[Fix #38698] Fix nested Arrays when permitting arbitrary Hashes 2023-05-06 13:09:03 -07:00
Jean Boussier d5ff2bf222
Merge pull request #48067 from shouichi/document-flash-delete
document AD::FlashHash#delete [skip ci]
2023-04-27 17:04:05 +02:00
Shouichi Kamiya 7b64a759e1 document AD::FlashHash#delete [skip ci]
Co-authored-by: Seonggi Yang <seonggi.yang@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
Co-authored-by: oljfte <oljfte@gmail.com>
2023-04-27 13:26:35 +09:00
Jean Boussier 073d90c67d
Merge pull request #47735 from nirebu/nirebu/stop-root-string-allocation-in-helper
Do not allocate the first character when checking for relative paths
2023-04-26 12:08:01 +02:00
Petrik de Heus 40f6c12c24
Merge pull request #48044 from p8/docs/fix-headers
Escape namespaces in some doc headers [ci-skip]
2023-04-24 09:25:00 +02:00
Petrik f89588240f Escape namespaces in some doc headers [ci-skip]
Also move the CSP header from a method to the module.
2023-04-24 09:18:08 +02:00
Gareth Adams 8f3c6a1005 Make Rails cookies RFC6265-compliant with domain: :all
Rails has incorrectly been adding leading dots to cookie domain values
when the `domain: :all` option is present.

This leading dot was required in cookies based on [RFC 2965][rfc2965]
(October 2000), but [RFC 6265][rfc6265] (April 2011) changed that
behaviour, making a leading dot strictly incorrect. Todays browsers aim
to confirm to RFC6265 with repect to cookies.

The new behaviour is that *any* cookie with an explicitly passed domain
is sent to all matching subdomains[[ref][mdn]]. For a server to indicate
that only the exact origin server should receive the cookie, it should
instead pass *no* domain attribute.

Despite the change in behaviour, browser devtools often display a cookie
domain with a leading dot to indicate that it is valid for subdomains -
this prefixed domain is *not* necessarily the raw value that was passed
in the Set-Cookie header. This explains why it's a common belief among
developers that the leading dot is required.

RFC6265 standard gives UAs an algorithm to handle old-style cookie
domain parameters (they can drop a leading dot if present), so it's
unlikely that this error would ever have had any effect on web browsers.

However, cookies generated this way can't be processed by Ruby's own
CGI::Cookie class:

> CGI::Cookie.new "domain" => ".foo.bar", "name" => "foo"
ArgumentError: invalid domain: ".foo.bar"

Newer versions of the Ruby CGI library accomodate the same fallback
behaviour (dropping the extra dot) but this isn't a justification for it
being the right way to set a cookie.

[mdn]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#domain_attribute
[rfc2965]: https://www.rfc-editor.org/rfc/rfc2965#section-3.2
[rfc6265]: https://www.rfc-editor.org/rfc/rfc6265#section-4.1.1
2023-04-24 01:38:34 +01:00
Petrik 48b205989a Cleanup Action Pack documentation headers [ci-skip] 2023-04-22 20:40:39 +02:00
Petrik c0d501e818 Fix some doc headings naming [ci-skip]
Headings should use the name of library instead of the namespace.
2023-04-21 10:15:47 +02:00
Petrik 168c206e06 Add missing headers to Action Pack docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-20 22:24:43 +02:00
Jonathan Hefner d618a457c4 Replace backticks with RDoc markup [ci-skip]
Follow-up to #47933.

RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2023-04-16 18:26:50 -05:00
Renny Ren 80c6cd871a Update docs about SSE streaming response 2023-04-13 18:13:49 +08:00
zzak fdd0cb8b04
💅 Clean up changelog entry for #47877 2023-04-13 09:40:52 +09:00
Vipul A M bcc2e0c4e4
Merge pull request #47921 from luanzeba/route_source_changelog
Changelog entry for routes source location
2023-04-12 20:45:21 +05:30
Luan Vieira a154a08f2b
Changelog entry for routes source location
Change made in https://github.com/rails/rails/pull/47877
2023-04-12 10:54:40 -04:00
Aaron Patterson 2675c906b1
Merge pull request #47877 from luanzeba/route-source-location
Print source location when inspecting routes
2023-04-11 11:58:47 -07:00
Daniel Colson a00e548da7
Print source location when inspecting routes
In larger route files, or when routes are spread across multiple files,
it can be difficult to get from the output of the route inspector to the
relevant route definition.

This commit adds a route source location to the route, and uses that in
the HtmlTableFormatter (for rails/info and the debug exceptions
middleware) and the Expanded formatter (for `rails routes -E`).

To avoid doing extra work in production, it only sets the source location
in development.

This commit injects the application's backtrace cleaner so we can use it
to remove the rails root from the path. This also means we don't get
source locations for the routes defined by Rails.

If mounting an engine from a gem, we'll get a source location for where
we mount it in the application, but not for the routes defined in the
gem itself. That's probably good enough, since Rails already prints
routes for an engine separately under the title "Routes for
Foo::Engine".

Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: Luan Vieira <luanzeba@github.com>
Co-authored-by: Daniel Colson <composerinteralia@github.com>
2023-04-10 09:52:27 -04:00
zzak 5a4c212aca
Hide Rack internals from API docs 2023-04-06 16:39:38 +09:00
Petrik 3376ab5285 Add documentation intros for Action Controller and Action Dispatch
In 7c94708d24 the READMEs were included for
the main framework pages of the API documentation, except for Action Pack.
As Action Pack doesn't define any code in the ActionPack namespace, only
it's included modules (Action Dispatch, Action Controller and Abstract
Controller) are documented.

This adds documentation intro's to the main page for Action Controller
and Action Dispatch. The content was copied from the Action Pack README.
As Abstract Controller isn't mentioned there, it is skipped for now.
[ci-skip]
2023-04-02 17:34:35 +02:00
Hidde-Jan Jongsma 603b5cdde5 Alias ActionController::Parameters except as without 2023-03-29 10:56:58 +02:00
Rafael Mendonça França acd8fd142d
Merge pull request #47758 from sled/security/set-content-type-charset
Set charset in content type response headers (OWASP)
2023-03-25 11:24:43 -04:00
zzak 57b01b4633
Fix actionpack CHANGELOG lint error 2023-03-25 08:32:26 +09:00
Simon Schmid a9d191997b set charset in content type response headers 2023-03-24 10:17:04 +01:00
Nicolò Rebughini 14c6e04438 Do not allocate the first character when checking for relative paths
This is the same optimization applied in
a63ae913df
which I proposed in https://github.com/rails/rails/pull/47714

Here's the benchmark:

require "bundler/inline"

ROOT_STRING = '/'
TEST_PATH = "/some/path"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report("path[0]") do
   TEST_PATH[0] != ROOT_STRING
  end

  x.report("path.start_with?") do
   TEST_PATH.start_with?(ROOT_STRING)
  end

  x.compare!
end

Warming up --------------------------------------
             path[0]   942.044k i/100ms
    path.start_with?     1.556M i/100ms
Calculating -------------------------------------
             path[0]      9.463M (± 0.9%) i/s -     48.044M in   5.077358s
    path.start_with?     15.611M (± 0.2%) i/s -     79.352M in   5.083056s

Comparison:
    path.start_with?: 15611192.8 i/s
             path[0]:  9463245.0 i/s - 1.65x  slower
2023-03-22 16:18:24 +01:00
Andrew Novoselac 6902cbce1b Introducs `TestFixtures#fixture_paths`.
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
2023-03-14 19:02:56 -04:00
Rafael Mendonça França e64cbf75e9
Merge pull request #47597 from higher-pixels/fix-47535
Fixes 47535 - flag multiple cookies as secure
2023-03-13 13:54:08 -04:00
Jonathan Hefner 4bd6251a15 Remove obsolete AC::Rendering#_normalize_args
The sole purpose of `ActionController::Rendering#_normalize_args` is to
store the given block in `options[:update]`.  This behavior was added
long ago in 6923b392b7 (as [part of
`ActionController::Base#_normalize_options`][part-of]) to support RJS.
Rails no longer supports RJS, so this override is no longer necessary.

[part-of]: 6923b392b7 (diff-febf2f89e7c197d6a9a7077c96031c68b2b7ac4d8ce7ec634de92b164e5f69adR100)
2023-03-10 15:51:54 -06:00
Ron Shinall 45547e1ee7 Fix #47535 - flag multiple cookies as secure 2023-03-08 12:29:26 -05:00
Junichi Sato aacd909b7f
Give documentational consistency to authenticate_with_http_token [ci-skip] 2023-03-07 12:21:54 +09:00
Jason Kotchoff 69d50468cb Expand rails route search to all table content
Expands the search field on the rails/info/routes page to also search:
* Route name (with or without a _path and _url extension)
* HTTP Verb (eg. GET/POST/PUT etc.)
* Controller#Action

because it's not obvious that the search field is currently only
restricted to the route paths.
2023-03-03 17:14:33 +11:00
Rafael Mendonça França 696ccbc265
Remove deprecated `poltergeist` and `webkit` (capybara-webkit) driver registration for system testing 2023-03-03 00:38:23 +00:00
Rafael Mendonça França 1e70d0f5d3
Remove deprecated ability to assign a single value to `config.action_dispatch.trusted_proxies` 2023-03-03 00:38:22 +00:00
Rafael Mendonça França 689b277733
Remove deprecated behavior on `Request#content_type` 2023-03-03 00:38:21 +00:00
Rafael Mendonça França 787b81b620
Merge pull request #47488 from jkotchoff/rails-info-routes-layout-compaction
Line break long routes to prevent scrolling
2023-02-28 17:49:56 -05:00
Matthew Draper 629a32148c
Merge pull request #47477 from ioquatix/rack-3-static-lowercase-headers
Rack 3 static lowercase headers.
2023-02-26 20:33:54 +10:30
Matthew Draper e06844f69b Expect Static to set lowercase values in Vary 2023-02-26 19:36:29 +10:30
Jason Kotchoff b11131868f Line break long routes to prevent scrolling
Prevents horizontal scrolling on the rails/info/routes page when there
are long route names by introducing styled line breaks so that the table
will fit within the rendered width of the browser.

This is particularly relevant when there are a lot of nested namespaces
in a rails project and makes the page more readable, especially when
filtering with a search query.

The table headings have also been left-aligned so that they line up more
intuitively with the content and now that the table is no longer
horizontally scrolling, less space has been explicitly allocated for the
HTTP Verb column.
2023-02-24 05:16:30 +00:00
Nick Borromeo 92216ebb19 Create an ActionView::PathRegistry module
This is a refactor of the `Registry` module added in https://github.com/rails/rails/pull/47347. This is an attempt to
minimize the namespace conflcits that will happen when users will have a top level `Registry` module which can cause
incorrect behavior

Replace ActionView::ViewPaths::Registry with ActionView::PathRegistry
2023-02-23 16:53:57 -08:00
zzak d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Samuel Williams 152b6c9986
Prefer lowercase headers in `ActionDispatch::Static`.
`ActionDispatch::Static` uses mixed-case headers and merges them with
lower case headers. This produces duplicate headers. Prefer lowercase
headers to avoid this situation.
2023-02-23 20:24:17 +13:00
Gannon McGibbon 3f4a7734da Set ORIGINAL_FULLPATH header in controller tests
Since rails/rails#47296, nothing sets the fullpath early, so changing
the path of a request, and then calling original_fullpath returns the
updated fullpath. This is a controller testing specific bug as
integration tests and real requests always have this header set, so I
think controller tests should too.
2023-02-22 00:33:09 -06:00
John Hawthorn 28284fc186 Refactor into ViewPaths::Registry 2023-02-16 10:29:17 -08:00
Aaron Patterson 218ec10df8
Merge pull request #47092 from ioquatix/rack-3-streaming-body
Update `ActionDispatch::Response` to support streaming bodies.
2023-02-14 17:01:45 -08:00
Aaron Patterson e89b2e4271
Merge pull request #47147 from ioquatix/rack-3-headers-name-normalization
Normalize usage of "Headers".
2023-02-14 17:01:05 -08:00
zzak 0c71b60cfd
Add test for request.get_header("route_uri_pattern")
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-02-14 13:55:22 +09:00
Yasuo Honda f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Pedro de Jesus c426e46d76 Add body_stream.rewind before reading it on ActionPack::Request 2023-02-10 19:02:19 +00:00
Pedro de Jesus 75126b8dd4 Fix issue #46784 2023-02-10 17:27:49 +00:00
Carlos Antonio da Silva 643c2cbbff Fix changelog example in actionpack
`full_path` is actually `fullpath`, as described in the line above.
`filtered_path` exists only in the `request` object, not `response`.

[ci skip]
2023-02-09 09:08:17 -03:00
Rafael Mendonça França aa3fc0fca2
Merge pull request #47296 from ritikesh/filtered_path
use filtered_path in action_controller event payloads instead of fullpath
2023-02-08 13:29:10 -05:00