From bc2b2214a88187e54d2cf019e6592ec86bbcc87f Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 9 Aug 2018 12:51:40 -0400 Subject: [PATCH] add test for ssh over network ssh key password preference --- awx/main/tests/unit/test_tasks.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index e3e538bb3f..2962197e9c 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -765,12 +765,12 @@ class TestJobCredentials(TestJobExecution): if expected_flag: assert expected_flag in ' '.join(args) - def test_net_password(self): + def test_net_ssh_key_unlock(self): net = CredentialType.defaults['net']() credential = Credential( pk=1, credential_type=net, - inputs = {'username': 'bob', 'ssh_key_unlock': 'secret'} + inputs = {'ssh_key_unlock': 'secret'} ) credential.inputs['ssh_key_unlock'] = encrypt_field(credential, 'ssh_key_unlock') self.instance.credentials.add(credential) @@ -781,6 +781,32 @@ class TestJobCredentials(TestJobExecution): assert 'secret' in call_kwargs.get('expect_passwords').values() + def test_prefer_ssh_over_net_ssh_key_unlock(self): + net = CredentialType.defaults['net']() + net_credential = Credential( + pk=1, + credential_type=net, + inputs = {'ssh_key_unlock': 'net_secret'} + ) + net_credential.inputs['ssh_key_unlock'] = encrypt_field(net_credential, 'ssh_key_unlock') + + ssh = CredentialType.defaults['ssh']() + ssh_credential = Credential( + pk=1, + credential_type=ssh, + inputs = {'ssh_key_unlock': 'ssh_secret'} + ) + ssh_credential.inputs['ssh_key_unlock'] = encrypt_field(ssh_credential, 'ssh_key_unlock') + + self.instance.credentials.add(net_credential) + self.instance.credentials.add(ssh_credential) + self.task.run(self.pk) + + assert self.run_pexpect.call_count == 1 + call_args, call_kwargs = self.run_pexpect.call_args_list[0] + + assert 'ssh_secret' in call_kwargs.get('expect_passwords').values() + def test_vault_password(self): vault = CredentialType.defaults['vault']() credential = Credential(