From 62e58b122f905b4e5462df6b0bbebd278bb56419 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Fri, 4 Jun 2021 23:13:05 -0700 Subject: [PATCH] fix test_accounts_routes test coverage Signed-off-by: Kevin Morris --- .gitlab-ci.yml | 2 +- test/test_accounts_routes.py | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5bdf427c..8e14f77f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ cache: before_script: - pacman -Syu --noconfirm --noprogressbar --needed --cachedir .pkg-cache - base-devel git gpgme protobuf pyalpm python-mysql-connector + base-devel git gpgme protobuf pyalpm python-mysqlclient python-pygit2 python-srcinfo python-bleach python-markdown python-sqlalchemy python-alembic python-pytest python-werkzeug python-pytest-tap python-fastapi hypercorn nginx python-authlib diff --git a/test/test_accounts_routes.py b/test/test_accounts_routes.py index 3080a505..d5fd089e 100644 --- a/test/test_accounts_routes.py +++ b/test/test_accounts_routes.py @@ -30,6 +30,20 @@ client = TestClient(app) user = None +def make_ssh_pubkey(): + # Create a public key with ssh-keygen (this adds ssh-keygen as a + # dependency to passing this test). + with tempfile.TemporaryDirectory() as tmpdir: + with open("/dev/null", "w") as null: + proc = Popen(["ssh-keygen", "-f", f"{tmpdir}/test.ssh", "-N", ""], + stdout=null, stderr=null) + proc.wait() + assert proc.returncode == 0 + + # Read in the public key, then delete the temp dir we made. + return open(f"{tmpdir}/test.ssh.pub").read().rstrip() + + @pytest.fixture(autouse=True) def setup(): global user @@ -770,27 +784,13 @@ def test_post_account_edit_error_unauthorized(): def test_post_account_edit_ssh_pub_key(): - pk = str() - - # Create a public key with ssh-keygen (this adds ssh-keygen as a - # dependency to passing this test). - with tempfile.TemporaryDirectory() as tmpdir: - with open("/dev/null", "w") as null: - proc = Popen(["ssh-keygen", "-f", f"{tmpdir}/test.ssh", "-N", ""], - stdout=null, stderr=null) - proc.wait() - assert proc.returncode == 0 - - # Read in the public key, then delete the temp dir we made. - pk = open(f"{tmpdir}/test.ssh.pub").read().rstrip() - request = Request() sid = user.login(request, "testPassword") post_data = { "U": "test", "E": "test@example.org", - "PK": pk, + "PK": make_ssh_pubkey(), "passwd": "testPassword" }