Commit Graph

11636 Commits

Author SHA1 Message Date
Matthew Draper
7025d7769d For now, we will keep sorting the tests.
This reverts commits e969c928463e329fd6529ac59cad96385c538ffb and
bd2b3fbe54e750ba97469a7896e8d143d6dfd465.
2014-09-05 23:33:27 +09:30
Xavier Noria
4dfe140ef3 code gardening in ActionController::Renderers
* Renames _handle_render_options to _render_to_body_with_renderer, which is more
  intention-revealing.

* The name of the dynamically generated method for a renderer with key :js was
  "_render_option_js".

  That name is too weak. :js is an option if you see the render argument as just
  a generic options hash, but in the context of renderers that's the renderer
  key, is what identifies the renderer.

  Now "_render_with_renderer_js" is generated instead, which is crystal clear.

* The name of the dynamically generated method for the renderer was constructed
  using string literals in a few places. That is now encapsulated in a method.

* Since we were on it, also removed a couple of redundant selfs.
2014-09-04 00:45:01 +02:00
Kasper Timm Hansen
28eecd934b Ship with rails-html-sanitizer instead. 2014-09-03 20:27:59 +02:00
Matthew Draper
2f52f96988 Leave all our tests as order_dependent! for now
We're seeing too many failures to believe otherwise.

This reverts commits bc116a55ca3dd9f63a1f1ca7ade3623885adcc57,
cbde413df3839e06dd14e3c220e9800af91e83ab,
bf0a67931dd8e58f6f878b9510ae818ae1f29a3a, and
2440933fe2c27b27bcafcd9019717800db2641aa.
2014-09-02 23:55:34 +09:30
Sammy Larbi
2fae37f0ac Allow polymorphic routes with nil when a route can still be drawn
Suppose you have two resources routed in the following manner:

```ruby
resources :blogs do
  resources :posts
end

resources :posts
```

When using polymorphic resource routing like `url_for([@blog, @post])`, and `@blog` is `nil` Rails should still try to match the route to the top-level posts resource.

Fixes #16754
2014-08-31 11:39:46 -05:00
Robin Dupret
84c0f73c8d Refer to the library name instead of the constant
When we are loading a component and we want to know its version, we are
actually not speaking about the constant but the library itself.

[ci skip]

[Godfrey Chan & Xavier Noria]
2014-08-30 11:58:23 +02:00
Xavier Noria
4c917dae9a Merge pull request #16644 from Agis-/drb-tests-actionpack-vagrant
Use system /tmp for temp files when testing actionpack
2014-08-30 09:49:13 +02:00
David Heinemeier Hansson
7475b43cdb Merge branch 'master' of github.com:rails/rails 2014-08-29 14:54:08 -07:00
Peter Suschlik
a59a9b7f72 Don't rescue IPAddr::InvalidAddressError
IPAddr::InvalidAddressError does not exist in Ruby 1.9.3
and fails for JRuby in 1.9 mode.

As IPAddr::InvalidAddressError is a subclass of ArgumentError
(via IPAddr::Error) just rescuing ArgumentError is fine.
2014-08-29 09:05:31 +02:00
Aaron Patterson
6d86762fd8 Merge pull request #16637 from Agis-/redirect-with-constraint-route
Fix the router ignoring constraints when used together with a redirect route
2014-08-28 10:33:40 -07:00
Akira Matsuda
b7d649d2ff Test everything
This actually was testing test everything, so why not do it simpler?
2014-08-28 14:40:54 +09:00
Akira Matsuda
e969c92846 AP test files does no more need to be alphabetically sorted here 2014-08-28 14:38:42 +09:00
schneems
0b1a87f73c Refactor out Dir.glob from ActionDispatch::Static
Dir.glob can be a security concern. The original use was to provide logic of fallback files. Example a request to `/` should render the file from `/public/index.html`. We can replace the dir glob with the specific logic it represents. The glob {,index,index.html} will look for the current path, then in the directory of the path with index file and then in the directory of the path with index.html. This PR replaces the glob logic by manually checking each potential match. Best case scenario this results in one less file API request, worst case, this has one more file API request.

Related to #16464

