Skip to content

Commit

Permalink
increase test coverage for verifyPTR
Browse files Browse the repository at this point in the history
tests whether a nxdomain during verifyPTR does not raise an unexpected
exception but rejects the order.
  • Loading branch information
uedvt359 committed Nov 6, 2024
1 parent 44a698f commit cd13547
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_challengefuns.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def get(self, *args, **kwargs):
class MockedRequestsResponseSession:
def get(self, *args, **kwargs):
mock_response = Mock()
mock_response.raw.connection.sock.getpeername = lambda: ("10.0.0.1", "")
host = args[0].split("/")[2]
peer = {
"example.test": "10.0.0.1",
"example.invalid": "10.0.0.2",
}
mock_response.raw.connection.sock.getpeername = lambda: (peer[host], "")
mock_response.text = "something wrong"
return mock_response

Expand Down Expand Up @@ -339,6 +344,20 @@ def test_http_challenge_ptr(self):
result = main.http_challenge(mock_challenge)
self.assertEqual(result[0], "rejectedIdentifier")

def test_http_challenge_ptr_nxdomain(self):
with unittest.mock.patch.object(
main.requests, "Session", MockedRequestsResponseSession
), unittest.mock.patch.dict(
main.config, {"verifyPTR": True}
), unittest.mock.patch.object(
dns.resolver, "query", mockedDNSResolve
), unittest.mock.patch.object(
dns.resolver, "resolve", mockedDNSResolve
):
mock_challenge.authorization.identifier.value = "example.invalid"
result = main.http_challenge(mock_challenge)
self.assertEqual(result[0], "rejectedIdentifier")

# DNS challenge unit testing
def test_dns_challenge_ok(self):
mock_dns_challenge.authorization.identifier.value = "example.test"
Expand Down

0 comments on commit cd13547

Please sign in to comment.