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