Beispiel #1
0
    def error(self, flow):
        """ Checks if the watchdog will be triggered.

        Only triggers watchdog for timeouts after last reset and if flow.error is set (shows that error is a server
        error). Ignores HttpSyntaxException Errors since this can be triggered on purpose by web application scanner.

        Args:
            flow: mitmproxy.http.flow
        """
        if (self.not_in_timeout(self.last_trigger, self.timeout)
                and flow.error is not None
                and not isinstance(flow.error, HttpSyntaxException)):

            self.last_trigger = time.time()
            logger.error(f"Watchdog triggered! Cause: {flow}")
            self.error_event.set()

            # save the request which might have caused the problem
            if flow.request:
                with (self.flow_dir /
                      f"{datetime.utcnow().isoformat()}.curl").open("w") as f:
                    f.write(curl_command(flow))
                with (self.flow_dir /
                      f"{datetime.utcnow().isoformat()}.raw").open("wb") as f:
                    f.write(raw(flow))
Beispiel #2
0
 def test_tcp(self, tcp_flow):
     with pytest.raises(exceptions.CommandError):
         export.raw(tcp_flow)
Beispiel #3
0
 def test_get(self, get_request):
     assert b"header: qvalue" in export.raw(get_request)
Beispiel #4
0
 def test_missing_both(self, get_request):
     delattr(get_request, 'request')
     delattr(get_request, 'response')
     with pytest.raises(exceptions.CommandError):
         export.raw(get_request)
Beispiel #5
0
 def test_get_response_present(self, get_response):
     delattr(get_response, 'request')
     assert b"header-response: svalue" in export.raw(get_response)
Beispiel #6
0
 def test_req_and_resp_present(self, get_flow):
     assert b"header: qvalue" in export.raw(get_flow)
     assert b"header-response: svalue" in export.raw(get_flow)
Beispiel #7
0
 def test_get_request_present(self, get_request):
     assert b"header: qvalue" in export.raw(get_request)
     assert b"content-length: 0" in export.raw_request(get_request)
Beispiel #8
0
 def test_tcp(self, tcp_flow):
     with pytest.raises(
             exceptions.CommandError,
             match="Can't export flow with no request or response"):
         export.raw(tcp_flow)
Beispiel #9
0
 def test_get_response_present(self, get_response):
     get_response.request.content = None
     assert b"header-response: svalue" in export.raw(get_response)