diff --git a/changelogs/fragments/T9251_vyos_user_sk_key_types.yml b/changelogs/fragments/T9251_vyos_user_sk_key_types.yml index d1736cf2..47806abb 100644 --- a/changelogs/fragments/T9251_vyos_user_sk_key_types.yml +++ b/changelogs/fragments/T9251_vyos_user_sk_key_types.yml @@ -1,3 +1,5 @@ --- bugfixes: - - vyos_user - Accept the OpenSSH security key types ``sk-ecdsa-sha2-nistp256@openssh.com`` and ``sk-ssh-ed25519@openssh.com`` for ``public_keys.type``, which VyOS accepts but the module rejected. + - >- + vyos_user - Accept OpenSSH security key types ``sk-ecdsa-sha2-nistp256@openssh.com`` and + ``sk-ssh-ed25519@openssh.com`` for ``public_keys.type``, which were previously rejected. diff --git a/tests/unit/modules/network/vyos/test_vyos_user.py b/tests/unit/modules/network/vyos/test_vyos_user.py index f17685b4..27ab1f38 100644 --- a/tests/unit/modules/network/vyos/test_vyos_user.py +++ b/tests/unit/modules/network/vyos/test_vyos_user.py @@ -1,337 +1,342 @@ # (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type from unittest.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_user from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args from .vyos_module import TestVyosModule, load_fixture class TestVyosUserModule(TestVyosModule): module = vyos_user def setUp(self): super(TestVyosUserModule, self).setUp() self.mock_get_config = patch( "ansible_collections.vyos.vyos.plugins.modules.vyos_user.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( "ansible_collections.vyos.vyos.plugins.modules.vyos_user.load_config", ) self.load_config = self.mock_load_config.start() def tearDown(self): super(TestVyosUserModule, self).tearDown() self.mock_get_config.stop() self.mock_load_config.stop() def load_fixtures(self, commands=None, filename=None): self.get_config.return_value = load_fixture("vyos_user_config.cfg") self.load_config.return_value = dict(diff=None, session="session") def test_vyos_user_password(self): set_module_args(dict(name="ansible", configured_password="test")) result = self.execute_module(changed=True) self.assertEqual( result["commands"], ["set system login user ansible authentication plaintext-password test"], ) def test_vyos_user_password_special_chars(self): set_module_args(dict(name="ansible", configured_password="test$123!@")) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "set system login user ansible authentication plaintext-password 'test$123!@'", ], ) def test_vyos_user_password_embedded_quote(self): set_module_args(dict(name="ansible", configured_password="pa'ss")) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "set system login user ansible authentication plaintext-password 'pa'\"'\"'ss'", ], ) def test_vyos_user_password_complex_special_chars(self): set_module_args(dict(name="ansible", configured_password="P@ss w0rd!$#'xy\\")) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "set system login user ansible authentication plaintext-password 'P@ss w0rd!$#'\"'\"'xy\\'", ], ) def test_vyos_user_delete(self): set_module_args(dict(name="ansible", state="absent")) result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["delete system login user ansible"]) def test_vyos_user_purge(self): set_module_args(dict(purge=True)) result = self.execute_module(changed=True) self.assertEqual( sorted(result["commands"]), sorted( [ "delete system login user ansible", "delete system login user admin", "delete system login user ssh", ], ), ) def test_vyos_user_update_password_changed(self): set_module_args( dict( name="test", configured_password="test", update_password="on_create", ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], ["set system login user test authentication plaintext-password test"], ) def test_vyos_user_update_password_on_create_ok(self): set_module_args( dict( name="ansible", configured_password="test", update_password="on_create", ), ) self.execute_module() def test_vyos_user_update_password_always(self): set_module_args( dict( name="ansible", configured_password="test", update_password="always", ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], ["set system login user ansible authentication plaintext-password test"], ) def test_vyos_user_set_ssh_key(self): set_module_args( dict( name="ansible", public_keys=[ dict( name="user@host", key="AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu", type="ssh-ed25519", ), ], ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "set system login user ansible authentication public-keys user@host key 'AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu'", "set system login user ansible authentication public-keys user@host type 'ssh-ed25519'", ], ) def test_vyos_user_set_security_keys(self): set_module_args( dict( name="ansible", public_keys=[ dict( name="ecdsa@host", key="AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTY", type="sk-ecdsa-sha2-nistp256@openssh.com", ), dict( name="ed25519@host", key="AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIFIR0jrMvBdmvTJNY5EDhOD", type="sk-ssh-ed25519@openssh.com", ), ], ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ - "set system login user ansible authentication public-keys ecdsa@host key 'AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTY'", - "set system login user ansible authentication public-keys ecdsa@host type 'sk-ecdsa-sha2-nistp256@openssh.com'", - "set system login user ansible authentication public-keys ed25519@host key 'AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIFIR0jrMvBdmvTJNY5EDhOD'", - "set system login user ansible authentication public-keys ed25519@host type 'sk-ssh-ed25519@openssh.com'", + "set system login user ansible authentication public-keys " + "ecdsa@host key 'AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTY'", + "set system login user ansible authentication public-keys ecdsa@host " + "type 'sk-ecdsa-sha2-nistp256@openssh.com'", + "set system login user ansible authentication public-keys ed25519@host " + "key 'AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIFIR0jrMvBdmvTJNY5EDhOD'", + "set system login user ansible authentication public-keys ed25519@host " + "type 'sk-ssh-ed25519@openssh.com'", ], ) def test_vyos_user_set_ssh_key_idempotent(self): set_module_args( dict( name="ssh", public_keys=[ dict( name="user@host", key="AAAAB3NzaC1yc2EAAAADAQABAAABAQD", type="ssh-rsa", ), ], ), ) self.load_fixtures() result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) def test_vyos_user_set_ssh_key_change(self): set_module_args( dict( name="ssh", public_keys=[ dict( name="user@host", key="AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu", type="ssh-ed25519", ), ], ), ) self.load_fixtures() result = self.execute_module( changed=True, commands=[ "set system login user ssh authentication public-keys user@host key 'AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu'", "set system login user ssh authentication public-keys user@host type 'ssh-ed25519'", ], ) def test_vyos_user_set_ssh_key_add_and_remove(self): set_module_args( dict( name="ssh", public_keys=[ dict( name="noone@nowhere", key="AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu", type="ssh-ed25519", ), ], ), ) self.load_fixtures() result = self.execute_module( changed=True, commands=[ "delete system login user ssh authentication public-keys user@host", "set system login user ssh authentication public-keys noone@nowhere key 'AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2uyuhu'", "set system login user ssh authentication public-keys noone@nowhere type 'ssh-ed25519'", ], ) def test_vyos_user_set_ssh_key_empty(self): # empty public_keys has no effect (for setting passwords, user names, etc.) set_module_args( dict( name="ssh", public_keys=[], ), ) self.load_fixtures() result = self.execute_module(changed=False) def test_vyos_user_set_encrypted_password(self): set_module_args( dict( name="ansible", encrypted_password="$6$rounds=656000$SALT$HASH", ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "set system login user ansible authentication encrypted-password '$6$rounds=656000$SALT$HASH'", ], ) def test_vyos_user_set_encrypted_password_idem(self): set_module_args( dict( name="ansible", encrypted_password="$6$ZfvSv6A50W6yNPYX$4HP5eg2sywcXYxTqhApQ7zvUvx0HsQHrI9xuJoFLy2gM/", ), ) result = self.execute_module(changed=False) def test_vyos_user_aggregate_with_public_keys(self): set_module_args( dict( aggregate=[ dict( name="user1", public_keys=[ dict( name="user1@host1", key="AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2u", type="ssh-ed25519", ), ], ), dict( name="user2", public_keys=[ dict( name="user2@host2", key="AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2u", type="ssh-ed25519", ), ], ), ], ), ) result = self.execute_module(changed=True) self.assertEqual( sorted(result["commands"]), sorted( [ "set system login user user1 authentication public-keys user1@host1 key 'AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2u'", "set system login user user1 authentication public-keys user1@host1 type 'ssh-ed25519'", "set system login user user2 authentication public-keys user2@host2 key 'AAAAC3NzaC1lZDI1NTE5AAAAIFIR0jrMvBdmvTJNY5EDhOD+eixvbOinhY1eBU2u'", "set system login user user2 authentication public-keys user2@host2 type 'ssh-ed25519'", ], ), )