diff --git a/aurweb/util.py b/aurweb/util.py index 0a39cd3d7b825e11252dc18fdc3a3b07fb35abe6..7b997609d447f73c332b55e8170e1147c627ebd9 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -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]: diff --git a/po/aurweb.pot b/po/aurweb.pot index 1838fae5dacf17492c68830d0c61b1ded9382403..ff1bde8b28bc6e8edb24ad147392caf56cdbffb1 100644 --- a/po/aurweb.pot +++ b/po/aurweb.pot @@ -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 "" diff --git a/templates/partials/account_form.html b/templates/partials/account_form.html index 007fb3895863de201a2414b433f3345117dcc9d3..a433a57d790f962ef9b9115f9fd4b9760cca52b6 100644 --- a/templates/partials/account_form.html +++ b/templates/partials/account_form.html @@ -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> diff --git a/test/test_util.py b/test/test_util.py index 2e8b2e4efeb7c64c5cda3710a7b208aca62020da..fd7d8655ec09b624e92239e5982ef7d16385579f 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -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]