Skip to content

Commit

Permalink
Test: housekeeping: test_sss_ssh_knownhosts.py => test_ipa.py
Browse files Browse the repository at this point in the history
Update the docstring of each test.
Update the test case method name.
Added assertion error messages on failures.

Signed-off-by: Madhuri Upadhye <[email protected]>

Reviewed-by: Dan Lavu <[email protected]>
Reviewed-by: Jakub Vávra <[email protected]>
  • Loading branch information
madhuriupadhye authored and alexey-tikhonov committed Aug 2, 2024
1 parent 8e59f77 commit 2162317
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""
sss_ssh_knownhosts tests.
IPA SSH Public Host Keys Tests.
:requirement: Support 'KnownHostsCommand' and deprecate 'sss_ssh_knownhostsproxy'
:requirement: IPA: hostpublickeys
sss_ssh_knownhosts acquires SSH public keys for host and outputs them in OpenSSH known_hosts key format.
Support for 'KnownHostsCommand' and deprecate 'sss_ssh_knownhostsproxy'
"""

from __future__ import annotations
Expand Down Expand Up @@ -33,46 +36,45 @@ def public_keys(moduledatadir: str) -> list[str]:
@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]):
def test_ipa__hostpublickeys_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
1. Create host with SSH key
2. Configure SSSD with SSH responder
3. Start SSSD
:steps:
1. Run "sss_ssh_knownhosts ssh.ipa.test"
1. Lookup SSH key
: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)

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)
assert result.rc == 0, "Did not get OpenSSH known hosts public keys!"
assert len(public_keys) == len(result.stdout_lines), "Did not get expected number of public keys!"
for key in public_keys:
assert f"{hostname} {key}" in result.stdout_lines
assert f"{hostname} {key}" in result.stdout_lines, "Did not get expected public keys!"


@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]):
def test_ipa__hostpublickeys_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
1. Create host with SSH key and add "search ipa.test" to /etc/resolv.conf
2. Configure SSSD with SSH responder
3. Start SSSD
:steps:
1. Run "sss_ssh_knownhosts ssh"
1. Lookup SSH key by running "sss_ssh_knownhosts ssh"
:expectedresults:
1. All public keys were printed
:customerscenario: False
Expand All @@ -86,24 +88,24 @@ def test_sss_ssh_knownhosts__by_shortname(client: Client, ipa: IPA, public_keys:
client.sssd.start()

result = client.sss_ssh_knownhosts("ssh")
assert result.rc == 0
assert len(public_keys) == len(result.stdout_lines)
assert result.rc == 0, "Did not get OpenSSH known hosts public keys!"
assert len(public_keys) == len(result.stdout_lines), "Did not get expected number of public keys!"
for key in public_keys:
assert f"ssh {key}" in result.stdout_lines
assert f"ssh {key}" in result.stdout_lines, "Did not get expected public keys!"


@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]):
def test_ipa__hostpublickeys_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
1. Create host with SSH key
2. Configure SSSD with SSH responder
3. Start SSSD
:steps:
1. Run "sss_ssh_knownhosts $ip"
1. Lookup SSH key by running "sss_ssh_knownhosts $ip"
:expectedresults:
1. All public keys were printed
:customerscenario: False
Expand All @@ -116,7 +118,7 @@ def test_sss_ssh_knownhosts__by_ip(client: Client, ipa: IPA, public_keys: list[s
client.sssd.start()

result = client.sss_ssh_knownhosts(ip)
assert result.rc == 0
assert len(public_keys) == len(result.stdout_lines)
assert result.rc == 0, "Did not get OpenSSH known hosts public keys!"
assert len(public_keys) == len(result.stdout_lines), "Did not get expected number of public keys!"
for key in public_keys:
assert f"{ip} {key}" in result.stdout_lines
assert f"{ip} {key}" in result.stdout_lines, "Did not get expected public keys!"

0 comments on commit 2162317

Please sign in to comment.