Skip to content

Commit 367dc2e

Browse files
committed
Verify default headers on API calls via WireMock verification
Add WireMock stub for settings endpoint and use WireMock's /__admin/requests/count API to assert custom headers are sent on actual API calls, not just during initialization.
1 parent 9a5dc7d commit 367dc2e

1 file changed

Lines changed: 43 additions & 12 deletions

File tree

test/test_transport_options.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ def setup_class(cls) -> None:
106106
with urllib.request.urlopen(req) as resp: # noqa: S310
107107
assert resp.status == 201
108108

109+
# Register stub for Settings API endpoint (for verifying headers on API calls)
110+
settings_stub = json.dumps(
111+
{
112+
"request": {
113+
"method": "POST",
114+
"url": "/zitadel.settings.v2.SettingsService/GetGeneralSettings",
115+
},
116+
"response": {
117+
"status": 200,
118+
"headers": {"Content-Type": "application/json"},
119+
"jsonBody": {},
120+
},
121+
}
122+
).encode()
123+
124+
req = urllib.request.Request(
125+
f"http://{cls.host}:{cls.http_port}/__admin/mappings",
126+
data=settings_stub,
127+
headers={"Content-Type": "application/json"},
128+
method="POST",
129+
)
130+
with urllib.request.urlopen(req) as resp: # noqa: S310
131+
assert resp.status == 201
132+
109133
@classmethod
110134
def teardown_class(cls) -> None:
111135
if cls.wiremock is not None:
@@ -139,18 +163,25 @@ def test_default_headers(self) -> None:
139163
)
140164
self.assertIsNotNone(zitadel)
141165

142-
# Verify via WireMock request journal
143-
journal_url = f"http://{self.host}:{self.http_port}/__admin/requests"
144-
with urllib.request.urlopen(journal_url) as response: # noqa: S310
145-
journal = json.loads(response.read().decode())
146-
147-
found_header = False
148-
for req in journal.get("requests", []):
149-
headers = req.get("request", {}).get("headers", {})
150-
if "X-Custom-Header" in headers:
151-
found_header = True
152-
break
153-
self.assertTrue(found_header, "Custom header should be present in WireMock request journal")
166+
# Make an actual API call to verify headers propagate to service requests
167+
zitadel.settings.get_general_settings({})
168+
169+
# Use WireMock's verification API to assert the header was sent on the API call
170+
verify_body = json.dumps(
171+
{
172+
"url": "/zitadel.settings.v2.SettingsService/GetGeneralSettings",
173+
"headers": {"X-Custom-Header": {"equalTo": "test-value"}},
174+
}
175+
).encode()
176+
req = urllib.request.Request(
177+
f"http://{self.host}:{self.http_port}/__admin/requests/count",
178+
data=verify_body,
179+
headers={"Content-Type": "application/json"},
180+
method="POST",
181+
)
182+
with urllib.request.urlopen(req) as resp: # noqa: S310
183+
result = json.loads(resp.read().decode())
184+
self.assertGreaterEqual(result["count"], 1, "Custom header should be present on API call")
154185

155186
def test_proxy_url(self) -> None:
156187
# Use HTTP (not HTTPS) to avoid TLS complications with the proxy

0 commit comments

Comments
 (0)