Files
insights/.semgrep/rules/security/data-imports-http-transport.py
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

138 lines
3.8 KiB
Python

# Test cases for data-imports-http-transport rules.
# These fixtures are matched against the rule patterns by `pytest .semgrep/`.
# ruff: noqa: F401, F841, E501
#
# `paths.include` in the rule scopes the matchers to
# `products/warehouse_sources/backend/temporal/data_imports/sources/**`, but for the test fixture the
# paths setting is ignored — semgrep applies the rule directly to this file.
import httpx
import requests
from requests import Request, Response, Session
from requests.exceptions import HTTPError, RequestException
# ============================================================
# Should flag: direct requests.<verb>
# ============================================================
def bad_requests_get():
# ruleid: data-imports-http-transport-requests-verb
return requests.get("https://api.example.com/")
def bad_requests_post():
# ruleid: data-imports-http-transport-requests-verb
return requests.post("https://api.example.com/", json={"a": 1})
def bad_requests_put():
# ruleid: data-imports-http-transport-requests-verb
return requests.put("https://api.example.com/", json={})
def bad_requests_patch():
# ruleid: data-imports-http-transport-requests-verb
return requests.patch("https://api.example.com/", json={})
def bad_requests_delete():
# ruleid: data-imports-http-transport-requests-verb
return requests.delete("https://api.example.com/")
def bad_requests_head():
# ruleid: data-imports-http-transport-requests-verb
return requests.head("https://api.example.com/")
def bad_requests_options():
# ruleid: data-imports-http-transport-requests-verb
return requests.options("https://api.example.com/")
def bad_requests_request():
# ruleid: data-imports-http-transport-requests-verb
return requests.request("GET", "https://api.example.com/")
# ============================================================
# Should flag: requests.Session()
# ============================================================
def bad_session():
# ruleid: data-imports-http-transport-requests-session
return requests.Session()
def bad_session_with_kwargs():
# ruleid: data-imports-http-transport-requests-session
sess = requests.Session()
sess.headers.update({"X-Custom": "value"})
return sess
# ============================================================
# Should flag: httpx.Client / httpx.<verb>
# ============================================================
def bad_httpx_client():
# ruleid: data-imports-http-transport-httpx-client
return httpx.Client()
def bad_httpx_async_client():
# ruleid: data-imports-http-transport-httpx-client
return httpx.AsyncClient()
def bad_httpx_get():
# ruleid: data-imports-http-transport-httpx-client
return httpx.get("https://api.example.com/")
def bad_httpx_post():
# ruleid: data-imports-http-transport-httpx-client
return httpx.post("https://api.example.com/", json={})
# ============================================================
# Should NOT flag: type and exception imports
# ============================================================
def ok_request_type_annotation(req: Request, resp: Response) -> None:
pass
def ok_session_type_annotation(sess: Session) -> None:
pass
def ok_exception_handling():
try:
do_something()
except HTTPError:
pass
except RequestException:
pass
def do_something() -> None:
pass
# ============================================================
# Should NOT flag: tracked session (the supported path)
# ============================================================
def ok_tracked_session():
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
session = make_tracked_session()
return session.get("https://api.example.com/")