You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http.py 976B

123456789101112131415161718192021222324252627282930313233343536
  1. import json
  2. from typing import Literal
  3. import httpx
  4. import pytest
  5. from _pytest.monkeypatch import MonkeyPatch
  6. from core.helper import ssrf_proxy
  7. class MockedHttp:
  8. @staticmethod
  9. def httpx_request(
  10. method: Literal["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"], url: str, **kwargs
  11. ) -> httpx.Response:
  12. """
  13. Mocked httpx.request
  14. """
  15. request = httpx.Request(
  16. method, url, params=kwargs.get("params"), headers=kwargs.get("headers"), cookies=kwargs.get("cookies")
  17. )
  18. data = kwargs.get("data")
  19. resp = json.dumps(data).encode("utf-8") if data else b"OK"
  20. response = httpx.Response(
  21. status_code=200,
  22. request=request,
  23. content=resp,
  24. )
  25. return response
  26. @pytest.fixture
  27. def setup_http_mock(request, monkeypatch: MonkeyPatch):
  28. monkeypatch.setattr(ssrf_proxy, "make_request", MockedHttp.httpx_request)
  29. yield
  30. monkeypatch.undo()