Fix EncryptedConfiguration not behaving like Hash

Previously, `EncryptedConfiguration` was [updated][1] to use
`InheritableOptions` so that keys could be called like methods. It was
later [updated again][2] to ensure that it behaved both like a `Hash` and
`OrderedOptions`. In this second change, the `InheritableOptions`
instance was accidentally nested with another `InheritableOptions`
instance.

This continued to mostly work as expected because `InheritableOptions`
will fall back to the inner `InheritableOptions` when the outer one
doesn't have a key. However, any methods that try to treat the outer
`InheritableOptions` like it should know about all of its keys will fail
(for example, `#keys`, `#to_h`, `#to_json`, etc.)

This commit fixes the issue by removing the extraneous outer
`InheritableOptions` instance.

[1]: a6a9fed1719a3cfe47eb1566ae4d6034374fd809
[2]: 80585daf2def5bf94854be69f81e24a16ce14c55
This commit is contained in:
Hartley McGuire 2023-06-21 23:21:29 -04:00
parent 7a033f58ab
commit 8355658a56
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
3 changed files with 7 additions and 1 deletions

@ -1,3 +1,8 @@
* Fix `EncryptedConfiguration` returning incorrect values for some `Hash`
methods
*Hartley McGuire*
* Don't show secrets for `MessageEncryptor#inspect`.
Before:

@ -92,7 +92,7 @@ def deep_transform(hash)
end
def options
@options ||= ActiveSupport::InheritableOptions.new(deep_transform(config))
@options ||= deep_transform(config)
end
def deserialize(content)

@ -45,6 +45,7 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
assert_not @credentials.something.bad
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
assert_equal "bar", @credentials.something.nested.foo
assert_equal [:something], @credentials.keys
assert_equal [:good, :bad, :nested], @credentials.something.keys
assert_equal ({ good: true, bad: false, nested: { foo: "bar" } }), @credentials.something
end