Commit Graph

5846 Commits

Author SHA1 Message Date
Rafael França
8788c7ce84 Merge pull request #22906 from bf4/rendering_exceptions
Add ActionController:Renderers test
2016-01-04 21:12:11 -02:00
Benjamin Fleischer
f27360af04 Add ActionController:Renderers test
To complement actionpack/test/controller/metal/renderers_test.rb
2016-01-03 22:51:45 -06:00
Anton Davydov
7d74b73a06 Fix typo in test desctiption [skip ci] 2016-01-04 00:11:03 +03:00
Benjamin Fleischer
1c361ea356 Test ActionController::Renderers::use_renderers 2015-12-31 13:07:58 -06:00
Kasper Timm Hansen
4ff5f6a15b Merge pull request #22850 from prathamesh-sonpatki/fix_ac_params_unsafe_h_2
Fix AC::Parameters#to_unsafe_h to return all unfiltered values
2015-12-31 09:04:42 +01:00
Prathamesh Sonpatki
28f648dbc7 Fix AC::Parameters#to_unsafe_h to return all unfiltered values
- AC::Parameters#convert_parameters_to_hashes should return filtered or
  unfiltered values based on whether it is called from `to_h` or `to_unsafe_h`
  instead of always defaulting to `to_h`.
- Fixes #22841
2015-12-31 12:32:29 +05:30
Rafael França
1f85e1c9f3 Merge pull request #22826 from timrogers/actiondispatch-ssl-config
Configurable redirect and secure cookies for ActionDispatch::SSL
2015-12-31 03:25:47 -02:00
Prathamesh Sonpatki
07af4dfd00 Fix test for AC::Parameters#to_unsafe_h
- Test should call `to_unsafe_h` instead of `to_h`
2015-12-30 20:54:46 +05:30
Richard Schneeman
cc5ae3e6df Merge pull request #22830 from jcoyne/parameters_include
Add AC::Parameters#include?
2015-12-29 14:14:51 -06:00
Jorge Bejar
44ca804229 Format from Accept headers have higher precedence than path extension format 2015-12-29 13:43:14 -03:00
Jorge Bejar
9a85da9367 Rely on default Mime format when MimeNegotiation#format_from_path_extension is not a valid type
Closes #22747
2015-12-29 13:42:57 -03:00
Justin Coyne
ff8a62d1d0 Add AC::Parameters#include?
Fixes #22818
2015-12-29 10:11:26 -06:00
Tim Rogers
32b1c90837 Flexible configuration for ActionDispatch::SSL 2015-12-29 13:07:51 +00:00
Rafael Mendonça França
d182c22e91 Currectly test the Middleware#== 2015-12-22 17:09:26 -02:00
Jon Moss
0c5287a668 Add #== back to ActionDispatch::MiddlewareStack::Middleware
This was causing bug #22738 to occur. Also added extra tests to make
sure everything is A-OK.
2015-12-21 19:55:10 -05:00
Rafael França
027d964d89 Merge pull request #22650 from derekprior/dp-actionpack-warnings
Fix "instance variable not initialized" in tests
2015-12-18 12:49:36 -02:00
Rafael França
b5c13fcdaa Merge pull request #20797 from byroot/prevent-url-for-ac-parameters
Prevent ActionController::Parameters in url_for
2015-12-18 12:47:38 -02:00
Derek Prior
31ef17a5eb
Fix "instance variable not initialized" in tests
The ActionPack test suite had a handful of these warnings when run. This
was due to `assert_response` being tested outside the context of a
controller instance where those instance variables would already have
been initialized.
2015-12-17 21:20:25 -05:00
Kasper Timm Hansen
4b46c5ce83 Only dup Ruby's Hash and Array.
When calling `to_h` on an `ActionController::Parameters` instance it would
`deep_dup` its internal parameters.

This inadvertently called `dup` on a passed Active Record model which would
create new models. Fix by only dupping Ruby's Arrays and Hashes.
2015-12-17 21:55:03 +01:00
Derek Prior
dc4429ca3b
Deprecate redirect_to :back
Applications that use `redirect_to :back` can be forced to 500 by
clients that do not send the HTTP `Referer` (sic) header.
`redirect_back` requires the user to consider this possibility up front
and avoids this trivially-caused application error.
2015-12-16 11:42:25 -05:00
Derek Prior
13fd5586ce
Add redirect_back for safer referrer redirects
`redirect_to :back` is a somewhat common pattern in Rails apps, but it
is not completely safe. There are a number of circumstances where HTTP
referrer information is not available on the request. This happens often
with bot traffic and occasionally to user traffic depending on browser
security settings.

