summaryrefslogtreecommitdiffhomepage
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2023-04-27 18:00:16 -0400
committerJeff Forcier <jeff@bitprophet.org>2023-05-05 12:27:20 -0400
commit162213fa1a4551bd955134c97ca5276a5f29e907 (patch)
tree5a70c153853fa2114c7f67523cb59db63ecfc5d8 /tests/conftest.py
parent9ece9fcc8d8e5d22de0a65fcc44374a53c31dfdb (diff)
Migrate rest of main keys and update suite to be more pytest-relaxed compat
Main branch as of today: 350 passed, 21 skipped, 52 deselected, 3 warnings in 11.10s This branch as of this commit: 361 passed, 21 skipped, 52 deselected, 3 warnings in 10.51s Of those 11 "new" tests, 8 are ones I wrote (tests/pkey.py). Hard to figure out what the other 3 are given pytest-relaxed's output is very different from regular verbose pytest. oops.
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py63
1 files changed, 58 insertions, 5 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index b28d2a17..beef87c2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,13 +2,24 @@ import logging
import os
import shutil
import threading
+from pathlib import Path
+
+from invoke.vendor.lexicon import Lexicon
import pytest
-from paramiko import RSAKey, SFTPServer, SFTP, Transport
+from paramiko import (
+ SFTPServer,
+ SFTP,
+ Transport,
+ DSSKey,
+ RSAKey,
+ Ed25519Key,
+ ECDSAKey,
+)
-from .loop import LoopSocket
-from .stub_sftp import StubServer, StubSFTPServer
-from .util import _support
+from ._loop import LoopSocket
+from ._stub_sftp import StubServer, StubSFTPServer
+from ._util import _support
from icecream import ic, install as install_ic
@@ -71,7 +82,7 @@ def sftp_server():
tc = Transport(sockc)
ts = Transport(socks)
# Auth
- host_key = RSAKey.from_private_key_file(_support("test_rsa.key"))
+ host_key = RSAKey.from_private_key_file(_support("rsa.key"))
ts.add_server_key(host_key)
# Server setup
event = threading.Event()
@@ -103,3 +114,45 @@ def sftp(sftp_server):
yield client
# Clean up - as in make_sftp_folder, we assume local-only exec for now.
shutil.rmtree(client.FOLDER, ignore_errors=True)
+
+
+key_data = [
+ ["ssh-rsa", RSAKey, "SHA256:OhNL391d/beeFnxxg18AwWVYTAHww+D4djEE7Co0Yng"],
+ ["ssh-dss", DSSKey, "SHA256:uHwwykG099f4M4kfzvFpKCTino0/P03DRbAidpAmPm0"],
+ [
+ "ssh-ed25519",
+ Ed25519Key,
+ "SHA256:J6VESFdD3xSChn8y9PzWzeF+1tl892mOy2TqkMLO4ow",
+ ],
+ [
+ "ecdsa-sha2-nistp256",
+ ECDSAKey,
+ "SHA256:BrQG04oNKUETjKCeL4ifkARASg3yxS/pUHl3wWM26Yg",
+ ],
+]
+for datum in key_data:
+ short = datum[0].replace("ssh-", "").replace("sha2-nistp", "")
+ datum.insert(0, short)
+
+
+@pytest.fixture(scope="session", params=key_data, ids=lambda x: x[0])
+def key(request):
+ """
+ Yield an object for each known type of key, with attributes:
+
+ - ``short_type``: short identifier, eg ``rsa`` or ``ecdsa-256``
+ - ``full_type``: the "message style" key identifier, eg ``ssh-rsa``, or
+ ``ecdsa-sha2-nistp256``.
+ - ``path``: a pathlib Path object to the fixture key file
+ - ``pkey``: an instantiated PKey subclass object
+ - ``fingerprint``: the expected fingerprint of said key
+ """
+ short_type, key_type, key_class, fingerprint = request.param
+ bag = Lexicon()
+ bag.short_type = short_type
+ bag.full_type = key_type
+ bag.path = Path(_support(f"{short_type}.key"))
+ with bag.path.open() as fd:
+ bag.pkey = key_class.from_private_key(fd)
+ bag.fingerprint = fingerprint
+ yield bag