From ca9ac310028d0009edf1fbf657541d2dea327535 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 22 Apr 2017 18:29:05 +0900 Subject: `respond_to_missing?` should be private Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private. --- activesupport/lib/active_support/duration.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 99080e34a1..d4424ed792 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -305,10 +305,6 @@ module ActiveSupport to_i end - def respond_to_missing?(method, include_private = false) #:nodoc: - @value.respond_to?(method, include_private) - end - # Build ISO 8601 Duration string for this duration. # The +precision+ parameter can be used to limit seconds' precision of duration. def iso8601(precision: nil) @@ -335,8 +331,12 @@ module ActiveSupport end end + def respond_to_missing?(method, _) + value.respond_to?(method) + end + def method_missing(method, *args, &block) - value.send(method, *args, &block) + value.public_send(method, *args, &block) end def raise_type_error(other) -- cgit v1.2.3 From 90f851a18b1aca6323c77d21153761e36f864079 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Tue, 25 Apr 2017 07:40:51 -0700 Subject: Remove checks for Enumerator#size method The Enumerator#size method was introduced in Ruby 2.0. These tests were added when Rails 4.1 was current, and Ruby 1.9.3 was still supported. Since Rails 5 only Ruby >= 2.2.2 is supported, so the checks are no longer necessary. --- activesupport/test/core_ext/enumerable_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 4f1ab993b8..0b345ecf0f 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -171,10 +171,8 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) }, payments.index_by(&:price)) assert_equal Enumerator, payments.index_by.class - if Enumerator.method_defined? :size - assert_nil payments.index_by.size - assert_equal 42, (1..42).index_by.size - end + assert_nil payments.index_by.size + assert_equal 42, (1..42).index_by.size assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) }, payments.index_by.each(&:price)) end -- cgit v1.2.3 From 001fc80d8784670277af3b9dd3d22f16cbf965f9 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Fri, 28 Apr 2017 10:18:55 -0700 Subject: Add missing require for `remove_possible_method` https://github.com/rails/rails/commit/505537082849d912e8e29819655b80a573e93c0c added a call to `remove_possible_method`, but didn't require the file that defines it. --- activesupport/lib/active_support/core_ext/date_time/compatibility.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb index eb8b8b2c65..870391aeaa 100644 --- a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb +++ b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb @@ -1,4 +1,5 @@ require "active_support/core_ext/date_and_time/compatibility" +require "active_support/core_ext/module/remove_method" class DateTime include DateAndTime::Compatibility -- cgit v1.2.3 From 4e6d84f5553421ad1d24d4d137d46c85d4e1881c Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 29 Apr 2017 23:30:38 +0900 Subject: Use `flat_map` rather than `map(&:...).flatten` --- activesupport/lib/active_support/i18n_railtie.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb index b749913ee9..f05c707ccd 100644 --- a/activesupport/lib/active_support/i18n_railtie.rb +++ b/activesupport/lib/active_support/i18n_railtie.rb @@ -42,7 +42,7 @@ module I18n case setting when :railties_load_path reloadable_paths = value - app.config.i18n.load_path.unshift(*value.map(&:existent).flatten) + app.config.i18n.load_path.unshift(*value.flat_map(&:existent)) when :load_path I18n.load_path += value else @@ -58,7 +58,7 @@ module I18n directories = watched_dirs_with_extensions(reloadable_paths) reloader = app.config.file_watcher.new(I18n.load_path.dup, directories) do I18n.load_path.keep_if { |p| File.exist?(p) } - I18n.load_path |= reloadable_paths.map(&:existent).flatten + I18n.load_path |= reloadable_paths.flat_map(&:existent) I18n.reload! end -- cgit v1.2.3 From 89389428b5d04e14f09009ac9af593d7c3da709f Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 30 Apr 2017 02:41:44 +0900 Subject: Cleanup CHANGELOGs [ci skip] * Remove trailing spaces. * Add backticks around method and command. * Fix indentation. --- activesupport/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index a4fc1e34eb..3ce4a0bbab 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -18,4 +18,5 @@ *Josh Pencheon* + Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activesupport/CHANGELOG.md) for previous changes. -- cgit v1.2.3 From aa913280584ba63bfc461d0009abd6c32525da9c Mon Sep 17 00:00:00 2001 From: "T.J. Schuck" Date: Thu, 4 May 2017 15:43:19 -0400 Subject: Assorted delegate_missing_to doc fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix rdoc code formatting — `tt`, not backticks * Fix/simplify sentence grammar — should at least just be “and the like”, not “likes”, but this is just general tightening up. * Add note that delegated methods must be public. Tested here: https://github.com/rails/rails/blob/7ff5ccae94ce2aff76b5f8a31a28e305a047d642/activesupport/test/core_ext/module_test.rb#L359-L365 * Simplify example code for delegate_missing_to. The example had complexity that wasn’t necessary for demonstrating `delegate_missing_to`. This gets rid of a bunch of cruft so the example is more obvious about what’s going on regarding the feature itself. [ci skip] --- .../active_support/core_ext/module/delegation.rb | 39 ++++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 85ab739095..13f3894e6c 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -219,48 +219,43 @@ class Module # When building decorators, a common pattern may emerge: # # class Partition - # def initialize(first_event) - # @events = [ first_event ] + # def initialize(event) + # @event = event # end # - # def people - # if @events.first.detail.people.any? - # @events.collect { |e| Array(e.detail.people) }.flatten.uniq - # else - # @events.collect(&:creator).uniq - # end + # def person + # @event.detail.person || @event.creator # end # # private # def respond_to_missing?(name, include_private = false) - # @events.respond_to?(name, include_private) + # @event.respond_to?(name, include_private) # end # # def method_missing(method, *args, &block) - # @events.send(method, *args, &block) + # @event.send(method, *args, &block) # end # end # - # With `Module#delegate_missing_to`, the above is condensed to: + # With Module#delegate_missing_to, the above is condensed to: # # class Partition - # delegate_missing_to :@events + # delegate_missing_to :@event # - # def initialize(first_event) - # @events = [ first_event ] + # def initialize(event) + # @event = event # end # - # def people - # if @events.first.detail.people.any? - # @events.collect { |e| Array(e.detail.people) }.flatten.uniq - # else - # @events.collect(&:creator).uniq - # end + # def person + # @event.detail.person || @event.creator # end # end # - # The target can be anything callable within the object. E.g. instance - # variables, methods, constants and the likes. + # The target can be anything callable within the object, e.g. instance + # variables, methods, constants, etc. + # + # The delegated method must be public on the target, otherwise it will + # raise +NoMethodError+. def delegate_missing_to(target) target = target.to_s target = "self.#{target}" if DELEGATION_RESERVED_METHOD_NAMES.include?(target) -- cgit v1.2.3 From 170085592604ac9f05e7033bc3000af6683ad494 Mon Sep 17 00:00:00 2001 From: "T.J. Schuck" Date: Thu, 4 May 2017 16:04:32 -0400 Subject: Update test names to match method name The method is named `delegate_missing_to`, not `delegate_to_missing` --- activesupport/test/core_ext/module_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 085fd6592d..a4d4444d69 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -348,15 +348,15 @@ class ModuleTest < ActiveSupport::TestCase assert has_block.hello? end - def test_delegate_to_missing_with_method + def test_delegate_missing_to_with_method assert_equal "David", DecoratedTester.new(@david).name end - def test_delegate_to_missing_with_reserved_methods + def test_delegate_missing_to_with_reserved_methods assert_equal "David", DecoratedReserved.new(@david).name end - def test_delegate_to_missing_does_not_delegate_to_private_methods + def test_delegate_missing_to_does_not_delegate_to_private_methods e = assert_raises(NoMethodError) do DecoratedReserved.new(@david).private_name end @@ -364,7 +364,7 @@ class ModuleTest < ActiveSupport::TestCase assert_match(/undefined method `private_name' for/, e.message) end - def test_delegate_to_missing_does_not_delegate_to_fake_methods + def test_delegate_missing_to_does_not_delegate_to_fake_methods e = assert_raises(NoMethodError) do DecoratedReserved.new(@david).my_fake_method end @@ -372,7 +372,7 @@ class ModuleTest < ActiveSupport::TestCase assert_match(/undefined method `my_fake_method' for/, e.message) end - def test_delegate_to_missing_affects_respond_to + def test_delegate_missing_to_affects_respond_to assert DecoratedTester.new(@david).respond_to?(:name) assert_not DecoratedTester.new(@david).respond_to?(:private_name) assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method) @@ -382,7 +382,7 @@ class ModuleTest < ActiveSupport::TestCase assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method, true) end - def test_delegate_to_missing_respects_superclass_missing + def test_delegate_missing_to_respects_superclass_missing assert_equal 42, DecoratedTester.new(@david).extra_missing assert_respond_to DecoratedTester.new(@david), :extra_missing -- cgit v1.2.3 From b201474756a2ee493406ad0cb49f49c6873bdc28 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 7 May 2017 04:08:58 +0900 Subject: Should escape meta characters in regexp --- activesupport/test/testing/file_fixtures_test.rb | 4 ++-- activesupport/test/time_travel_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/testing/file_fixtures_test.rb b/activesupport/test/testing/file_fixtures_test.rb index e44fe58ce9..faa81b5e75 100644 --- a/activesupport/test/testing/file_fixtures_test.rb +++ b/activesupport/test/testing/file_fixtures_test.rb @@ -8,7 +8,7 @@ class FileFixturesTest < ActiveSupport::TestCase test "#file_fixture returns Pathname to file fixture" do path = file_fixture("sample.txt") assert_kind_of Pathname, path - assert_match %r{.*/test/file_fixtures/sample.txt$}, path.to_s + assert_match %r{.*/test/file_fixtures/sample\.txt$}, path.to_s end test "raises an exception when the fixture file does not exist" do @@ -25,6 +25,6 @@ class FileFixturesPathnameDirectoryTest < ActiveSupport::TestCase test "#file_fixture_path returns Pathname to file fixture" do path = file_fixture("sample.txt") assert_kind_of Pathname, path - assert_match %r{.*/test/file_fixtures/sample.txt$}, path.to_s + assert_match %r{.*/test/file_fixtures/sample\.txt$}, path.to_s end end diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb index e0d3fb0cf5..9d354f14f4 100644 --- a/activesupport/test/time_travel_test.rb +++ b/activesupport/test/time_travel_test.rb @@ -99,7 +99,7 @@ class TimeTravelTest < ActiveSupport::TestCase #noop end end - assert_match(/Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing./, e.message) + assert_match(/Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing\./, e.message) end end end -- cgit v1.2.3 From 4fc2ea11811c50fb1f7c5baba6d4c20532a5a00c Mon Sep 17 00:00:00 2001 From: Peter McCracken Date: Wed, 10 May 2017 13:30:41 -0400 Subject: handle loops in the cause chain in Rescuable#rescue_with_handler --- activesupport/lib/active_support/rescuable.rb | 10 ++++++-- activesupport/test/rescuable_test.rb | 34 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index ee6592fb5a..12ec8bf1b8 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -84,12 +84,18 @@ module ActiveSupport # end # # Returns the exception if it was handled and +nil+ if it was not. - def rescue_with_handler(exception, object: self) + def rescue_with_handler(exception, object: self, visited_exceptions: []) + visited_exceptions << exception + if handler = handler_for_rescue(exception, object: object) handler.call exception exception elsif exception - rescue_with_handler(exception.cause, object: object) + if visited_exceptions.include?(exception.cause) + nil + else + rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions) + end end end diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index f7eb047d44..3bdd1651e7 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -43,7 +43,9 @@ class Stargate def dispatch(method) send(method) rescue Exception => e - rescue_with_handler(e) + unless rescue_with_handler(e) + @result = "unhandled" + end end def attack @@ -58,6 +60,26 @@ class Stargate raise MadRonon.new("dex") end + def crash + raise "unhandled RuntimeError" + end + + def looped_crash + ex1 = StandardError.new("error 1") + ex2 = StandardError.new("error 2") + begin + begin + raise ex1 + rescue + # sets the cause on ex2 to be ex1 + raise ex2 + end + rescue + # sets the cause on ex1 to be ex2 + raise ex1 + end + end + def fall_back_to_cause # This exception is the cause and has a handler. ronanize @@ -139,4 +161,14 @@ class RescuableTest < ActiveSupport::TestCase @stargate.dispatch :fall_back_to_cause assert_equal "dex", @stargate.result end + + def test_unhandled_exceptions + @stargate.dispatch(:crash) + assert_equal "unhandled", @stargate.result + end + + def test_rescue_handles_loops_in_exception_cause_chain + @stargate.dispatch :looped_crash + assert_equal "unhandled", @stargate.result + end end -- cgit v1.2.3 From db9ae5f1e1449b09c08d55a8a3a21ff61d904bd3 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Sun, 14 May 2017 23:24:37 +0100 Subject: Don't cache locally if unless_exist was passed Some cache backends support the `unless_exist` option, which tells them not to overwrite an existing entry. The local cache currently always stores the new value, even though the backend may have rejected it. Since we can't tell which value will end up in the backend cache, we should delete the key from the local cache, so that the next read for that key will go to the backend and pick up the correct value. --- activesupport/lib/active_support/cache/strategy/local_cache.rb | 7 ++++++- activesupport/test/caching_test.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 672eb2bb80..91875a56f5 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -115,7 +115,12 @@ module ActiveSupport end def write_entry(key, entry, options) - local_cache.write_entry(key, entry, options) if local_cache + if options[:unless_exist] + local_cache.delete_entry(key, options) if local_cache + else + local_cache.write_entry(key, entry, options) if local_cache + end + super end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index c67ffe69b8..dbec684ce0 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -708,6 +708,14 @@ module LocalCacheBehavior end end + def test_local_cache_of_write_with_unless_exist + @cache.with_local_cache do + @cache.write("foo", "bar") + @cache.write("foo", "baz", unless_exist: true) + assert_equal @peek.read("foo"), @cache.read("foo") + end + end + def test_local_cache_of_delete @cache.with_local_cache do @cache.write("foo", "bar") -- cgit v1.2.3 From 71fb6def5f07233e4fdf628e02981e4add5c6b8b Mon Sep 17 00:00:00 2001 From: Michael Coyne Date: Mon, 15 May 2017 08:45:14 +0000 Subject: Fix for AEAD auth_tag check in MessageEncryptor When MessageEncryptor tries to +decrypt_and_verify+ ciphertexts generated in a different mode (such CBC-HMAC), the +auth_tag+ may be +nil+ and must explicitly check for it. See the discussion here: https://github.com/rails/rails/pull/28132#discussion_r116388462 --- activesupport/lib/active_support/message_encryptor.rb | 2 +- activesupport/test/message_encryptor_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 0671469788..9589dba3ca 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -110,7 +110,7 @@ module ActiveSupport # Currently the OpenSSL bindings do not raise an error if auth_tag is # truncated, which would allow an attacker to easily forge it. See # https://github.com/ruby/openssl/issues/63 - raise InvalidMessage if aead_mode? && auth_tag.bytes.length != 16 + raise InvalidMessage if aead_mode? && (auth_tag.nil? || auth_tag.bytes.length != 16) cipher.decrypt cipher.key = @secret diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 56a436f751..c67ada5f20 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -86,6 +86,14 @@ class MessageEncryptorTest < ActiveSupport::TestCase assert_equal @data, encryptor.decrypt_and_verify(message) end + def test_aead_mode_with_hmac_cbc_cipher_text + encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") + + assert_raise ActiveSupport::MessageEncryptor::InvalidMessage do + encryptor.decrypt_and_verify "eHdGeExnZEwvMSt3U3dKaFl1WFo0TjVvYzA0eGpjbm5WSkt5MXlsNzhpZ0ZnbWhBWFlQZTRwaXE1bVJCS2oxMDZhYVp2dVN3V0lNZUlWQ3c2eVhQbnhnVjFmeVVubmhRKzF3WnZyWHVNMDg9LS1HSisyakJVSFlPb05ISzRMaXRzcFdBPT0=--831a1d54a3cda8a0658dc668a03dedcbce13b5ca" + end + end + def test_messing_with_aead_values_causes_failures encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") text, iv, auth_tag = encryptor.encrypt_and_sign(@data).split("--") -- cgit v1.2.3 From 51b090549b76684692bbb8a5c7fbdb3bdaa25642 Mon Sep 17 00:00:00 2001 From: Michael Coyne Date: Mon, 15 May 2017 08:55:46 +0000 Subject: Updates to MessageEncryptor AEAD tests --- activesupport/test/message_encryptor_test.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index c67ada5f20..4c3515b5e1 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -89,25 +89,29 @@ class MessageEncryptorTest < ActiveSupport::TestCase def test_aead_mode_with_hmac_cbc_cipher_text encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") - assert_raise ActiveSupport::MessageEncryptor::InvalidMessage do - encryptor.decrypt_and_verify "eHdGeExnZEwvMSt3U3dKaFl1WFo0TjVvYzA0eGpjbm5WSkt5MXlsNzhpZ0ZnbWhBWFlQZTRwaXE1bVJCS2oxMDZhYVp2dVN3V0lNZUlWQ3c2eVhQbnhnVjFmeVVubmhRKzF3WnZyWHVNMDg9LS1HSisyakJVSFlPb05ISzRMaXRzcFdBPT0=--831a1d54a3cda8a0658dc668a03dedcbce13b5ca" - end + assert_aead_not_decrypted(encryptor, "eHdGeExnZEwvMSt3U3dKaFl1WFo0TjVvYzA0eGpjbm5WSkt5MXlsNzhpZ0ZnbWhBWFlQZTRwaXE1bVJCS2oxMDZhYVp2dVN3V0lNZUlWQ3c2eVhQbnhnVjFmeVVubmhRKzF3WnZyWHVNMDg9LS1HSisyakJVSFlPb05ISzRMaXRzcFdBPT0=--831a1d54a3cda8a0658dc668a03dedcbce13b5ca") end def test_messing_with_aead_values_causes_failures encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") text, iv, auth_tag = encryptor.encrypt_and_sign(@data).split("--") - assert_not_decrypted([iv, text, auth_tag] * "--") - assert_not_decrypted([munge(text), iv, auth_tag] * "--") - assert_not_decrypted([text, munge(iv), auth_tag] * "--") - assert_not_decrypted([text, iv, munge(auth_tag)] * "--") - assert_not_decrypted([munge(text), munge(iv), munge(auth_tag)] * "--") - assert_not_decrypted([text, iv] * "--") - assert_not_decrypted([text, iv, auth_tag[0..-2]] * "--") + assert_aead_not_decrypted(encryptor, [iv, text, auth_tag] * "--") + assert_aead_not_decrypted(encryptor, [munge(text), iv, auth_tag] * "--") + assert_aead_not_decrypted(encryptor, [text, munge(iv), auth_tag] * "--") + assert_aead_not_decrypted(encryptor, [text, iv, munge(auth_tag)] * "--") + assert_aead_not_decrypted(encryptor, [munge(text), munge(iv), munge(auth_tag)] * "--") + assert_aead_not_decrypted(encryptor, [text, iv] * "--") + assert_aead_not_decrypted(encryptor, [text, iv, auth_tag[0..-2]] * "--") end private + def assert_aead_not_decrypted(encryptor, value) + assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do + encryptor.decrypt_and_verify(value) + end + end + def assert_not_decrypted(value) assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do @encryptor.decrypt_and_verify(@verifier.generate(value)) -- cgit v1.2.3