diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 13:19:32 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 13:19:32 -0500 |
commit | 347dc166324c108b4a9c25c5ab03222a2f42b1d0 (patch) | |
tree | a268301da79b96278bc99439812f8c2c034fd000 | |
parent | c285c6824dc186e00040b7283877fea917050275 (diff) | |
download | rails-347dc166324c108b4a9c25c5ab03222a2f42b1d0.tar.gz rails-347dc166324c108b4a9c25c5ab03222a2f42b1d0.tar.bz2 rails-347dc166324c108b4a9c25c5ab03222a2f42b1d0.zip |
VerifiedKeyWithExpiration no longer needed
Thanks to rails/rails#29854! This does mean that we now depend on rails/rails master.
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 13 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | app/controllers/active_storage/disk_controller.rb | 2 | ||||
-rw-r--r-- | app/models/active_storage/service/disk_service.rb | 3 | ||||
-rw-r--r-- | app/models/active_storage/verified_key_with_expiration.rb | 22 | ||||
-rw-r--r-- | test/controllers/disk_controller_test.rb | 4 | ||||
-rw-r--r-- | test/models/blob_test.rb | 3 | ||||
-rw-r--r-- | test/models/verified_key_with_expiration_test.rb | 20 |
9 files changed, 11 insertions, 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" diff --git a/Gemfile.lock b/Gemfile.lock index e18acab95b..4319b1e22d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/controllers/active_storage/disk_controller.rb b/app/controllers/active_storage/disk_controller.rb index 62380a3774..7269239216 100644 --- a/app/controllers/active_storage/disk_controller.rb +++ b/app/controllers/active_storage/disk_controller.rb @@ -24,7 +24,7 @@ class ActiveStorage::DiskController < ActionController::Base end def decode_verified_key - ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_key]) + ActiveStorage.verifier.verified(params[:encoded_key]) end def disposition_param diff --git a/app/models/active_storage/service/disk_service.rb b/app/models/active_storage/service/disk_service.rb index 905f41c138..c7c45e2146 100644 --- a/app/models/active_storage/service/disk_service.rb +++ b/app/models/active_storage/service/disk_service.rb @@ -2,7 +2,6 @@ require "fileutils" 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 @@ class ActiveStorage::Service::DiskService < ActiveStorage::Service 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) diff --git a/app/models/active_storage/verified_key_with_expiration.rb b/app/models/active_storage/verified_key_with_expiration.rb deleted file mode 100644 index 5cb07c6988..0000000000 --- a/app/models/active_storage/verified_key_with_expiration.rb +++ /dev/null @@ -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 diff --git a/test/controllers/disk_controller_test.rb b/test/controllers/disk_controller_test.rb index 3e3f70de7a..c427942c57 100644 --- a/test/controllers/disk_controller_test.rb +++ b/test/controllers/disk_controller_test.rb @@ -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 diff --git a/test/models/blob_test.rb b/test/models/blob_test.rb index ded11e5dbe..45c8b7168f 100644 --- a/test/models/blob_test.rb +++ b/test/models/blob_test.rb @@ -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 diff --git a/test/models/verified_key_with_expiration_test.rb b/test/models/verified_key_with_expiration_test.rb deleted file mode 100644 index dd69e7cb10..0000000000 --- a/test/models/verified_key_with_expiration_test.rb +++ /dev/null @@ -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 |