From bd12b2a18a5565de0619643e458921a50a451298 Mon Sep 17 00:00:00 2001 From: Ruben van Staveren Date: Thu, 10 Mar 2022 14:03:09 +0100 Subject: [PATCH] pylint fixes --- tests/test_ban.py | 19 +++++-------------- tests/test_register.py | 11 +++++++---- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/test_ban.py b/tests/test_ban.py index 61c6584..edf3266 100644 --- a/tests/test_ban.py +++ b/tests/test_ban.py @@ -1,14 +1,6 @@ import base64 from types import SimpleNamespace -pfctl_stdout_lines = b''' -block drop quick proto tcp from to any port = submission -block drop quick proto tcp from to any port = smtps -block drop quick proto tcp from to any port = smtp -block drop quick proto tcp from to any port = ssh -block drop quick proto tcp from to any -''' - def test_ban_ipv6(client, mocker): def noop(): @@ -16,36 +8,35 @@ def test_ban_ipv6(client, mocker): run_res = SimpleNamespace() run_res.stdout = b'' run_res.stderr = b'1/1 addresses added.\n' - run_res.returncode=0 + run_res.returncode = 0 run_res.check_returncode = noop mocker.patch('jail2ban.pfctl.run', return_value=run_res) valid_credentials = base64.b64encode(b"test.example.com:testpassword").decode("utf-8") - json_payload = {"name":"sshd","ip":"2001:db8::abad:cafe"} + json_payload = {"name": "sshd", "ip": "2001:db8::abad:cafe"} response = client.put("/ban", json=json_payload, headers={"Authorization": "Basic " + valid_credentials}) - assert response.json['operation'] == 'add' + def test_ban_ipv4(client, mocker): def noop(): pass run_res = SimpleNamespace() run_res.stdout = b'' run_res.stderr = b'1/1 addresses added.\n' - run_res.returncode=0 + run_res.returncode = 0 run_res.check_returncode = noop mocker.patch('jail2ban.pfctl.run', return_value=run_res) valid_credentials = base64.b64encode(b"test.example.com:testpassword").decode("utf-8") - json_payload = {"name":"sshd","ip":"192.0.2.42"} + json_payload = {"name": "sshd", "ip": "192.0.2.42"} response = client.put("/ban", json=json_payload, headers={"Authorization": "Basic " + valid_credentials}) - assert response.json['operation'] == 'add' diff --git a/tests/test_register.py b/tests/test_register.py index b061ad6..9dc5bda 100644 --- a/tests/test_register.py +++ b/tests/test_register.py @@ -11,7 +11,9 @@ block drop quick proto tcp from to any def test_request_unauth(client): - json_payload = {"port": "any port {pop3,pop3s,imap,imaps,submission,465,sieve}", "name": "dovecot", "protocol": "tcp"} + json_payload = {"port": + "any port {pop3,pop3s,imap,imaps,submission,465,sieve}", + "name": "dovecot", "protocol": "tcp"} response = client.put("/register", json=json_payload) assert response.json['error'] == 'Access Denied' @@ -26,12 +28,13 @@ def test_request_example(client, mocker): mocker.patch('jail2ban.pfctl.run', return_value=run_res) - valid_credentials = base64.b64encode(b"test.example.com:testpassword").decode("utf-8") - json_payload = {"port": "any port {pop3,pop3s,imap,imaps,submission,465,sieve}", "name": "dovecot", "protocol": "tcp"} + json_payload = {"port": + "any port {pop3,pop3s,imap,imaps,submission,465,sieve}", + "name": "dovecot", "protocol": "tcp"} + response = client.put("/register", json=json_payload, headers={"Authorization": "Basic " + valid_credentials}) - assert response.json['remote_user'] == 'test.example.com'