From 387d4ba73716a40d4f42814e45701d8679abc278 Mon Sep 17 00:00:00 2001 From: Takeru Hayasaka Date: Sat, 28 Dec 2024 20:55:19 +0000 Subject: [PATCH] T6013: fix code format --- smoketest/scripts/cli/test_service_ssh.py | 34 +++++++++++++++++------ src/conf_mode/service_ssh.py | 4 ++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/smoketest/scripts/cli/test_service_ssh.py b/smoketest/scripts/cli/test_service_ssh.py index f4330d3e61..db83f14c35 100755 --- a/smoketest/scripts/cli/test_service_ssh.py +++ b/smoketest/scripts/cli/test_service_ssh.py @@ -39,7 +39,8 @@ key_dsa = '/etc/ssh/ssh_host_dsa_key' key_ed25519 = '/etc/ssh/ssh_host_ed25519_key' trusted_user_ca_key = '/etc/ssh/trusted_user_ca_key' -authorized_principals = '/etc/ssh/authorized_principals' +authorized_principals_dir = '/etc/ssh/authorized_principals' + def get_config_value(key): tmp = read_file(SSHD_CONF) @@ -381,13 +382,15 @@ def test_ssh_trusted_user_ca_key(self): trusted_user_ca_key_config = get_config_value('TrustedUserCAKeys') self.assertIn(trusted_user_ca_key, trusted_user_ca_key_config) authorize_principals_file_config = get_config_value('AuthorizedPrincipalsFile') - self.assertIn("none", authorize_principals_file_config) + self.assertIn('none', authorize_principals_file_config) with open(trusted_user_ca_key, 'r') as file: ca_key_contents = file.read() self.assertIn(ca_root_cert_data, ca_key_contents) - self.cli_delete(base_path + ['trusted-user-ca-key', 'ca-certificate', ca_cert_name]) + self.cli_delete( + base_path + ['trusted-user-ca-key', 'ca-certificate', ca_cert_name] + ) self.cli_delete(['pki', 'ca', ca_cert_name]) self.cli_commit() @@ -395,7 +398,7 @@ def test_ssh_trusted_user_ca_key(self): trusted_user_ca_key_config = get_config_value('TrustedUserCAKeys') self.assertNotIn(trusted_user_ca_key, trusted_user_ca_key_config) authorize_principals_file_config = get_config_value('AuthorizedPrincipalsFile') - self.assertNotIn("none", authorize_principals_file_config) + self.assertNotIn('none', authorize_principals_file_config) def test_ssh_trusted_user_ca_key_and_bind_user_with_principal(self): ca_cert_name = 'test_ca' @@ -435,13 +438,19 @@ def test_ssh_trusted_user_ca_key_and_bind_user_with_principal(self): for principal in principals: self.cli_set( base_path - + ['trusted-user-ca-key', 'bind-user', bind_user, 'principal', principal] + + [ + 'trusted-user-ca-key', + 'bind-user', + bind_user, + 'principal', + principal, + ] ) self.cli_commit() trusted_user_ca_key_config = get_config_value('TrustedUserCAKeys') self.assertIn(trusted_user_ca_key, trusted_user_ca_key_config) - authorized_principals_file = f'{authorized_principals}/{bind_user}' + authorized_principals_file = f'{authorized_principals_dir}/{bind_user}' self.assertTrue(os.path.exists(authorized_principals_file)) with open(authorized_principals_file, 'r') as file: @@ -452,10 +461,18 @@ def test_ssh_trusted_user_ca_key_and_bind_user_with_principal(self): for principal in principals: self.cli_delete( base_path - + ['trusted-user-ca-key', 'bind-user', bind_user, 'principal', principal] + + [ + 'trusted-user-ca-key', + 'bind-user', + bind_user, + 'principal', + principal, + ] ) - self.cli_delete(base_path + ['trusted-user-ca-key', 'ca-certificate', ca_cert_name]) + self.cli_delete( + base_path + ['trusted-user-ca-key', 'ca-certificate', ca_cert_name] + ) self.cli_delete(['pki', 'ca', ca_cert_name]) self.cli_delete(['system', 'login', 'user', test_user]) self.cli_commit() @@ -463,5 +480,6 @@ def test_ssh_trusted_user_ca_key_and_bind_user_with_principal(self): # Verify the authorized principals file is removed self.assertFalse(os.path.exists(authorized_principals_file)) + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/src/conf_mode/service_ssh.py b/src/conf_mode/service_ssh.py index bb2b50d4fc..aa90594be7 100755 --- a/src/conf_mode/service_ssh.py +++ b/src/conf_mode/service_ssh.py @@ -62,6 +62,7 @@ def cleanup_authorized_principal_dir(valid_users: list[str]): if not os.listdir(authorized_principal): os.rmdir(authorized_principal) + def handle_trusted_user_ca_key(ssh: dict): if 'trusted_user_ca_key' not in ssh: if os.path.exists(trusted_user_ca_key): @@ -131,7 +132,8 @@ def get_config(config=None): ) login_users_base = ['system', 'login', 'user'] login_users = conf.get_config_dict( - login_users_base, key_mangling=('-', '_'), + login_users_base, + key_mangling=('-', '_'), no_tag_node_value_mangle=True, get_first_key=True, )