aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorCameron Bothner <cameronbothner@gmail.com>2018-08-18 14:03:52 -0400
committerCameron Bothner <cameronbothner@gmail.com>2018-08-21 15:35:58 -0400
commit22efb2ec49087827ca1cb28a8bad9f016800c591 (patch)
tree4b6ec860a38657b99d24d95a3a9f60fe7ef5943c /activestorage
parent5cd2d07bdcda4b2f547830d2becafe5e0722fa43 (diff)
downloadrails-22efb2ec49087827ca1cb28a8bad9f016800c591.tar.gz
rails-22efb2ec49087827ca1cb28a8bad9f016800c591.tar.bz2
rails-22efb2ec49087827ca1cb28a8bad9f016800c591.zip
Respond with 404 in ActiveStorage::DiskController#show when file missing
`ActiveStorage::DiskController#show` generates a 404 Not Found response when the requested file is missing from the disk service. It previously raised `Errno::ENOENT`.
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/CHANGELOG.md6
-rw-r--r--activestorage/app/controllers/active_storage/disk_controller.rb2
-rw-r--r--activestorage/test/controllers/disk_controller_test.rb8
3 files changed, 16 insertions, 0 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md
index 8e11146121..b592f79ca6 100644
--- a/activestorage/CHANGELOG.md
+++ b/activestorage/CHANGELOG.md
@@ -1,3 +1,9 @@
+* `ActiveStorage::DiskController#show` generates a 404 Not Found response when
+ the requested file is missing from the disk service. It previously raised
+ `Errno::ENOENT`.
+
+ *Cameron Bothner*
+
* `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
`ActiveStorage::FileNotFoundError` when the corresponding file is missing
from the storage service. Services translate service-specific missing object
diff --git a/activestorage/app/controllers/active_storage/disk_controller.rb b/activestorage/app/controllers/active_storage/disk_controller.rb
index 75cc11d6ff..7bd641ab9a 100644
--- a/activestorage/app/controllers/active_storage/disk_controller.rb
+++ b/activestorage/app/controllers/active_storage/disk_controller.rb
@@ -13,6 +13,8 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
else
head :not_found
end
+ rescue Errno::ENOENT
+ head :not_found
end
def update
diff --git a/activestorage/test/controllers/disk_controller_test.rb b/activestorage/test/controllers/disk_controller_test.rb
index c053052f6f..4bc61d13f3 100644
--- a/activestorage/test/controllers/disk_controller_test.rb
+++ b/activestorage/test/controllers/disk_controller_test.rb
@@ -31,6 +31,14 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
assert_equal " worl", response.body
end
+ test "showing blob that does not exist" do
+ blob = create_blob
+ blob.delete
+
+ get blob.service_url
+ assert_response :not_found
+ end
+
test "directly uploading blob with integrity" do
data = "Something else entirely!"