Test unregistering and check intended fields
This commit is contained in:
parent
963f7e5702
commit
c33e63978e
@ -10,7 +10,7 @@ block drop quick proto tcp from <f2b-recidive> to any
|
||||
'''
|
||||
|
||||
|
||||
def test_request_unauth(client):
|
||||
def test_register_unauth(client):
|
||||
json_payload = {"port":
|
||||
"any port {pop3,pop3s,imap,imaps,submission,465,sieve}",
|
||||
"name": "dovecot", "protocol": "tcp"}
|
||||
@ -19,7 +19,28 @@ def test_request_unauth(client):
|
||||
assert response.json['error'] == 'Access Denied'
|
||||
|
||||
|
||||
def test_request_valid(client, mocker):
|
||||
def test_register_valid(client, mocker):
|
||||
def noop():
|
||||
pass
|
||||
run_res = SimpleNamespace()
|
||||
run_res.stdout = pfctl_stdout_lines
|
||||
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 = {"port":
|
||||
"any port {pop3,pop3s,imap,imaps,submission,465,sieve}",
|
||||
"name": "dovecot", "protocol": "tcp"}
|
||||
|
||||
response = client.delete("/register",
|
||||
json=json_payload,
|
||||
headers={"Authorization": "Basic " + valid_credentials})
|
||||
|
||||
assert response.json['action'] == 'delete'
|
||||
|
||||
|
||||
def test_unregister_valid(client, mocker):
|
||||
def noop():
|
||||
pass
|
||||
run_res = SimpleNamespace()
|
||||
@ -37,10 +58,10 @@ def test_request_valid(client, mocker):
|
||||
json=json_payload,
|
||||
headers={"Authorization": "Basic " + valid_credentials})
|
||||
|
||||
assert response.json['remote_user'] == 'test.example.com'
|
||||
assert response.json['action'] == 'start'
|
||||
|
||||
|
||||
def test_request_invalid(client, mocker):
|
||||
def test_register_invalid(client, mocker):
|
||||
def noop():
|
||||
pass
|
||||
run_res = SimpleNamespace()
|
||||
|
Loading…
x
Reference in New Issue
Block a user