When there is no referrer available on the request, `redirect_to :back`
will raise `ActionController::RedirectBackError`, usually resulting in
an application error.

`redirect_back` takes a required `fallback_location` keyword argument
that specifies the redirect when the referrer information is not
available.  This prevents 500 errors caused by
`ActionController::RedirectBackError`.
2015-12-16 11:42:05 -05:00
Tony Ta
2eda1a98e0 deletes code commented out in 72160d9f 2015-12-15 22:28:50 -08:00
Sean Griffin
1ad94e760d Merge pull request #14212 from tylerhunt/fix-token-regex
Handle tab in token authentication header.
2015-12-15 10:59:54 -07:00
Jean Boussier
4752e7d837 Prevent ActionController::Parameters from being passed to url_for directly 2015-12-15 13:16:54 +01:00
Sam Stephenson
99caf9ae7e Add fragment_cache_key macro for controller-wide fragment cache key prefixes 2015-12-14 19:53:43 -06:00
Sean Griffin
1dc1c8e40b Merge pull request #22564 from maximeg/legit_name_errors
Don't catch all NameError to reraise as ActionController::RoutingError
2015-12-14 10:17:42 -07:00
Prem Sichanugrist
6d4aef984c Make Parameters#to_h and #to_unsafe_h return HWIA
This makes these two methods to be more inline with the previous
behavior of Parameters as Parameters used to be inherited from HWIA.

Fixes #21391
2015-12-14 10:28:54 -05:00
Maxime Garcia
d3dd3847bc Don't catch all NameError to reraise as ActionController::RoutingError #22368 2015-12-12 11:22:08 +01:00
Jon Atack
c6fe614e45 Show redirect response code in assert_response messages
Follow-up to PR #19977, which helpfully added the redirection path to the error message of assert_response if response is a redirection, but which removed the response code, obscuring the type of redirect.

This PR:

- brings back the response code in the error message,

- updates the tests so the new messages can be tested,

- and adds test cases for the change.
2015-12-11 18:18:08 +01:00
Rafael França
b0e5fc2737 Merge pull request #22514 from prathamesh-sonpatki/use-assert-over-assert-predicate
Use assert over assert_predicate in assert_response
2015-12-11 14:11:15 -02:00
Santiago Pastorino
b11bca98bf Merge pull request #20831 from jmbejar/rails-api-json-error-response
Rails API: Ability to return error responses in json format also in development
2015-12-09 15:26:46 -03:00
Jorge Bejar
84e8accd6f Do not add format key to request_params
I did this change but it is affecting how the request params end up
after being processed by the router.

To be in the safe side, I just take the format from the extension in the
URL when is not present in those params and it's being used only for the
`Request#formats` method
2015-12-09 10:53:46 -03:00
Jorge Bejar
6fa2023c81 DebugException initialize with a response_format value 2015-12-09 10:53:45 -03:00
Jorge Bejar
05d89410bf Fix some edge cases in AD::DebugExceptions in rails api apps 2015-12-09 10:53:44 -03:00
Jorge Bejar
83b4e9073f Response when error should be formatted properly in Rails API if local request 2015-12-09 10:53:41 -03:00
eileencodes
b05801754f Fix make_response! when called by serve in RouteSet
All of our tests were testing the `ActionController::Live` behavior in a
standalone environment, without going through the router or behaving
like a real application.

This resulted in `ActionController::Live` throwing the exception
`undefined method 'request' for #<ActionDispatch::Request:0x00000003ad1148>`
because `make_response!` was expecting a response instead of a request.

The expectation of a response came from `set_response!` in non-router
tests setting the response and passing it to `make_response!`. In the
case of an application we would hit `serve` in `RouteSet` first which
would send us to `make_response!` with a request sent instead of a
response.

The changes here remove `set_response!` so `make_response!` always
receives a request.

Thanks to KalabiYau for help with the investigation and solution.

Fixes #22524

[Eileen M. Uchitelle & KalabiYau]
2015-12-09 08:19:07 -05:00
Jorge Bejar
b79bfaadaf Use URL path extension as format in bad params exception handling 2015-12-08 21:23:47 -03:00
eileencodes
3979403781 Change the protect_from_forgery prepend default to false
Per this comment
https://github.com/rails/rails/pull/18334#issuecomment-69234050 we want
`protect_from_forgery` to default to `prepend: false`.

