Agent: Capture secrets if missing username in SSHCredentialCollector

This commit is contained in:
Mike Salvatore 2022-07-18 08:51:58 -04:00
parent d5a125d985
commit 9edfe6979b
2 changed files with 9 additions and 1 deletions

View File

@ -45,7 +45,7 @@ class SSHCredentialCollector(ICredentialCollector):
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
)
if identity is not None:
if any([identity, secret]):
ssh_credentials.append(Credentials(identity, secret))
return ssh_credentials

View File

@ -43,6 +43,12 @@ def test_ssh_info_result_parsing(monkeypatch, patch_telemetry_messenger):
"private_key": None,
},
{"name": "guest", "home_dir": "/", "public_key": None, "private_key": None},
{
"name": "",
"home_dir": "/home/mcus",
"public_key": "PubKey",
"private_key": "PrivKey",
},
]
patch_ssh_handler(ssh_creds, monkeypatch)
@ -53,11 +59,13 @@ def test_ssh_info_result_parsing(monkeypatch, patch_telemetry_messenger):
ssh_keypair1 = SSHKeypair("ExtremelyGoodPrivateKey", "SomePublicKeyUbuntu")
ssh_keypair2 = SSHKeypair("", "AnotherPublicKey")
ssh_keypair3 = SSHKeypair("PrivKey", "PubKey")
expected = [
Credentials(identity=username, secret=ssh_keypair1),
Credentials(identity=username2, secret=ssh_keypair2),
Credentials(identity=username3, secret=None),
Credentials(identity=None, secret=ssh_keypair3),
]
collected = SSHCredentialCollector(patch_telemetry_messenger).collect_credentials()
assert expected == collected