From 4a46fc8d19643dc9f8c687e2b685dcde936cdab5 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Tue, 7 May 2024 09:44:37 +0200 Subject: [PATCH] accounts_ssh_authorized_keys_line_parser: Output regex matches when sshkey format isnt correct --- .../accounts_ssh_authorized_keys_line_parser.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/puppet/functions/accounts_ssh_authorized_keys_line_parser.rb b/lib/puppet/functions/accounts_ssh_authorized_keys_line_parser.rb index 77ca368a..15a8a172 100644 --- a/lib/puppet/functions/accounts_ssh_authorized_keys_line_parser.rb +++ b/lib/puppet/functions/accounts_ssh_authorized_keys_line_parser.rb @@ -17,7 +17,16 @@ def accounts_ssh_authorized_keys_line_parser_string(str) matched = str.match(%r{((sk-ssh-ed25519|sk-ecdsa-|ssh-|ecdsa-)[^\s]+)\s+([^\s]+)\s+(.*)$}) - raise ArgumentError, 'Wrong Keyline format!' unless matched && matched.length == 5 + + raise ArgumentError, "Wrong Keyline format! Got nil after applying regex to'#{str}'" unless matched + unless matched.length == 5 + output = [] + # first element is str, aftwerwards are all matching groups. We ignore the first element + (1..matched.length).each do |counter| + output << "element #{counter}: #{matched[counter]}" + end + raise ArgumentError, "Wrong Keyline format! Input: #{str}. Expected 4 elements after applying regex, got: #{output}" + end options = str[0, str.index(matched[0])].rstrip [options, matched[1], matched[3], matched[4]]