Update: added a test for when a file of a given name (`public/bar.html` and a directory `public/bar` both exist in the same root directory. Changed logic to accommodate this scenario.
2014-08-27 13:03:08 -05:00
Santiago Pastorino
f1a5e1520f Merge pull request #16717 from splattael/keygenerator
Use less iterations for KeyGenerator in tests
2014-08-27 11:51:36 -03:00
Yves Senn
20e7f08ecc minor changelog formatting changes. 2014-08-27 12:09:21 +02:00
Peter Suschlik
03e660e768 Use less iterations for KeyGenerator in tests
This commit improves performance of cookie tests:

Ruby  |   After  |   Before
----- | --------:| --------:
MRI   |    5.03s |     9.28s
JRuby |   25.45s |  1648.23s

Please note the improvement for JRuby.
2014-08-27 11:34:17 +02:00
Agis-
d78f3f0ec3 Don't ignore constraints in redirect routes
402c2af550
introduced a regression that caused any constraints added to redirect routes
to be ignored.

Fixes #16605
2014-08-25 00:18:25 +03:00
schneems
8e31fa3b72 Address comments on Gzip implementation
- don't mutate PATH_INFO in env, test
- test fallback content type matches Rack::File
- change assertion style
- make HTTP_ACCEPT_ENCODING comparison case insensitive
- return gzip path from method instead of true/false so we don't have to assume later
- don't allocate un-needed hash.

Original comments:

https://github.com/rails/rails/commit/
cfaaacd9763642e91761de54c90669a88d772e5a#commitcomment-7468728

cc @jeremy
2014-08-24 15:58:16 -05:00
Agis-
b7ab73a4e2 Use system /tmp when testing actionpack
c64bff2c87
added support and enabled parallel execution of the actionpack tests.

However it introduced c64bff2c87
since one cannot connect to a socket file that's inside a Vagrant synced folder
due to security restrictions, and DRb tries to.

Also rename the temporary files to make it obvious that they're rails-related,
since now they're placed outside the project's directory.

Fixes c64bff2c87
2014-08-22 22:03:41 +03:00
Sam Aarons
f9a84bb236 Refactor ActionDispatch::RemoteIp
Refactored IP address checking in ActionDispatch::RemoteIp to rely on
the IPAddr class instead of the unwieldly regular expression to match
IP addresses. This commit keeps the same api but allows users to pass
IPAddr objects to config.action_dispatch.trusted_proxies in addition
to passing strings and regular expressions.

Example:

    # config/environments/production.rb
    config.action_dispatch.trusted_proxies = IPAddr.new('4.8.15.0/16')
2014-08-21 18:38:08 -07:00
Guo Xiang Tan
9212042631 Improve router test.
We should assert that routes will not be recognized if the verbs do
not match.
2014-08-21 16:35:39 +08:00
Guo Xiang Tan
d3eb92d95a Avoid duplicating routes for HEAD requests.
Follow up to rails#15321

Instead of duplicating the routes, we will first match the HEAD request to
HEAD routes. If no match is found, we will then map the HEAD request to
GET routes.
2014-08-21 16:35:39 +08:00
schneems
cfaaacd976 Enable gzip compression by default
If someone is using ActionDispatch::Static to serve assets and makes it past the `match?` then the file exists on disk and it will be served. This PR adds in logic that checks to see if the file being served is already compressed (via gzip) and on disk, if it is it will be served as long as the client can handle gzip encoding. If not, then a non gzip file will be served.

This additional logic slows down an individual asset request but should speed up the consumer experience as compressed files are served and production applications should be delivered with a CDN. This PR allows a CDN to cache a gzip file by setting the `Vary` header appropriately. In net this should speed up a production application that are using Rails as an origin for a CDN. Non-asset request speed is not affected in this PR.
2014-08-20 22:33:06 -05:00
David Heinemeier Hansson
6a23bf0f4c Preparing for 4.2.0.beta1 release 2014-08-19 19:32:51 -07:00
Jeremy Kemper
79d50ce310 Merge pull request #16570 from bradleybuda/breach-mitigation-mask-csrf-token
CSRF token mask from breach-mitigation-rails gem
2014-08-19 18:17:07 -07:00
Bradley Buda
69fc0e1b5e Auth token mask from breach-mitigation-rails gem
This merges in the code from the breach-mitigation-rails gem that masks
authenticity tokens on each request by XORing them with a random set of
bytes. The masking is used to make it impossible for an attacker to
steal a CSRF token from an SSL session by using techniques like the
BREACH attack.

The patch is pretty simple - I've copied over the [relevant
code](https://github.com/meldium/breach-mitigation-rails/blob/master/lib/breach_mitigation/masking_secrets.rb)
and updated the tests to pass, mostly by adjusting stubs and mocks.
2014-08-19 15:28:07 -07:00
Rafael Mendonça França
08f209614b Use released rails-deprecated_sanitizer 2014-08-19 16:45:31 -03:00
Rafael Mendonça França
fad9e729f1 Fix the rails-dom-testing dependecy 2014-08-19 16:41:38 -03:00
Rafael Mendonça França
d59a24d543 Protect against error when parsing parameters with Bad Request
Related with #11795.
2014-08-19 15:36:05 -03:00
Jeremy Kemper
4d1d81d338 Merge pull request #16299 from sikachu/ps-safer-ac-params
Update `ActionController::Parameters` to be more secure on parameters handling
2014-08-19 11:31:38 -07:00
Vijay Dev
41231ef6c6 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	actionpack/lib/action_controller/metal/mime_responds.rb
	actionview/lib/action_view/vendor/html-scanner/html/sanitizer.rb
	activerecord/lib/active_record/type/value.rb
2014-08-19 16:28:53 +00:00
Godfrey Chan
0d4d52a1cf Add missing require 2014-08-18 21:33:00 -07:00
Prem Sichanugrist
3fcbbc8a1c User #to_hash instead of calling super
Ruby 1.9.3 does not implement Hash#to_h, so we can't call `super` on it.
2014-08-18 23:42:42 -04:00
Prem Sichanugrist
3591dd59e0 Fix failing test on several methods on Parameter
* `each`
* `each_pair`
* `delete`
* `select!`
2014-08-18 20:42:46 -04:00
Prem Sichanugrist
0663e8f179 Seperate Parameters accessors and mutators tests 2014-08-18 20:42:46 -04:00
Prem Sichanugrist
9704379c78 Refactor code to reduce duplicate self.class.new 2014-08-18 20:42:45 -04:00
Prem Sichanugrist
bd7f47190e Add missing Hash methods to AC::Parameters
This is to make sure that `permitted` status is maintained on the
resulting object.

I found these methods that needs to be redefined by looking for
`self.class.new` in the code.

* extract!
* transform_keys
* transform_values
2014-08-18 20:42:45 -04:00
Prem Sichanugrist
5109740c6b Make AC::Params#to_h return Hash with safe keys
`ActionController::Parameters#to_h` now returns a `Hash` with
unpermitted keys removed. This change is to reflect on a security
concern where some method performed on an `ActionController::Parameters`
may yield a `Hash` object which does not maintain `permitted?` status.
If you would like to get a `Hash` with all the keys intact, duplicate
and mark it as permitted before calling `#to_h`.

    params = ActionController::Parameters.new(name: 'Senjougahara Hitagi')
    params.to_h # => {}

    unsafe_params = params.dup.permit!
    unsafe_params.to_h # => {"name"=>"Senjougahara Hitagi"}

    safe_params = params.permit(:name)
    safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}

