aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models
Commit message (Collapse)AuthorAgeFilesLines
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-212-2/+2
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Fix broken `ActiveStorage::BlobTest`yuuji.yaginuma2018-11-281-1/+1
| | | | `ActiveStorage::Filename#parameters` was removed by #33829.
* Prevent content type and disposition bypass in storage service URLsRosa Gutierrez2018-11-272-8/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Force content-type to binary on service urls for relevant content types We have a list of content types that must be forcibly served as binary, but in practice this only means to serve them as attachment always. We should also set the Content-Type to the configured binary type. As a bonus: add text/cache-manifest to the list of content types to be served as binary by default. * Store content-disposition and content-type in GCS Forcing these in the service_url when serving the file works fine for S3 and Azure, since these services include params in the signature. However, GCS specifically excludes response-content-disposition and response-content-type from the signature, which means an attacker can modify these and have files that should be served as text/plain attachments served as inline HTML for example. This makes our attempt to force specific files to be served as binary and as attachment can be easily bypassed. The only way this can be forced in GCS is by storing content-disposition and content-type in the object metadata. * Update GCS object metadata after identifying blob In some cases we create the blob and upload the data before identifying the content-type, which means we can't store that in GCS right when uploading. In these, after creating the attachment, we enqueue a job to identify the blob, and set the content-type. In other cases, files are uploaded to the storage service via direct upload link. We create the blob before the direct upload, which happens independently from the blob creation itself. We then mark the blob as identified, but we have already the content-type we need without having put it in the service. In these two cases, then, we need to update the metadata in the GCS service. * Include content-type and disposition in the verified key for disk service This prevents an attacker from modifying these params in the service signed URL, which is particularly important when we want to force them to have specific values for security reasons. * Allow only a list of specific content types to be served inline This is different from the content types that must be served as binary in the sense that any content type not in this list will be always served as attachment but with its original content type. Only types in this list are allowed to be served either inline or as attachment. Apart from forcing this in the service URL, for GCS we need to store the disposition in the metadata. Fix CVE-2018-16477.
* Merge pull request #33829 from mtsmfm/encode-filenameKasper Timm Hansen2018-09-232-33/+1
|\ | | | | Encode Content-Disposition filenames on send_data and send_file
| * Encode Content-Disposition filenames on send_data and send_fileFumiaki MATSUSHIMA2018-09-132-33/+1
| |
* | Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purgeJasper Martin2018-07-263-2/+93
| | | Do nothing instead of raising an error when it’s called on an attached blob.
* Test that ActiveStorage::Blob#purge fails when attachments existGeorge Claghorn2018-07-201-0/+8
|
* Add a foreign-key constraint to the attachments table for blobsGeorge Claghorn2018-07-192-2/+2
|
* Remove unnecessary tapGeorge Claghorn2018-07-171-10/+8
|
* Fix replacing many attachments via assign and attachGeorge Claghorn2018-07-171-0/+36
|
* Correct test nameGeorge Claghorn2018-07-161-1/+1
|
* Fix that successive ActiveStorage::Attached::Many#attach calls would ↵George Claghorn2018-07-161-26/+11
| | | | overwrite previous attachments
* Test removing attachments via #attachGeorge Claghorn2018-07-162-12/+59
|
* Clear attachment changes on reloadGeorge Claghorn2018-07-132-0/+16
|
* Implement ActiveStorage::Attached::{One,Many}#attach in terms of changesGeorge Claghorn2018-07-132-29/+153
|
* Fix that detaching could purgeGeorge Claghorn2018-07-132-0/+32
|
* Fix analyzing new blobs from uploaded files on attachGeorge Claghorn2018-07-132-0/+116
|
* Raise an ArgumentError instead of a RuntimeErrorGeorge Claghorn2018-07-082-2/+2
|
* Store newly-uploaded files on save rather than assignmentGeorge Claghorn2018-07-076-531/+674
|
* Fix that models can clobber each others' attachment reflectionsGeorge Claghorn2018-07-071-14/+19
| | | | | | | | | | | | | | Consider the following model definitions: class User < ApplicationRecord has_one_attached :avatar end class Group < ApplicationRecord has_one_attached :avatar end If you attempt to reflect on the User model's avatar attachment via User.reflect_on_attachment, you could receive a reflection for the Group model's avatar attachment. Fix this by ensuring that each model class uses its own Hash object to track attachment reflections.
* Permit configuring the default service URL expiryGeorge Claghorn2018-06-211-3/+3
|
* Refactor activestorage/test/models/attached_test.rbbogdanvlviv2018-06-071-19/+21
| | | | | | | | | | | Don't include `ActiveJob::TestHelper` since there is no test that uses it. Ensure removing of overridden User's methods. Related to https://github.com/rails/rails/pull/33085#issuecomment-395548563 Module#remove_method is private in Ruby 2.4. Related to fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9
* Merge pull request #33018 from kddeisz/defined-attachmentsRafael França2018-06-011-0/+29
|\ | | | | ActiveStorage reflection
| * Move ActiveStorage reflection logic entirely into ActiveStorageKevin Deisz2018-05-311-2/+2
| |
| * Reflection for attachmentsKevin Deisz2018-05-301-0/+29
| | | | | | | | Add the ability to reflect on the attachments that have been defined using ActiveRecord::Reflection.
* | Remove errant debugger callGeorge Claghorn2018-05-301-1/+0
| |
* | Include blob ID in tempfile name for debugging convenienceGeorge Claghorn2018-05-301-5/+9
|/
* Verify integrity after chunked downloadGeorge Claghorn2018-05-281-1/+11
|
* Change video preview format from PNG to JPGJavan Makhmali2018-05-231-2/+2
|
* Disable variant options when false or nil presentJacob Smith2018-05-211-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In response to https://github.com/rails/rails/issues/32917 In the current implementation, ActiveStorage passes all options to the underlying processor, including when a key has a value of false. For example, passing: ``` avatar.variant(resize: "100x100", monochrome: false, flip: "-90") ``` will return a monochrome image (or an error, pending on ImageMagick configuration) because it passes `-monochrome false` to the command (but the command line does not allow disabling flags this way, as usually a user would omit the flag entirely to disable that feature). This fix only passes those keys forward to the underlying processor if the value responds to `present?`. In practice, this means that `false` or `nil` will be filtered out before going to the processor. One possible use case would be for a user to be able to apply different filters to an avatar. The code might look something like: ``` variant_options = { monochrome: params[:monochrome], resize: params[:resize] } avatar.variant(*variant_options) ``` Obviously some sanitization may be beneficial in a real-world scenario, but this type of configuration object could be used in many other places as well. - Add removing falsy values from varaints to changelog - The entirety of #image_processing_transformation inject block was wrapped in `list.tap` to guard against the default `nil` being returned if no conditional was called. - add test for explicitly true variant options
* Permit opening a blob in a custom tempdirGeorge Claghorn2018-05-171-0/+12
|
* Generate getter and setter methods in mixinJosh Susser2018-05-171-0/+54
| | | | | | | | | | | Generated attachment getter and setter methods are created within the model's `GeneratedAssociationMethods` module to allow overriding and composition using `super`. Includes tests for new functionality. Co-authored-by: Josh Susser <josh@hasmanythrough.com> Co-authored-by: Jamon Douglas <terrildouglas@gmail.com>
* Add ActiveStorage::Blob#openGeorge Claghorn2018-05-161-0/+9
| | | | [David Robertson & George Claghorn]
* Add option to ActiveStorage::Blob to set extract_content_type_from_ioRyan Davidson2018-05-081-0/+10
| | | | | | | This adds a boolean argument called identify to ActiveStorage::Blob methods #create_after_upload, #build_after_upload and #upload. It allows a user to bypass the automatic content_type inference from the io.
* Stream blobs from disk in 5 MB chunksGeorge Claghorn2018-04-291-3/+3
| | | | Match other services, which all use a 5 MB chunk size.
* Merge pull request #31956 from fatkodima/has_attached-presence-validationEileen M. Uchitelle2018-04-271-0/+30
|\ | | | | has_(one/many)_attached presence validation
| * has_(one/many)_attached presence validationfatkodima2018-02-111-0/+30
| |
* | Show ImageProcessing macros in a dedicated exampleJanko Marohnić2018-04-231-3/+13
| |
* | Rename ActiveStorage.processor to .variant_processorJanko Marohnić2018-04-221-4/+4
| |
* | Use ImageProcessing gem for ActiveStorage variantsJanko Marohnić2018-04-181-12/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ImageProcessing gem is a wrapper around MiniMagick and ruby-vips, and implements an interface for common image resizing and processing. This is the canonical image processing gem recommended in [Shrine], and that's where it developed from. The initial implementation was extracted from Refile, which also implements on-the-fly transformations. Some features that ImageProcessing gem adds on top of MiniMagick: * resizing macros - #resize_to_limit - #resize_to_fit - #resize_to_fill - #resize_and_pad * automatic orientation * automatic thumbnail sharpening * avoids the complex and inefficient MiniMagick::Image class * will use "magick" instead of "convert" on ImageMagick 7 However, the biggest feature of the ImageProcessing gem is that it has an alternative implementation that uses libvips. Libvips is an alternative to ImageMagick that can process images very rapidly (we've seen up 10x faster than ImageMagick). What's great is that the ImageProcessing gem provides the same interface for both implementations. The macros are named the same, and the libvips implementation does auto orientation and thumbnail sharpening as well; only the operations/options specific to ImageMagick/libvips differ. The integration provided by this PR should work for both implementations. The plan is to introduce the ImageProcessing backend in Rails 6.0 as the default backend and deprecate the MiniMagick backend, then in Rails 6.1 remove the MiniMagick backend.
* | Use a current model to provide the host for service urlsAndrew White2018-04-061-1/+1
| | | | | | | | | | | | | | Trying to pass the current request down to the service so that it can create full urls instead of paths makes the API messy so use a model based on ActiveSupport::CurrentAttributes to provide the current host to services that need it (primarily the disk service).
* | Flip the order of the after_create callbacksDwight Watson2018-03-271-3/+13
| | | | | | | | | | | | | | | | | | | | Addresses rails/rails#32247 Add test that checks identify and analyze work in correct order Break out direct upload test helper Review changes for direct-upload test helper
* | Allow selectively purging attached blobsNicholas Shirley2018-03-061-0/+28
| |
* | Fix purging dependent blobs when attachments aren't loadedGeorge Claghorn2018-03-051-2/+16
| |
* | Delete dependent attachments with recordGeorge Claghorn2018-03-051-0/+14
| | | | | | | | [Matt Jones & George Claghorn]
* | Generate root-relative paths in Active Storage disk service URL methodsGeorge Claghorn2018-03-052-2/+1
| | | | | | | | Fixes #32129.
* | Handle another case where a blob might be erroneously purgedGeorge Claghorn2018-03-041-0/+12
| |
* | Avoid purging attached blob when replacing it with itselfGeorge Claghorn2018-03-041-0/+12
| |
* | Support varying ICO filesGeorge Claghorn2018-02-241-0/+11
| | | | | | | | Closes #32096.