Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/diffcrypt/encryptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def encrypt_values(data, original_data = nil)
key_changed ? encrypt_string(value) : original_encrypted_value
end
end
data
data.sort.to_h
end
# rubocop:enable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity

Expand Down
6 changes: 3 additions & 3 deletions test/diffcrypt/encryptor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_it_encrypts_nested_structures
aws:
access_key_id: AKIAXXX
CONTENT
expected_pattern = /---\nsecret_key_base: #{ENCRYPTED_VALUE_PATTERN}\naws:\n access_key_id: #{ENCRYPTED_VALUE_PATTERN}\n/
expected_pattern = /---\naws:\n access_key_id: #{ENCRYPTED_VALUE_PATTERN}\nsecret_key_base: #{ENCRYPTED_VALUE_PATTERN}\n/

assert_match expected_pattern, Diffcrypt::Encryptor.new(TEST_KEY_128, cipher: 'aes-128-gcm').encrypt_data(content).to_yaml
end
Expand All @@ -77,15 +77,15 @@ def test_it_encrypts_nested_structures
def test_it_only_updates_changed_values
original_encrypted_content = "---\ndata:\n secret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\naws:\n secret_access_key: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\n"
updated_content = "---\nsecret_key_base_1: secret_key_base_test\naws:\n secret_access_key: secret_access_key_2"
expected_pattern = /---\nsecret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\naws:\n secret_access_key: #{ENCRYPTED_VALUE_PATTERN}\n/
expected_pattern = /---\naws:\n secret_access_key: #{ENCRYPTED_VALUE_PATTERN}\nsecret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\n/

assert_match expected_pattern, Diffcrypt::Encryptor.new(TEST_KEY_128, cipher: 'aes-128-gcm').encrypt_data(updated_content, original_encrypted_content).to_yaml
end

def test_it_assumes_changed_when_no_original_value
original_encrypted_content = "---\ndata:\n secret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\n"
updated_content = "---\nsecret_key_base_1: secret_key_base_test\naws:\n access_key_id: new_value\n"
expected_pattern = /---\nsecret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\naws:\n access_key_id: #{ENCRYPTED_VALUE_PATTERN}\n/
expected_pattern = /---\naws:\n access_key_id: #{ENCRYPTED_VALUE_PATTERN}\nsecret_key_base_1: 88Ry6HESUoXBr6QUFXmni9zzfCIYt9qGNFvIWFcN--4xoecI5mqbNRBibI--62qPJbkzzh5h8lhFEFOSaQ==\n/

assert_match expected_pattern, Diffcrypt::Encryptor.new(TEST_KEY_128, cipher: 'aes-128-gcm').encrypt_data(updated_content, original_encrypted_content).to_yaml
end
Expand Down