VerifiedKeyWithExpiration no longer needed

Thanks to rails/rails#29854! This does mean that we now depend on rails/rails master.
This commit is contained in:
David Heinemeier Hansson 2017-07-23 13:19:32 -05:00
parent c285c6824d
commit 347dc16632
9 changed files with 11 additions and 62 deletions

@ -4,10 +4,7 @@ git_source(:github) { |repo_path| "https://github.com/#{repo_path}.git" }
gemspec
gem "activesupport", github: "rails/rails"
gem "activerecord", github: "rails/rails"
gem "actionpack", github: "rails/rails"
gem "activejob", github: "rails/rails"
gem "rails", github: "rails/rails"
gem "rake"
gem "byebug"

@ -1,6 +1,6 @@
GIT
remote: https://github.com/rails/rails.git
revision: 5c16dd35a23f75038baf1527143ee44accf081ff
revision: 127b475dc251a06942fe0cd2de2e0545cf5ed69f
specs:
actioncable (5.2.0.alpha)
actionpack (= 5.2.0.alpha)
@ -126,7 +126,7 @@ GEM
multi_json (~> 1.10)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
mail (2.6.6)
mime-types (>= 1.16, < 4)
memoist (0.16.0)
method_source (0.8.2)
@ -135,7 +135,7 @@ GEM
mime-types-data (3.2016.0521)
mini_magick (4.8.0)
mini_portile2 (2.2.0)
minitest (5.10.2)
minitest (5.10.3)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
@ -199,20 +199,17 @@ PLATFORMS
ruby
DEPENDENCIES
actionpack!
activejob!
activerecord!
activestorage!
activesupport!
aws-sdk (~> 2)
bundler (~> 1.15)
byebug
google-cloud-storage (~> 1.3)
httparty
mini_magick
rails!
rake
rubocop
sqlite3
BUNDLED WITH
1.15.2
1.15.3

@ -87,7 +87,6 @@ Variation of image attachment:
- Read metadata via Marcel?
- Add Migrator to copy/move between services
- [Explore direct uploads to cloud](https://github.com/rails/activestorage/pull/19)
- Extract VerifiedKeyWithExpiration into Rails as a feature of MessageVerifier
## Roadmap

@ -24,7 +24,7 @@ def disk_service
end
def decode_verified_key
ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_key])
ActiveStorage.verifier.verified(params[:encoded_key])
end
def disposition_param

@ -2,7 +2,6 @@
require "pathname"
require "digest/md5"
require "active_support/core_ext/numeric/bytes"
require "active_storage/verified_key_with_expiration"
class ActiveStorage::Service::DiskService < ActiveStorage::Service
attr_reader :root
@ -54,7 +53,7 @@ def exist?(key)
def url(key, expires_in:, disposition:, filename:)
instrument :url, key do |payload|
verified_key_with_expiration = ActiveStorage::VerifiedKeyWithExpiration.encode(key, expires_in: expires_in)
verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in)
generated_url =
if defined?(Rails) && defined?(Rails.application)

@ -1,22 +0,0 @@
class ActiveStorage::VerifiedKeyWithExpiration
class << self
def encode(key, expires_in: nil)
ActiveStorage.verifier.generate([ key, expires_at(expires_in) ])
end
def decode(encoded_key)
key, expires_at = ActiveStorage.verifier.verified(encoded_key)
key if key && fresh?(expires_at)
end
private
def expires_at(expires_in)
expires_in ? Time.now.utc.advance(seconds: expires_in) : nil
end
def fresh?(expires_at)
expires_at.nil? || Time.now.utc < expires_at
end
end
end

@ -11,13 +11,13 @@ class ActiveStorage::DiskControllerTest < ActionController::TestCase
end
test "showing blob inline" do
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes) }
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage.verifier.generate(@blob.key, expires_in: 5.minutes) }
assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end
test "sending blob as attachment" do
get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@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), disposition: :attachment }
assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end

@ -1,6 +1,5 @@
require "test_helper"
require "database/setup"
require "active_storage/verified_key_with_expiration"
class ActiveStorage::BlobTest < ActiveSupport::TestCase
test "create after upload sets byte size and checksum" do
@ -36,6 +35,6 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
private
def expected_url_for(blob, disposition: :inline)
"/rails/active_storage/disk/#{ActiveStorage::VerifiedKeyWithExpiration.encode(blob.key, expires_in: 5.minutes)}/#{blob.filename}?disposition=#{disposition}"
"/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes)}/#{blob.filename}?disposition=#{disposition}"
end
end

@ -1,20 +0,0 @@
require "test_helper"
require "active_support/core_ext/securerandom"
require "active_storage/verified_key_with_expiration"
class ActiveStorage::VerifiedKeyWithExpirationTest < ActiveSupport::TestCase
FIXTURE_KEY = SecureRandom.base58(24)
test "without expiration" do
encoded_key = ActiveStorage::VerifiedKeyWithExpiration.encode(FIXTURE_KEY)
assert_equal FIXTURE_KEY, ActiveStorage::VerifiedKeyWithExpiration.decode(encoded_key)
end
test "with expiration" do
encoded_key = ActiveStorage::VerifiedKeyWithExpiration.encode(FIXTURE_KEY, expires_in: 1.minute)
assert_equal FIXTURE_KEY, ActiveStorage::VerifiedKeyWithExpiration.decode(encoded_key)
travel 2.minutes
assert_nil ActiveStorage::VerifiedKeyWithExpiration.decode(encoded_key)
end
end