Let's test an method that is not allowed in app.route

This commit is contained in:
Ruben van Staveren 2022-03-11 22:07:04 +01:00
parent e3a71a851d
commit 3f94410716
Signed by: ruben
GPG Key ID: 886F6BECD477A93F

View File

@ -36,3 +36,19 @@ def test_flush_nonexistent(client, mocker):
headers={"Authorization": "Basic " + valid_credentials}) headers={"Authorization": "Basic " + valid_credentials})
assert 'error' in response.json 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