Make sure we set the error message in the json as defined in the test

This commit is contained in:
Ruben van Staveren 2023-01-15 18:57:26 +01:00
parent dd66bf3dc9
commit 59ecd48210
Signed by: ruben
GPG Key ID: 886F6BECD477A93F

View File

@ -88,6 +88,9 @@ def create_app():
name = untaint(PAT_NAME, name)
app.logger.info(f'Flushing table f2b-{name}'
f' in anchor f2b-jail/{remote_user}')
reply = {'anchor': f'f2b-jail/{remote_user}',
'table': f'f2b-{name}',
'operation': 'list'}
try:
res = pfctl_table_op('f2b-jail/{remote_user}',
table='f2b-{name}',
@ -96,6 +99,7 @@ def create_app():
except CalledProcessError as err:
if err.stderr.find(b'pfctl: Table does not exist.') > 0:
res = []
reply.update({'error': f'\'{name}\' is not a known fail2ban jail'})
else:
raise err
@ -103,11 +107,9 @@ def create_app():
re.finditer(_PFCTL_TABLE_PAT,
'\n'.join([x.decode('ascii') for x in res]),
re.MULTILINE|re.VERBOSE)]
reply.update({'result': result})
return jsonify({'anchor': f'f2b-jail/{remote_user}',
'table': f'f2b-{name}',
'operation': 'list',
'result': result }), 200 if len(res) else 404
return jsonify(reply), 200 if len(res) else 404
@app.route("/register", methods=['PUT', 'DELETE'])
@auth.login_required