-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for sss_ssh_knownhosts
Reviewed-by: Alexey Tikhonov <[email protected]> Reviewed-by: Pavel Březina <[email protected]>
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCI56aGtsWIbjz8XhODRT8NAio+TIHMXdiKoG6SdCtVlCR6xNP6gXgmChVWJ9DXlOF3WztOBf9om5SsPGX73/to= | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPeSgRv4Vyq6ehrcA8hc6LFd9cUR1H3vdtH+WMJXvf1h | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4O+2dXWi4iTJR3vlsqZE9707K0sKTeEnWHyMoWUY0N/p6TZgxoLWfUW8XPbj4Yt4BaI6M48/jWZjHjXPJjLfgon3BT5LvyZHrlnN34APcZ7+r73mMt4pIPI7WnzqJluRGgcdEQuJhaSUbTGBUoHwCmp5JAREqWMappkwwSo9QQEzeAxT58dLTEyENTxB1DCP7sJShZd9p+37+5XJ1m1fkpnpDb/JMnTX9jSApk6r2DOZgcpX2aNFMbxSQ5zASfhmzJCfx52c97GD85Zx+LMXBJ4KzNKAbvTsruFj3k5jh7pYvqZseUuReBDCjSGQ4Q4MDBm+XAPbCNfQcgLPo678kkIFK8bZfKLDeJH4g64EO1xHGxBhmcYiXkc0gyqpECKekiUb3ltkyUA/R+Q8Jo+Zr70IHEM2fFvyiIqyz2Nx3PH/FTLDSBguQuEtzBHcMfb9/sO8lbofJneAfsAk3C3TYxqJ176xYqk4C24pB8UrOAflni+P0RqS1Zwte2u3ZD0E= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
""" | ||
sss_ssh_knownhosts tests. | ||
:requirement: None | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
from sssd_test_framework.roles.client import Client | ||
from sssd_test_framework.roles.ipa import IPA | ||
from sssd_test_framework.topology import KnownTopology | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def public_keys(moduledatadir: str) -> list[str]: | ||
""" | ||
Read list of public keys from module data file. | ||
:return: List of public keys. | ||
:rtype: list[str] | ||
""" | ||
keys: list[str] = [] | ||
with open(f"{moduledatadir}/public_keys") as f: | ||
for line in f.readlines(): | ||
stripped = line.strip() | ||
if stripped: | ||
keys.append(stripped) | ||
|
||
return keys | ||
|
||
|
||
@pytest.mark.ticket(gh=5518) | ||
@pytest.mark.importance("low") | ||
@pytest.mark.topology(KnownTopology.IPA) | ||
def test_sss_ssh_knownhosts__by_name(client: Client, ipa: IPA, public_keys: list[str]): | ||
""" | ||
:title: sss_ssh_knownhosts returns public keys by name | ||
:setup: | ||
1. Create IPA host "ssh.ipa.test", public keys and IP resolvable via DNS | ||
2. Enable ssh responder | ||
3. Start SSSD | ||
:steps: | ||
1. Run "sss_ssh_knownhosts ssh.ipa.test" | ||
:expectedresults: | ||
1. All public keys were printed | ||
:customerscenario: False | ||
""" | ||
hostname = f"ssh.{ipa.domain}" | ||
ip = "10.255.251.10" | ||
ipa.host_account(hostname).add(ip=ip, sshpubkey=public_keys) | ||
|
||
client.sssd.enable_responder("ssh") | ||
client.sssd.start() | ||
|
||
result = client.sss_ssh_knownhosts(hostname) | ||
assert result.rc == 0 | ||
assert len(public_keys) == len(result.stdout_lines) | ||
for key in public_keys: | ||
assert f"{hostname} {key}" in result.stdout_lines | ||
|
||
|
||
@pytest.mark.ticket(gh=5518) | ||
@pytest.mark.importance("low") | ||
@pytest.mark.topology(KnownTopology.IPA) | ||
def test_sss_ssh_knownhosts__by_shortname(client: Client, ipa: IPA, public_keys: list[str]): | ||
""" | ||
:title: sss_ssh_knownhosts returns public keys by short name using the search domain | ||
:setup: | ||
1. Create IPA host "ssh.ipa.test", public keys and IP resolvable via DNS | ||
2. Add "search ipa.test" to /etc/resolv.conf | ||
3. Enable ssh responder | ||
4. Start SSSD | ||
:steps: | ||
1. Run "sss_ssh_knownhosts ssh" | ||
:expectedresults: | ||
1. All public keys were printed | ||
:customerscenario: False | ||
""" | ||
hostname = f"ssh.{ipa.domain}" | ||
ip = "10.255.251.10" | ||
ipa.host_account(hostname).add(ip=ip, sshpubkey=public_keys) | ||
|
||
client.fs.append("/etc/resolv.conf", f"search {ipa.domain}") | ||
client.sssd.enable_responder("ssh") | ||
client.sssd.start() | ||
|
||
result = client.sss_ssh_knownhosts("ssh") | ||
assert result.rc == 0 | ||
assert len(public_keys) == len(result.stdout_lines) | ||
for key in public_keys: | ||
assert f"ssh {key}" in result.stdout_lines | ||
|
||
|
||
@pytest.mark.ticket(gh=5518) | ||
@pytest.mark.importance("low") | ||
@pytest.mark.topology(KnownTopology.IPA) | ||
def test_sss_ssh_knownhosts__by_ip(client: Client, ipa: IPA, public_keys: list[str]): | ||
""" | ||
:title: sss_ssh_knownhosts returns public keys by IP | ||
:setup: | ||
1. Create IPA host "ssh.ipa.test", public keys and IP resolvable via DNS | ||
2. Enable ssh responder | ||
3. Start SSSD | ||
:steps: | ||
1. Run "sss_ssh_knownhosts $ip" | ||
:expectedresults: | ||
1. All public keys were printed | ||
:customerscenario: False | ||
""" | ||
hostname = f"ssh.{ipa.domain}" | ||
ip = "10.255.251.10" | ||
ipa.host_account(hostname).add(ip=ip, sshpubkey=public_keys) | ||
|
||
client.sssd.enable_responder("ssh") | ||
client.sssd.start() | ||
|
||
result = client.sss_ssh_knownhosts(ip) | ||
assert result.rc == 0 | ||
assert len(public_keys) == len(result.stdout_lines) | ||
for key in public_keys: | ||
assert f"{ip} {key}" in result.stdout_lines |