Skip to content

Commit

Permalink
T6013: fix code format
Browse files Browse the repository at this point in the history
  • Loading branch information
takehaya committed Dec 28, 2024
1 parent 4b14d9d commit 0d74b4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 24 additions & 6 deletions smoketest/scripts/cli/test_service_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
trusted_user_ca_key = '/etc/ssh/trusted_user_ca_key'
authorized_principals = '/etc/ssh/authorized_principals'


def get_config_value(key):
tmp = read_file(SSHD_CONF)
tmp = re.findall(f'\n?{key}\s+(.*)', tmp)
Expand Down Expand Up @@ -381,21 +382,23 @@ 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()

# Verify the CA key is removed
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'
Expand Down Expand Up @@ -435,7 +438,13 @@ 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()

Expand All @@ -452,16 +461,25 @@ 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()

# Verify the authorized principals file is removed
self.assertFalse(os.path.exists(authorized_principals_file))


if __name__ == '__main__':
unittest.main(verbosity=2)
4 changes: 3 additions & 1 deletion src/conf_mode/service_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 0d74b4e

Please sign in to comment.