From ec3d47b1096d43084629d2ce37c3163dbcf0a8b0 Mon Sep 17 00:00:00 2001 From: "Robert A. Vincent II (Bob-Vee)" Date: Thu, 29 Jul 2021 11:16:37 -0400 Subject: [PATCH 1/2] Issue #179 Add tests for empty eyaml values --- features/edit.feature | 5 ++++- features/sandbox/test_new_values.yaml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/features/edit.feature b/features/edit.feature index 6e84c207..3b83a54a 100644 --- a/features/edit.feature +++ b/features/edit.feature @@ -66,6 +66,7 @@ Feature: eyaml editing When I run `eyaml edit non-existant-file.eyaml` When I run `eyaml decrypt -e non-existant-file.eyaml` Then the output should not match /#| This is eyaml edit mode/ + And the output should match /new_key0: DEC::PKCS7\[\]\!/ And the output should match /new_key1: DEC::PKCS7\[new value one\]\!/ And the output should match /new_key2: DEC::PKCS7\[new value two\]\!/ @@ -99,6 +100,7 @@ Feature: eyaml editing When I run `eyaml edit test_input.eyaml` When I run `eyaml decrypt -e test_input.eyaml` Then the output should match /encrypted_string: DEC::PKCS7\[planet of the apes\]\!/ + And the output should match /new_key0: DEC::PKCS7\[\]\!/ And the output should match /new_key1: DEC::PKCS7\[new value one\]\!/ And the output should match /new_key2: DEC::PKCS7\[new value two\]\!/ And the output should match /multi_encryption: DEC::PLAINTEXT\[jammy\]\! DEC::PKCS7\[dodger\]!/ @@ -146,7 +148,8 @@ Feature: eyaml editing When I run `bash -c 'cp test_edit.yaml test_edit.eyaml'` When I run `eyaml edit -d test_edit.eyaml` When I run `eyaml decrypt -e test_edit.eyaml` - Then the output should match /new_key1: DEC::PKCS7\[new value one\]\!/ + Then the output should match /new_key0: DEC::PKCS7\[\]\!/ + And the output should match /new_key1: DEC::PKCS7\[new value one\]\!/ And the output should match /new_key2: DEC::PKCS7\[new value two\]\!/ Scenario: no-decrypt mode should not modify existing values diff --git a/features/sandbox/test_new_values.yaml b/features/sandbox/test_new_values.yaml index 6508608d..ef4e2276 100644 --- a/features/sandbox/test_new_values.yaml +++ b/features/sandbox/test_new_values.yaml @@ -1,2 +1,3 @@ +new_key0: DEC::PKCS7[]! new_key1: DEC::PKCS7[new value one]! new_key2: DEC::PKCS7[new value two]! \ No newline at end of file From 4caf75384bfc30a93f5333c97f6af6e54637f2c0 Mon Sep 17 00:00:00 2001 From: "Robert A. Vincent II (Bob-Vee)" Date: Thu, 29 Jul 2021 11:56:16 -0400 Subject: [PATCH 2/2] Issue #179 Fix encryption/decryption of empty eyaml values --- lib/hiera/backend/eyaml/parser/encrypted_tokens.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb b/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb index 4d778e5a..78b704ab 100644 --- a/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb +++ b/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb @@ -108,7 +108,7 @@ def create_enc_token(match, type, enc_comma, cipher, indentation = '') class EncHieraTokenType < EncTokenType def initialize - @regex = %r{ENC\[(\w+,)?([a-zA-Z0-9+/ =\n]+?)\]} + @regex = %r{ENC\[(\w+,)?([a-zA-Z0-9+/ =\n]*?)\]} @string_token_type = EncStringTokenType.new end @@ -119,7 +119,7 @@ def create_token(string) class EncStringTokenType < EncTokenType def initialize - @regex = %r{ENC\[(\w+,)?([a-zA-Z0-9+/=]+?)\]} + @regex = %r{ENC\[(\w+,)?([a-zA-Z0-9+/=]*?)\]} end def create_token(string)