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

accounts_ssh_authorized_keys_line_parser: Output regex matches when sshkey format isnt correct #484

Merged
merged 1 commit into from
May 7, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
Loading