Compare commits

...

4 Commits

2 changed files with 7 additions and 3 deletions

View File

@ -94,7 +94,7 @@ def create_app():
verbose=True)
result = [entry.groupdict() for entry in
re.finditer(_PFCTL_TABLE_PAT,
'\n'.join(res),
'\n'.join([x.decode('ascii') for x in res]),
re.MULTILINE|re.VERBOSE)]
return jsonify({'anchor': f'f2b-jail/{remote_user}',

View File

@ -2,6 +2,7 @@
Tests for /list route
'''
from types import SimpleNamespace
from subprocess import CalledProcessError
_PF_TABLE_LIST = b''' 192.0.2.66
@ -75,7 +76,7 @@ def test_list_single_table(client, mocker, valid_credentials):
headers={"Authorization":
"Basic " + valid_credentials})
assert response.json['anchor'] == 'f2b-sshd/test.example.com'
assert response.json['table'] == 'f2b-sshd'
assert response.json['result'] == _LIST_RESULT
@ -88,10 +89,13 @@ def test_list_nonexistent_table(client, mocker, valid_credentials):
run_res = SimpleNamespace()
run_res.stdout = b''
run_res.stderr = b'No ALTQ support in kernel\nALTQ related functions disabled\n'
run_res.stderr = b'No ALTQ support in kernel\nALTQ related functions disabled\n' \
b'pfctl: Table does not exist.\n'
run_res.returncode = 255
run_res.check_returncode = noop
# XXX raise a CalledProcessError here...
mocker.patch('jail2ban.pfctl.run', return_value=run_res)
response = client.get("/list/nonexistent",