From 3f94410716842d8f04e8c8244996a805627b6ff5 Mon Sep 17 00:00:00 2001 From: Ruben van Staveren Date: Fri, 11 Mar 2022 22:07:04 +0100 Subject: [PATCH] Let's test an method that is not allowed in app.route --- tests/test_flush.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_flush.py b/tests/test_flush.py index dcd45b7..8f1ef37 100644 --- a/tests/test_flush.py +++ b/tests/test_flush.py @@ -36,3 +36,19 @@ def test_flush_nonexistent(client, mocker): headers={"Authorization": "Basic " + valid_credentials}) assert 'error' in response.json + + +def test_wrong_method(client, mocker): + + cmd = ['/usr/local/bin/sudo', '/sbin/pfctl', '-a', 'some/anchor', '-t', 'nonexistent', '-T', 'flush'] + + mocker.patch('jail2ban.pfctl.run', + side_effect=CalledProcessError(255, cmd, output=b'', + stderr=b'pfctl: Table does not exist')) + + valid_credentials = base64.b64encode(b"test.example.com:testpassword").decode("utf-8") + name = 'nonexistent' + response = client.put(f"/flush/{name}", + headers={"Authorization": "Basic " + valid_credentials}) + + assert response.status_code == 405