Verified Commit 48e5dc67 authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos
Browse files

feat: remove empty lines from ssh_keys text area, and show helpful message



Signed-off-by: Leonidas Spyropoulos's avatarLeonidas Spyropoulos <artafinde@archlinux.org>
parent 7e06823e
Pipeline #35915 passed with stages
in 2 minutes and 34 seconds
......@@ -192,7 +192,7 @@ def parse_ssh_key(string: str) -> Tuple[str, str]:
def parse_ssh_keys(string: str) -> list[Tuple[str, str]]:
"""Parse a list of SSH public keys."""
return [parse_ssh_key(e) for e in string.splitlines()]
return [parse_ssh_key(e) for e in string.strip().splitlines(True) if e.strip()]
def shell_exec(cmdline: str, cwd: str) -> Tuple[int, str, str]:
......
......@@ -1398,6 +1398,10 @@ msgid ""
"the Arch User Repository."
msgstr ""
#: templates/partials/account_form.html
msgid "Specify multiple SSH Keys separated by new line, empty lines are ignored."
msgstr ""
#: template/account_edit_form.php
msgid "SSH Public Key"
msgstr ""
......
......@@ -264,6 +264,13 @@
<textarea id="id_ssh" name="PK"
rows="5" cols="30">{{ ssh_pks | join("\n") }}</textarea>
</p>
<p>
<em>
{{
"Specify multiple SSH Keys separated by new line, empty lines are ignored." | tr
}}
</em>
</p>
</fieldset>
<fieldset>
......
......@@ -96,14 +96,37 @@ YbxDwGimZZslg0OZu9UzoAT6xEGyiZsqJkTMbRp1ZYIOv9jHCJxRuxxuN3fzxyT3xE69+vhq2/NJX\
vTNJCD6JtMClxbIXW9q74nNqG+2SD/VQNMUz/505TK1PbY/4uyFfq5HquHJXQVCBll03FRerNHH2N\
schFne6BFHpa48PCoZNH45wLjFXwUyrGU1HrNqh6ZPdRfBTrTOkgs+BKBxGNeV45aYUPu/cFBSPcB\
fRSo6OFcejKc="""
assert_multiple_keys(pks)
def test_parse_ssh_keys_with_extra_lines():
pks = """ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyN\
TYAAABBBEURnkiY6JoLyqDE8Li1XuAW+LHmkmLDMW/GL5wY7k4/A+Ta7bjA3MOKrF9j4EuUTvCuNX\
ULxvpfSqheTFWZc+g=
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDmqEapFMh/ajPHnm1dBweYPeLOUjC0Ydp6uw7rB\
S5KCggUVQR8WfIm+sRYTj2+smGsK6zHMBjFnbzvV11vnMqcnY+Sa4LhIAdwkbt/b8HlGaLj1hCWSh\
a5b5/noeK7L+CECGHdvfJhpxBbhq38YEdFnCGbslk/4NriNcUp/DO81CXb1RzJ9GBFH8ivPW1mbe9\
YbxDwGimZZslg0OZu9UzoAT6xEGyiZsqJkTMbRp1ZYIOv9jHCJxRuxxuN3fzxyT3xE69+vhq2/NJX\
8aRsxGPL9G/XKcaYGS6y6LW4quIBCz/XsTZfx1GmkQeZPYHH8FeE+XC/+toXL/kamxdOQKFYEEpWK\
vTNJCD6JtMClxbIXW9q74nNqG+2SD/VQNMUz/505TK1PbY/4uyFfq5HquHJXQVCBll03FRerNHH2N\
schFne6BFHpa48PCoZNH45wLjFXwUyrGU1HrNqh6ZPdRfBTrTOkgs+BKBxGNeV45aYUPu/cFBSPcB\
fRSo6OFcejKc=
"""
assert_multiple_keys(pks)
def assert_multiple_keys(pks):
keys = util.parse_ssh_keys(pks)
assert len(keys) == 2
pfx1, key1, pfx2, key2 = pks.split()
k1, k2 = keys
assert pfx1 == k1[0]
assert key1 == k1[1]
assert pfx2 == k2[0]
assert key2 == k2[1]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment