Skip to content

Commit

Permalink
Fix inconsistencies writing credentials values
Browse files Browse the repository at this point in the history
Using [] or the dynamic accessors don't result in the same value because
`[]` is delegated to `config` (the decrypted deserialized YAML), whereas
`[]=` and the dynamic accessors are delegated to `options`, an
ActiveSupport::OrderedOptions instance.
  • Loading branch information
etiennebarrie committed Jul 21, 2023
1 parent ea9b647 commit b6ce10b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/encrypted_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "active_support/encrypted_file"
require "active_support/ordered_options"
require "active_support/core_ext/object/inclusion"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/module/delegation"

module ActiveSupport
Expand Down Expand Up @@ -42,7 +43,6 @@ def message
end
end

delegate :[], :fetch, to: :config
delegate_missing_to :options

def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
Expand Down Expand Up @@ -84,7 +84,7 @@ def inspect # :nodoc:
def deep_transform(hash)
return hash unless hash.is_a?(Hash)

h = ActiveSupport::InheritableOptions.new
h = ActiveSupport::OrderedOptions.new
hash.each do |k, v|
h[k] = deep_transform(v)
end
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/encrypted_configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
assert_equal @credentials.config, {}
end

test "writing with element assignment and reading with element reference" do
@credentials[:foo] = 42
assert_equal 42, @credentials[:foo]
end

test "writing with dynamic accessor and reading with element reference" do
@credentials.foo = 42
assert_equal 42, @credentials[:foo]
end

test "change configuration by key file" do
@credentials.write({ something: { good: true } }.to_yaml)
@credentials.change do |config_file|
Expand Down

0 comments on commit b6ce10b

Please sign in to comment.