diff --git a/tests/test_list.py b/tests/test_list.py index 055331d..9fcbbcd 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -109,3 +109,32 @@ def test_list_nonexistent_table(client, mocker, valid_credentials): assert response.status_code == 404 assert response.json['error'] == "'nonexistent' is not " \ "a known fail2ban jail" + +def test_list_wrong_table_name(client, mocker, valid_credentials): + ''' + Test for an wrong table name that lets pfctl fail. should result in a 500 + ''' + def noop(): + pass + + run_res = SimpleNamespace() + run_res.stdout = b'' + run_res.stderr = b'No ALTQ support in kernel\nALTQ related functions disabled\n' \ + b'pfctl: Invalid argument.\n' + run_res.returncode = 255 + run_res.check_returncode = noop + + mocker.patch('jail2ban.pfctl.run', + return_value=run_res, + side_effect=CalledProcessError(run_res.returncode, + 'foobar', + output=run_res.stdout, + stderr=run_res.stderr) + ) + + response = client.get("/list/notanerrorbuttestneedstofail", + headers={"Authorization": + "Basic " + valid_credentials}) + + assert response.status_code == 500 + assert response.json['error'] == "Command 'foobar' returned non-zero exit status 255."