mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Specify verification purposes
This commit is contained in:
parent
5889560427
commit
15efa6720f
6 changed files with 9 additions and 9 deletions
|
@ -24,7 +24,7 @@ class ActiveStorage::DiskController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode_verified_key
|
def decode_verified_key
|
||||||
ActiveStorage.verifier.verified(params[:encoded_key])
|
ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def disposition_param
|
def disposition_param
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ActiveStorage::Blob < ActiveRecord::Base
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def find_signed(id)
|
def find_signed(id)
|
||||||
find ActiveStorage.verifier.verify(id)
|
find ActiveStorage.verifier.verify(id, purpose: :blob_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_after_upload(io:, filename:, content_type: nil, metadata: nil)
|
def build_after_upload(io:, filename:, content_type: nil, metadata: nil)
|
||||||
|
@ -39,7 +39,7 @@ class ActiveStorage::Blob < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def signed_id
|
def signed_id
|
||||||
ActiveStorage.verifier.generate(id)
|
ActiveStorage.verifier.generate(id, purpose: :blob_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def key
|
def key
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ActiveStorage::Service::DiskService < ActiveStorage::Service
|
||||||
|
|
||||||
def url(key, expires_in:, disposition:, filename:)
|
def url(key, expires_in:, disposition:, filename:)
|
||||||
instrument :url, key do |payload|
|
instrument :url, key do |payload|
|
||||||
verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in)
|
verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in, purpose: :blob_key)
|
||||||
|
|
||||||
generated_url =
|
generated_url =
|
||||||
if defined?(Rails) && defined?(Rails.application)
|
if defined?(Rails) && defined?(Rails.application)
|
||||||
|
|
|
@ -6,11 +6,11 @@ class ActiveStorage::Variation
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def decode(key)
|
def decode(key)
|
||||||
new ActiveStorage.verifier.verify(key)
|
new ActiveStorage.verifier.verify(key, purpose: :variation)
|
||||||
end
|
end
|
||||||
|
|
||||||
def encode(transformations)
|
def encode(transformations)
|
||||||
ActiveStorage.verifier.generate(transformations)
|
ActiveStorage.verifier.generate(transformations, purpose: :variation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ class ActiveStorage::DiskControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "showing blob inline" do
|
test "showing blob inline" do
|
||||||
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage.verifier.generate(@blob.key, expires_in: 5.minutes) }
|
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage.verifier.generate(@blob.key, expires_in: 5.minutes, purpose: :blob_key) }
|
||||||
assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
|
assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
|
||||||
assert_equal "text/plain", @response.headers["Content-Type"]
|
assert_equal "text/plain", @response.headers["Content-Type"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "sending blob as attachment" do
|
test "sending blob as attachment" do
|
||||||
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage.verifier.generate(@blob.key, expires_in: 5.minutes), disposition: :attachment }
|
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage.verifier.generate(@blob.key, expires_in: 5.minutes, purpose: :blob_key), disposition: :attachment }
|
||||||
assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
|
assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
|
||||||
assert_equal "text/plain", @response.headers["Content-Type"]
|
assert_equal "text/plain", @response.headers["Content-Type"]
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,6 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
private
|
private
|
||||||
def expected_url_for(blob, disposition: :inline)
|
def expected_url_for(blob, disposition: :inline)
|
||||||
"/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes)}/#{blob.filename}?disposition=#{disposition}"
|
"/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)}/#{blob.filename}?disposition=#{disposition}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue