forked from p15670423/monkey
Agent: Capture secrets if missing username in SSHCredentialCollector
This commit is contained in:
parent
d5a125d985
commit
9edfe6979b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue