Commit Graph

15787 Commits

Author SHA1 Message Date
Eugene Kenny
797a7c5a62 Fix typos in RequestForgeryProtection docs [ci-skip] 2023-08-03 13:58:26 +01: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]: 61960e7b37767140e9af68bd5373e06dce08492d
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]: 401cd97923fb52c8f8c458b8cb276b338e0b20f3
[2]: d5ad92ced1786b742c3ecce3cb60d851c7200bc9
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