Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: sss_ssh_knownhosts with port number #7619

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion src/tests/system/tests/test_ipa.py
aplopez marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def public_keys(moduledatadir: str) -> list[str]:


@pytest.mark.ticket(gh=5518)
@pytest.mark.importance("low")
@pytest.mark.importance("high")
@pytest.mark.topology(KnownTopology.IPA)
@pytest.mark.builtwith(client="knownhosts")
def test_ipa__hostpublickeys_by_name(client: Client, ipa: IPA, public_keys: list[str]):
"""
:title: sss_ssh_knownhosts returns public keys by name
Expand Down Expand Up @@ -68,6 +69,7 @@ def test_ipa__hostpublickeys_by_name(client: Client, ipa: IPA, public_keys: list
@pytest.mark.ticket(gh=5518)
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.IPA)
@pytest.mark.builtwith(client="knownhosts")
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
Expand Down Expand Up @@ -100,6 +102,7 @@ def test_ipa__hostpublickeys_by_shortname(client: Client, ipa: IPA, public_keys:
@pytest.mark.ticket(gh=5518)
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.IPA)
@pytest.mark.builtwith(client="knownhosts")
def test_ipa__hostpublickeys_by_ip(client: Client, ipa: IPA, public_keys: list[str]):
"""
:title: sss_ssh_knownhosts returns public keys by IP
Expand Down Expand Up @@ -127,6 +130,96 @@ def test_ipa__hostpublickeys_by_ip(client: Client, ipa: IPA, public_keys: list[s
assert f"{ip} {key}" in result.stdout_lines, "Did not get expected public keys!"


@pytest.mark.ticket(gh=7583)
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.IPA)
@pytest.mark.parametrize("option", [(None), ("-o")])
@pytest.mark.builtwith(client="knownhosts")
def test_ipa__hostpublickeys_by_name_with_port(client: Client, ipa: IPA, public_keys: list[str], option: str | None):
"""
:title: sss_ssh_knownhosts returns public keys by host name with port
:setup:
1. Create host with SSH key
2. Configure SSSD with SSH responder
3. Start SSSD
:steps:
1. Lookup SSH key
:expectedresults:
1. All public keys were printed
:customerscenario: False
"""
hostname = f"ssh-host.{ipa.domain}"
ip = "10.255.251.10"
port = 3333

ipa.host_account(hostname).add(ip=ip, sshpubkey=public_keys)
client.sssd.enable_responder("ssh")
client.sssd.start()

args = []
if option is not None:
args.append(option)
args.append(f"[{hostname}]:{port}")

result = client.sss_ssh_knownhosts(*args)
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:
if option == "-o":
output = f"{hostname} {key}"
else:
output = f"[{hostname}]:{port} {key}"
assert output in result.stdout_lines, "Did not get expected public keys!"


@pytest.mark.ticket(gh=7583)
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.IPA)
@pytest.mark.builtwith(client="knownhosts")
def test_ipa__hostpublickeys_with_non_default_port(client: Client, ipa: IPA, public_keys: list[str]):
"""
:title: sss_ssh_knownhosts returns public keys by hostname with non-default port
:setup:
1. Create host with SSH key
2. Add the ipasshpubkey with hostname and port
3. Configure SSSD with SSH responder
4. Start SSSD
:steps:
1. Lookup SSH key
:expectedresults:
1. All public keys were printed
:customerscenario: False
"""
hostname = f"ssh-host.{ipa.domain}"
ip = "10.255.251.10"
port = 4444

ipa.host_account(hostname).add(ip=ip, sshpubkey=public_keys)
client.sssd.enable_responder("ssh")
client.sssd.start()

# IPA doesn't currently ipa host-mod with hostname and key
# this is workaround till IPA add the support.
for key in public_keys:
modify_content = ipa.fs.mktmp(
aplopez marked this conversation as resolved.
Show resolved Hide resolved
rf"""
dn: fqdn={hostname},cn=computers,cn=accounts,dc=ipa,dc=test
changetype: modify
add: ipaSshPubKey
ipaSshPubKey: [{hostname}]:{port} {key}
""",
mode="a=rx",
)
ipa.host.conn.run(command=f"ldapmodify -H ldap://master.ipa.test -f {modify_content}")

result = client.sss_ssh_knownhosts(f"[{hostname}]:{port}")
assert result.rc == 0, "Did not get OpenSSH known hosts public keys!"
for key in public_keys:
assert f"[{hostname}]:{port} {key}" in result.stdout_lines, (
"Did not get expected public keys with " " the host name with port"
)


@pytest.mark.ticket(bz=1926622)
@pytest.mark.integration
@pytest.mark.importance("low")
Expand Down
Loading