`protect_from_forgery` will now be insterted into the callback chain at the
point it is called in your application. This is useful for cases where you
want to `protect_from_forgery` after you perform required authentication
callbacks or other callbacks that are required to run after forgery protection.

If you want `protect_from_forgery` callbacks to always run first, regardless of
position they are called in your application, then you can add `prepend: true`
to your `protect_from_forgery` call.

Example:

```ruby
protect_from_forgery prepend: true
```
2015-12-07 10:38:26 -05:00
eileencodes
492b134433 Push before_sending to super class
We want to get rid of the `Live::Response` so we are consolidating methods
from `Live::Response` and `Response` by merging them together.

This adds an `#empty` method to the request so we don't need to
hard-code the empty array each time we call an empty
`ActionDispatch::Request`.

The work here is a continuation on combining controller and integration
test code bases into one.
2015-12-06 15:32:40 -05:00
Eileen M. Uchitelle
67688aa739 Merge pull request #22453 from wjessop/use_action_dispatch_default_tld_length
Test against the real value of tld_length unless explicitly set
2015-12-06 13:21:38 -05:00
Prathamesh Sonpatki
b247116210 Use assert over assert_predicate in assert_response
- `assert_predicate` appends its own error message at the end of message
  generated by `assert_response` and because of that the error message
  displays the whole `response` object.
- For eg.

  Expected response to be a <success>, but was a redirect to <http://test.host/posts>.
  Expected #<ActionDispatch::TestResponse:0x007fb1cc1cf6f8....(lambda)>}>> to be successful?.

- Complete message can be found here -
  https://gist.github.com/prathamesh-sonpatki/055afb74b66108e71ded#file-gistfile1-txt-L19.

- After this change the message from `assert_predicate` won't be
  displayed and only message generated by `assert_response` will be shown
  as follows:

  Expected response to be a <success>, but was a redirect to <http://test.host/posts>
2015-12-06 21:39:59 +05:30
Will Jessop
e8bfaa58bd Test against the real value of tld_length unless explicitly set
There were two places where the tld_length default
was hard-coded to 1, both overriding the real default
value of ActionDispatch::Http::URL.tld_length in this
set of tests.

This commit removes both of those, relying on the
actual value of ActionDispatch::Http::URL.tld_length,
unless it's specifically overridden.
2015-12-04 16:40:08 +00:00
Prathamesh Sonpatki
1ee87e42ca Add redirection path in the error message of assert_response if response is :redirect
- If the assert_response is checking for any non-redirect response like
  :success and actual response is :redirect then, the error message displayed
  was -

     Expected response to be a <success>, but was <302>

- This commit adds the redirect path to the error message of
  assert_response if the response is :redirect.
  So above message is changed to -

     Expected response to be a <success>, but was a redirect to <http://test.host/posts/lol>
2015-12-04 13:13:25 +05:30
Arthur Nogueira Neves
3513f80e53 Merge pull request #22371 from yui-knk/better_mount_error
Brush up errors of `ActionDispatch::Routing::Mapper#mount`
2015-11-28 11:29:46 -05:00
yui-knk
f8f7e66f5f Brush up errors of ActionDispatch::Routing::Mapper#mount
* Integrate to raise `ArgumentError`
* Detailed error message when `path` is not defined
* Add a test case, invalid rack app is passed
2015-11-28 10:50:11 +09:00
Arthur Nogueira Neves
9afb0b9c43 Merge pull request #21241 from pdg137/master
In url_for, never append ? when the query string is empty anyway.
2015-11-26 16:10:46 -05:00
Rafael França
e1e6499ede Merge pull request #22263 from mastahyeti/csrf-origin-check
Add option to verify Origin header in CSRF checks

[Jeremy Daer + Rafael Mendonça França]
2015-11-26 14:23:50 -02:00
Ben Toews
85783534fc Add option to verify Origin header in CSRF checks 2015-11-25 15:06:12 -07:00
Rafael França
40acdcfb7c Merge pull request #22172 from tijmenb/fix-source-in-show-exception
Add text template for source code
2015-11-24 02:11:09 -02:00
Sean Griffin
8404ed6408 Merge pull request #17928 from sergey-alekseev/remove-unused-form-data-method 2015-11-23 14:33:11 -07:00