aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
Commit message (Collapse)AuthorAgeFilesLines
...
| * Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-253-4/+4
| |
* | Eagerly build the routing helper module after routes are committedAaron Patterson2018-09-252-9/+10
|/ | | | | | | | | | | | | | This commit eagerly builds the route helper module after the routes have been drawn and finalized. This allows us to cache the helper module but not have to worry about people accessing the module while route definition is "in-flight", and automatically deals with cache invalidation as the module is regenerated anytime someone redraws the routes. The restriction this commit introduces is that the url helper module can only be accessed *after* the routes are done being drawn. Refs #24554 and #32892
* Merge pull request #33829 from mtsmfm/encode-filenameKasper Timm Hansen2018-09-231-0/+37
|\ | | | | Encode Content-Disposition filenames on send_data and send_file
| * Encode Content-Disposition filenames on send_data and send_fileFumiaki MATSUSHIMA2018-09-131-0/+37
| |
* | Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-233-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* | Merge pull request #32932 from y-yagi/fixes_32920Yuji Yaginuma2018-09-201-0/+15
|\ \ | |/ |/| Add CSP nonce to `style-src` directive
| * Add CSP nonce to `style-src` directiveyuuji.yaginuma2018-05-191-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | For nonce, only `script-src` and` style-src` are meaningful in the definition of Content Security Policy Level 2. https://www.w3.org/TR/CSP2/#script-src-nonce-usage https://www.w3.org/TR/CSP2/#style-src-nonce-usage Therefore, I think that customization function not needs and it is enough to enable both directives inside the framework. Fixes #32920
* | Update ParameterFilter to yield original parametersPeter Zhu2018-08-221-2/+5
| |
* | Merge pull request #33499 from lsylvester/caller-ignore-pathsKasper Timm Hansen2018-08-151-0/+1
|\ \ | | | | | | use BacktraceCleaner for ActiveRecord verbose logging
| * | Use backtrace cleaner to clean up backtrace for verbose query logsLachlan Sylvester2018-08-141-0/+1
| | |
* | | Changelog for the new purpose metadata and improved testsAssain2018-08-131-8/+4
|/ /
* | Purpose Metadata For Signed And Encrypted CookiesAssain2018-08-121-0/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Purpose metadata prevents cookie values from being copy-pasted and ensures that the cookie is used only for its originally intended purpose. The Purpose and Expiry metadata are embedded inside signed/encrypted cookies and will not be readable on previous versions of Rails. We can switch off purpose and expiry metadata embedded in signed and encrypted cookies using config.action_dispatch.use_cookies_with_metadata = false if you want your cookies to be readable on older versions of Rails.
* | Remove Rubocop's comments from Rails code basebogdanvlviv2018-07-261-4/+0
| | | | | | | | | | | | | | | | | | | | PR#32381 added Rubocop's comments to some tests files in order to exclude `Performance/RedundantMerge`. Turn off `Performance` cops for tests files via `Exclude` in `.rubocop.yml`. Context https://github.com/rails/rails/pull/32381#discussion_r205212331
* | Merge pull request #32381 from q-centrix/update-codeclimate-configsRichard Schneeman2018-07-251-1/+5
|\ \ | | | | | | Turn on performance based cops
| * | Turn on performance based copsDillon Welch2018-07-231-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* | | Rails guides are now served over httpsPaul McMahon2018-07-241-5/+5
|/ / | | | | | | | | http links will be redirected to the https version, but still better to just directly link to the https version.
* | Add implicit to path conversion to uploaded file (#28676)Aaron Kromer2018-07-221-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add implicit to path conversion to uploaded file Ruby has a few implicit conversion protocols (e.g. `to_hash`, `to_str`, `to_path`, etc.). These are considered implicit conversion protocols because in certain instances Ruby (MRI core objects) will check if an argument responds to the appropriate protocol and automatically convert it when it does; this is why you can provide a `Pathname` instance into `File.read` without having to explicitly call `to_s`. ```ruby a_file_path = 'some/path/file.ext' File.write a_file_path, 'String Path Content' File.read a_file_path a_pathname = Pathname(a_file_path) File.write core_file, 'Pathname Content' File.read a_file_path core_file = File.new(a_pathname) File.write core_file, 'File Content' File.read core_file tmp_file = Tempfile.new('example') File.write tmp_file, 'Tempfile Content' File.read tmp_file ``` So how does an uploaded file work in such cases? ```ruby tmp_file = Tempfile.new('example') File.write tmp_file, 'Uploaded Content' uploaded_file = ActionDispatch::Http::UploadedFile.new(tempfile: tmp_file) File.read uploaded_file ``` It fails with a `TypeError`: no implicit conversion of ActionDispatch::Http::UploadedFile into String In order to make an uploaded file work it must be explicitly converted to a file path using `path`. ```ruby File.read uploaded_file.path ``` This requires any code that expects path/file like objects to either special case an uploaded file, re-implement the path conversion protocol to use `path`, or forces the developer to explicitly cast uploaded files to paths. This last option can sometimes be difficult to do when such calls are deep within the inner workings of libraries. Since an uploaded file already has a path it makes sense to implement the implicit "path" conversion protocol (just like `File` and `Tempfile`). This change allows uploaded file content to be treated more closely to regular file content, without requiring any special case handling or explicit conversion for common file utilities. * Note uploaded file path delegation in CHANGELOG
* | Show nested exceptions on the debug viewYuki Nishijima2018-07-152-15/+80
|/
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-132-3/+3
| | | | Follow up of #32605.
* Add support for prefetch-src directiveyuuji.yaginuma2018-05-031-0/+6
| | | | | | | Specification: https://w3c.github.io/webappsec-csp/#directive-prefetch-src This directive can already be used as an experimental feature in Chrome. Ref: https://bugs.chromium.org/p/chromium/issues/detail?id=801561
* Introduce ActionDispatch::DebugExceptions interceptorsGenadi Samokovarov2018-04-201-0/+24
| | | | | | | | | | | | | | Plugins interacting with the exceptions caught and displayed by ActionDispatch::DebugExceptions currently have to monkey patch it to get the much needed exception for their calculation. With DebugExceptions.register_interceptor, plugin authors can hook into DebugExceptions and process the exception, before being rendered. They can store it into the request and process it on the way back of the middleware chain execution or act on it straight in the interceptor. The interceptors can be play blocks, procs, lambdas or any object that responds to `#call`.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-196-11/+11
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Pass nonce to CSP policy from outsideAndrew White2018-04-181-21/+72
|
* Output only one nonce in CSP header per requestAndrey Novikov2018-04-171-5/+23
|
* Add WebSocket URI support to CSP DSL mappingsStephen Solis2018-04-121-0/+6
|
* Partially revert 0bfdd1dyuuji.yaginuma2018-04-071-1/+5
| | | | | The `Capybara.server=` proc acceptance restored in Capyara 3.0.1. Ref: https://github.com/teamcapybara/capybara/commit/8f115d94e035eca992036f16e50c1dce5f555c97
* Fix broken `ServerTest` with Capybara 3.0.0yuuji.yaginuma2018-04-061-5/+1
| | | | | | | It seems that it is no longer possible to specify the value held by `Capybara.server` as sever. Ref: https://github.com/teamcapybara/capybara/commit/ba7674086cbcd3b22d3614011815bc5d483e5960
* Merge pull request #32441 from composerinteralia/refute-notRafael França2018-04-041-1/+1
|\ | | | | Add custom RuboCop for `assert_not` over `refute`
| * Autocorrect `refute` RuboCop violationsDaniel Colson2018-04-031-1/+1
| | | | | | | | | | | | 73e7aab behaved as expected on codeship, failing the build with exactly these RuboCop violations. Hopefully `rubocop -a` will have been enough to get a passing build!
* | Add #dig to ActionDispatch::Request::Sessionclaudiob2018-04-041-0/+12
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Summary The `session` object is not a real Hash but responds to many methods of Hash such as `[]`, `[]`, `fetch`, `has_key?`. Since Ruby 2.3, Hash also supports a `dig` method. This commit adds a `dig` method to `ActionDispatch::Request::Session` with the same behavior as `Hash#dig`. This is useful if you store a hash in your session, such as: ```ruby session[:user] = { id: 1, avatar_url: "http://example.org/nyancat.jpg" } ``` Then you can shorten your code from `session[:user][:avatar_url]` to `session.dig :user, :avatar_url`. ### Other Information I cherry-picked a commit from https://github.com/rails/rails/pull/23864, and modify a bit. The changes are below: * Converts only the first key to a string adjust to the `fetch` method. * Fixes a test case because we cannot use the indifferent access since ee5b621e2f8fde380ea4bc75b0b9d6f98499f511.
* Use ASCII-8BIT paths in ActionDispatch::StaticAndrew White2018-03-221-1/+10
| | | | | | | | | | The rack gem returns PATH_INFO as an ASCII-8BIT encoded string but it was being converted to US-ASCII by the match? method because it was calling Rack::Utils.escape_path. To prevent incompatibile encoding warnings use ASCII-8BIT strings for the root path and let Ruby handle any filename encoding conversion. Fixes #32294, Closes #32314.
* Check exclude before flagging cookies as secure in ActionDispatch::SSL (#32262)Catherine Khuu2018-03-151-0/+8
| | | | | | | * Check exclude before flagging cookies as secure. * Update comments in ActionDispatch::SSL. [Catherine Khuu + Rafael Mendonça França]
* Fix routing inspector tests broken in ↵Kasper Timm Hansen2018-03-131-14/+15
| | | | | | | | | | https://github.com/rails/rails/commit/6629d51a2756fadf961bb09df20579cacfef2c8e * Renames grep_pattern to grep throughout. * Fixes setup not calling super by calling setup with a block. * Converts test helper method to a private one, like we have it other places. * Uses keyword arguments to get around awkward draw({ grep: "x" }, Action…) construction.
* Introduce `ActionDispatch::Routing::ConsoleFormatter::Base`bogdanvlviv2018-03-131-11/+11
| | | | | | | | | | | | | | - Create `Base` and inherit `Sheet` and `Expanded` in order to - prevent code duplication. - Remove trailing "\n" for components of `Expanded`. - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead. - Change `no_routes` message "No routes were found for this controller" since if use `-g`, it sounds incorrect. - Display `No routes were found for this controller.` if apply `-c`. - Display `No routes were found for this grep pattern.` if apply `-g`. Related to #32130
* Merge pull request #32160 from bogdanvlviv/improve-rails-routes-expandedKasper Timm Hansen2018-03-111-5/+10
|\ | | | | Draw line of a route name to the end of row console on `rails routes --expanded`
| * Draw line of a route name to the end of row console on `rails routes --expanded`bogdanvlviv2018-03-051-5/+10
| | | | | | | | | | | | | | In order to get width of console use `IO::console_size`, See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size Related to #32130
* | Always yield a CSP policy instanceAndrew White2018-03-081-12/+58
| | | | | | | | | | If the app has the CSP disabled globally allow a controller action to enable the policy for that request.
* | Add the ability to disable the global CSP in a controllerAndrew White2018-03-081-0/+14
|/ | | | | | | | e.g: class LegacyPagesController < ApplicationController content_security_policy false, only: :index end
* Add --expanded option to "rails routes"Benoit Tigeot2018-02-281-2/+66
| | | | | | | | | | | | | | | | | | | | | | | | | When using rails routes with small terminal or complicated routes it can be very difficult to understand where is the element listed in header. psql had the same issue, that's why they created "expanded mode" you can switch using `\x` or by starting psql with ``` -x --expanded Turn on the expanded table formatting mode. This is equivalent to the \x command. ``` The output is similar to one implemented here for rails routes: db_user-# \du List of roles -[ RECORD 1 ]---------------------------------------------- Role name | super Attributes | Superuser, Create role, Create DB Member of | {} -[ RECORD 2 ]---------------------------------------------- Role name | role Attributes | Superuser, Create role, Create DB, Replication Member of | {}
* Uses the absolute path for system test screenshotsZamith2018-02-271-5/+5
| | | | | | | | | | | | | Why: * When getting an error that generates a screenshot it would be helpful to be able to ctrl+click it to quickly open it in the browser, which does not work with relative paths This change addresses the need by: * Changing `image_path` to disregard the relative path and use the absolute one instead
* Merge branch 'master' into update_default_hsts_max_ageGuillermo Iguaran2018-02-2412-98/+136
|\
| * Add support for automatic nonce generation for Rails UJSAndrew White2018-02-191-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because the UJS library creates a script tag to process responses it normally requires the script-src attribute of the content security policy to include 'unsafe-inline'. To work around this we generate a per-request nonce value that is embedded in a meta tag in a similar fashion to how CSRF protection embeds its token in a meta tag. The UJS library can then read the nonce value and set it on the dynamically generated script tag to enable it to execute without needing 'unsafe-inline' enabled. Nonce generation isn't 100% safe - if your script tag is including user generated content in someway then it may be possible to exploit an XSS vulnerability which can take advantage of the nonce. It is however an improvement on a blanket permission for inline scripts. It is also possible to use the nonce within your own script tags by using `nonce: true` to set the nonce value on the tag, e.g <%= javascript_tag nonce: true do %> alert('Hello, World!'); <% end %> Fixes #31689.
| * Remove trailing semi-colon from CSPAndrew White2018-02-191-32/+32
| | | | | | | | | | | | | | | | | | Although the spec[1] is defined in such a way that a trailing semi-colon is valid it also doesn't allow a semi-colon by itself to indicate an empty policy. Therefore it's easier (and valid) just to omit it rather than to detect whether the policy is empty or not. [1]: https://www.w3.org/TR/CSP2/#policy-syntax
| * Revert "Merge pull request #32045 from eagletmt/skip-csp-header"Andrew White2018-02-191-20/+2
| | | | | | | | | | | | | | | | | | This reverts commit 86f7c269073a3a9e6ddec9b957deaa2716f2627d, reversing changes made to 5ece2e4a4459065b5efd976aebd209bbf0cab89b. If a policy is set then we should generate it even if it's empty. However what is happening is that we're accidentally generating an empty policy when the initializer is commented out by default.
| * Skip generating empty CSP header when no policy is configuredKohei Suzuki2018-02-181-2/+20
| | | | | | | | | | | | | | | | `Rails.application.config.content_security_policy` is configured with no policies by default. In this case, Content-Security-Policy header should not be generated instead of generating the header with no directives. Firefox also warns "Content Security Policy: Couldn't process unknown directive ''".
| * Fix array routing constraintsfatkodima2018-02-171-2/+5
| |
| * Make sure assert_recognizes can still find routes mounted after enginesRafael Mendonça França2018-02-091-0/+6
| | | | | | | | | | Before, if the application defined after an engine this method would not recognize the route since it was not defined insdie the engine.
| * Consistent behavior for session and cookies with to_h and to_hash methodIgor Kasyanchuk2018-01-312-0/+7
| |
| * Allow @ in X-Request-Id headerDaniel Colson2018-01-291-0/+5
| | | | | | | | | | | | | | It makes sense to be as strict as possible with headers from the outside world, but allowing @ to support Apache's mod_unique_id (see #31644) seems OK to me
| * Use assert_empty and assert_not_emptyDaniel Colson2018-01-252-3/+3
| |