Unverified Commit 652b5793 authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

test: add OpenSSH key test with a ed25519 key

parent f3f72b9f
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
opensshpubkey1 = load_fixture("test_openssh_pub_key1.pub")
# Generated by: ssh-keygen -t rsa -b 4096 -C "Test2"
opensshpubkey2 = load_fixture("test_openssh_pub_key2.pub")
# Generated by: ssh-keygen -t ed25519 -C Test3
opensshpubkey3 = load_fixture("test_openssh_pub_key3.pub")


def openssh_version():
@@ -40,29 +42,47 @@ def openssh_version():
    return re.match(r"OpenSSH_([a-zA-Z0-9._+-]+)", out.decode()).group(1)


def test_identification(opensshpubkey1):
def test_identification_dsa(opensshpubkey1):
    assert isinstance(opensshpubkey1, PublicKeyFile)


def test_identification_rsa(opensshpubkey1):
    assert isinstance(opensshpubkey1, PublicKeyFile)


def test_identification_ed25519(opensshpubkey3):
    assert isinstance(opensshpubkey3, PublicKeyFile)


def test_no_differences(opensshpubkey1):
    difference = opensshpubkey1.compare(opensshpubkey1)
    assert difference is None


@pytest.fixture
def differences(opensshpubkey1, opensshpubkey2):
def differences12(opensshpubkey1, opensshpubkey2):
    return opensshpubkey1.compare(opensshpubkey2).details


@pytest.fixture
def differences23(opensshpubkey2, opensshpubkey3):
    return opensshpubkey2.compare(opensshpubkey3).details


@skip_unless_tool_is_at_least("ssh-keygen", openssh_version, "6.9")
def test_diff12(differences12):
    assert_diff(differences12[0], "openssh_pub_key_expected_diff_12")


@skip_unless_tool_is_at_least("ssh-keygen", openssh_version, "6.9")
def test_diff(differences):
    assert_diff(differences[0], "openssh_pub_key_expected_diff")
def test_diff23(differences23):
    assert_diff(differences23[0], "openssh_pub_key_expected_diff_23")


@skip_unless_tools_exist("ssh-keygen")
def test_compare_non_existing(monkeypatch, opensshpubkey1):
def test_compare_non_existing(monkeypatch, opensshpubkey2):
    monkeypatch.setattr(Config(), "new_file", True)
    difference = opensshpubkey1.compare(
    difference = opensshpubkey2.compare(
        MissingFile("/nonexisting", opensshpubkey1)
    )
    assert difference.source2 == "/nonexisting"
+3 −0
Original line number Diff line number Diff line
@@ -1 +1 @@
-4096 SHA256:9dH1CMkA6DSfPWU7vNwdPKS5/ppN4LMdvHTP60l7aSA Test2 (RSA)
+256 SHA256:8ST9pb6y/NgI8ZYvBhDhJedL9t0M19eft08gRvr6A8c Test3 (ED25519)
+1 −0
Original line number Diff line number Diff line
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFWd/pU/agbjC08engoJraAd23N/EiWLZpXiuISQv5JM Test3