This change is consider a stopgap as we cannot chage the code to stop
`ActionController::Parameters` to inherit from
`HashWithIndifferentAccess` in the next minor release.

Also, adding a CHANGELOG entry to mention that
`ActionController::Parameters` will not inheriting from
`HashWithIndifferentAccess` in the next major version.
2014-08-18 20:42:45 -04:00
Rafael Mendonça França
9cb4d3e03b Deprecate TagAssertion instead of removing 2014-08-18 20:20:41 -03:00
Santiago Pastorino
6b32a4f371 Bump rack dependency 2014-08-18 16:10:58 -03:00
Akira Matsuda
b30b99c615 Expectations first 2014-08-18 15:40:53 +09:00
Rafael Mendonça França
d2d809868c Merge pull request #15889 from carnesmedia/model-name
Use #model_name on instances instead of classes
2014-08-17 23:01:13 -03:00
Rafael Mendonça França
cdc00aba62 Merge branch 'loofah'
Conflicts:
	Gemfile
2014-08-17 22:51:13 -03:00
Rafael Mendonça França
37a298db39 Merge pull request #16533 from lucasmazza/lm-named-routes-helper
Deprecate NamedRouteCollection#helpers.
2014-08-17 22:47:52 -03:00
Rafael Mendonça França
c78da4d5c4 Merge branch 'master' into loofah
Conflicts:
	actionpack/CHANGELOG.md
2014-08-17 22:38:22 -03:00
Lucas Mazza
9ee64f07f7 Deprecate NamedRouteCollection#helpers.
This method was removed at 210b338db20b1cdd0684f40bd78b52ed16148b99 but it is
used by third party gems to check if a named route was defined. To help on the
upgrade path on 4.2.0 we bring it back and emit a deprecation warning.
2014-08-17 22:36:22 -03:00
Rafael Mendonça França
eced6f8118 Merge pull request #16294 from bf4/code_tools
Update, unify, encapsulate, and fix various code tools in Rails
2014-08-17 22:12:23 -03:00
Godfrey Chan
e158ee50e6 Use AS::JSON for (de)serializing cookies
Use the Active Support JSON encoder for cookie jars using the `:json` or
`:hybrid` serializer. This allows you to serialize custom Ruby objects into
cookies by defining the `#as_json` hook on such objects.

Fixes #16520.
2014-08-17 12:41:42 -07:00
Godfrey Chan
a485633b16 responders 1.x won't do it. Told you to RTFM for details! 2014-08-17 12:19:23 -07:00
Godfrey Chan
b662273df3 The gem is called 'responders' 2014-08-17 11:58:17 -07:00