Skip to content

Commit

Permalink
(voxpupuli#136) Support \t and \r in block tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
elyscape authored and TomPoulton committed Mar 4, 2015
1 parent bf6348d commit 8a119fa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions features/decrypts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: eyaml decrypting
When I run `eyaml decrypt -e test_input.yaml`
Then the output should match /encrypted_string: DEC::PKCS7\[planet of the apes\]\!/
And the output should match /encrypted_block: >\n\s+DEC::PKCS7\[gangs of new york\]\!/
And the output should match /encrypted_tabbed_block: >\n\s+DEC::PKCS7\[gangs of new york\]\!/
And the output should match /\- DEC::PKCS7\[apocalypse now\]\!/
And the output should match /\- DEC::PKCS7\[the count of monte cristo\]\!/
And the output should match /\- array4/
Expand Down
11 changes: 6 additions & 5 deletions features/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Feature: eyaml editing
Given my EDITOR is set to "/bin/cat"
When I run `bash -c 'cp test_input.yaml test_input.eyaml'`
When I run `eyaml edit test_input.eyaml`
Then the output should match /encrypted_string: DEC\(1\)::PKCS7\[planet of the apes\]\!/
And the output should match /encrypted_default_encryption_string: DEC\(3\)::PKCS7\[planet of the apes\]\!/
And the output should match /encrypted_block: >\n\s+DEC\(5\)::PKCS7\[gangs of new york\]\!/
And the output should match /encrypted_default_encryption_block: >\n\s+DEC\(7\)::PKCS7\[gangs of new york\]\!/
Then the output should match /encrypted_string: DEC\(\d+\)::PKCS7\[planet of the apes\]\!/
And the output should match /encrypted_default_encryption_string: DEC\(\d+\)::PKCS7\[planet of the apes\]\!/
And the output should match /encrypted_block: >\n\s+DEC\(\d+\)::PKCS7\[gangs of new york\]\!/
And the output should match /encrypted_tabbed_block: >\n\s+DEC\(\d+\)::PKCS7\[gangs of new york\]\!/
And the output should match /encrypted_default_encryption_block: >\n\s+DEC\(\d\)::PKCS7\[gangs of new york\]\!/
And the output should match /\- DEC\(\d+\)::PKCS7\[apocalypse now\]\!/
And the output should match /\- DEC\(\d+\)::PKCS7\[the count of monte cristo\]\!/
And the output should match /\- array4/
Expand All @@ -27,7 +28,7 @@ Feature: eyaml editing
And the output should match /\- >\n\s+i wondered lonely\s*\n\s+as a cloud/
And the output should match /\s+key5: DEC\(\d+\)::PKCS7\[value5\]\!/
And the output should match /\s+key6: DEC\(\d+\)::PKCS7\[value6\]\!/
And the output should match /multi_encryption: DEC\(29\)::PLAINTEXT\[jammy\]\! DEC\(\d+\)::PKCS7\[dodger\]!/
And the output should match /multi_encryption: DEC\(\d+\)::PLAINTEXT\[jammy\]\! DEC\(\d+\)::PKCS7\[dodger\]!/

Scenario: decrypting a eyaml file should add a preamble
Given my EDITOR is set to "/bin/cat"
Expand Down
4 changes: 2 additions & 2 deletions features/parser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Parser
And I configure the keypair
And I load a file called test_input.yaml
When I parse the content
Then I should have 33 tokens
Then I should have 35 tokens
Then token 1 should be a NonMatchToken
Then token 2 should be a EncToken
Then token 2 should start with "ENC[PKCS7,MIIBiQYJKoZIhvcNAQ"
Expand Down Expand Up @@ -47,4 +47,4 @@ Feature: Parser
When I parse the content
And map it to index decrypted values
Then decryption 1 should be "DEC(1)::PKCS7[planet of the apes]!"
Then decryption 11 should be "DEC(11)::PKCS7[the count of monte cristo]!"
Then decryption 13 should be "DEC(13)::PKCS7[the count of monte cristo]!"
2 changes: 1 addition & 1 deletion features/recrypt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Recrypt
And I configure the keypair
And I load a file called test_input.yaml
And I recrypt it twice
Then I should have 33 tokens
Then I should have 35 tokens
Then the recrypted tokens should match
Then the recrypted decrypted content should match
Then the recrypted contents should differ
Expand Down
11 changes: 11 additions & 0 deletions features/sandbox/test_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ encrypted_block: >
ebOxxDBMBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBCWeGlYS5cQoX78L6LK
/mczgCD/pI7usp1XPebnN8CngxHXuUjj5S+6IUpOW6l2JgUeWw==]
encrypted_tabbed_block: >
ENC[PKCS7,MIIBiQYJKoZIhvcNAQcDoIIBejCCAXYCAQAxggEhMIIBHQIBADAFMAACAQAw
DQYJKoZIhvcNAQEBBQAEggEAYzeWn3MBLhOs4hokxMCWcDd9VuwCylQRUQ0w
KwCObeORw8PJkCDvi5ZIA2YkrvYTT6u3/7KfAiHd0Rg1WLb9et0Mg/Fd3DFF
7qhqOGHoQt3+4eKzlcikeR0/Lqrq2vTpqZ2Sw1CZ7Dn+Z4ll95p7lp97rb2J
kYTVroLYGWEcsS3JZLL4/l3z0bJbXNKKqJ1aHCAFq+wmWXeb6cDvvyHFg2N/
vGPFEQjP7AbWhxHxXDbYIGcU073u5NtE40JXL8SH82iHxqRF8s9g6Dh5cmjg
AY2pkBD9e6N78NNx+PAJswsFAV4DOCbXdf2BisyYbM3na35MVfyb6ggDegrE
ebOxxDBMBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBCWeGlYS5cQoX78L6LK
/mczgCD/pI7usp1XPebnN8CngxHXuUjj5S+6IUpOW6l2JgUeWw==]
encrypted_default_encryption_block: >
ENC[MIIBiQYJKoZIhvcNAQcDoIIBejCCAXYCAQAxggEhMIIBHQIBADAFMAACAQAw
DQYJKoZIhvcNAQEBBQAEggEAYzeWn3MBLhOs4hokxMCWcDd9VuwCylQRUQ0w
Expand Down
10 changes: 5 additions & 5 deletions lib/hiera/backend/eyaml/parser/encrypted_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def to_encrypted(args={})
case format
when :block
# strip any white space
@cipher = @cipher.gsub(/ /m, "")
@cipher = @cipher.gsub(/[ \t]/, "")
# normalize indentation
ciphertext = @cipher.gsub(/\n/, "\n" + @indentation)
ciphertext = @cipher.gsub(/[\n\r]/, "\n" + @indentation)
chevron = (args[:use_chevron].nil? || args[:use_chevron]) ? ">\n" : ''
"#{label_string}#{chevron}" + @indentation + "ENC[#{@encryptor.tag},#{ciphertext}]"
when :string
ciphertext = @cipher.gsub(/\n/, "")
ciphertext = @cipher.gsub(/[\n\r]/, "")
"#{label_string}ENC[#{@encryptor.tag},#{ciphertext}]"
else
raise "#{@format} is not a valid format"
Expand Down Expand Up @@ -87,7 +87,7 @@ def initialize
@string_token_type = EncStringTokenType.new()
end
def create_token(string)
@string_token_type.create_token(string.gsub(/[ \n]/, ''))
@string_token_type.create_token(string.gsub(/\s/, ''))
end
end

Expand All @@ -103,7 +103,7 @@ def create_token(string)

class EncBlockTokenType < EncTokenType
def initialize
@regex = />\n(\s*)ENC\[(\w+,)?([a-zA-Z0-9\+\/ =\n]+?)\]/
@regex = />\n(\s*)ENC\[(\w+,)?([a-zA-Z0-9\+\/=\s]+?)\]/
end
def create_token(string)
md = @regex.match(string)
Expand Down

0 comments on commit 8a119fa

Please sign in to comment.