Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 179 Fix parsing of empty eyaml values #323

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion features/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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\]\!/

Expand Down Expand Up @@ -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\]!/
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions features/sandbox/test_new_values.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
new_key0: DEC::PKCS7[]!
new_key1: DEC::PKCS7[new value one]!
new_key2: DEC::PKCS7[new value two]!
4 changes: 2 additions & 2 deletions lib/hiera/backend/eyaml/parser/encrypted_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down