Skip to content

Commit 8ee3d24

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 16c7a55 commit 8ee3d24

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

‎src/test/java/com/zitadel/TransportOptionsTest.java‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.nio.charset.StandardCharsets;
1616
import java.nio.file.Path;
1717

18+
import static org.junit.jupiter.api.Assertions.assertFalse;
1819
import static org.junit.jupiter.api.Assertions.assertNotNull;
1920
import static org.junit.jupiter.api.Assertions.assertThrows;
2021
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -76,6 +77,15 @@ static void setUp() throws Exception {
7677
+ "\"jsonBody\":{\"access_token\":\"test-token-12345\",\"token_type\":\"Bearer\",\"expires_in\":3600}"
7778
+ "}"
7879
+ "}");
80+
81+
registerStub("{"
82+
+ "\"request\":{\"method\":\"POST\",\"url\":\"/zitadel.settings.v2.SettingsService/GetGeneralSettings\"},"
83+
+ "\"response\":{"
84+
+ "\"status\":200,"
85+
+ "\"headers\":{\"Content-Type\":\"application/json\"},"
86+
+ "\"jsonBody\":{}"
87+
+ "}"
88+
+ "}");
7989
}
8090

8191
@AfterAll
@@ -139,12 +149,24 @@ void testDefaultHeaders() throws Exception {
139149

140150
assertNotNull(zitadel);
141151

142-
URL journalUrl = new URL("http://" + host + ":" + httpPort + "/__admin/requests");
143-
HttpURLConnection conn = (HttpURLConnection) journalUrl.openConnection();
152+
// Make an actual API call to verify headers propagate to service requests
153+
zitadel.getSettings().getGeneralSettings();
154+
155+
// Use WireMock's verification API to assert the header was sent on the API call
156+
URL verifyUrl = new URL("http://" + host + ":" + httpPort + "/__admin/requests/count");
157+
HttpURLConnection conn = (HttpURLConnection) verifyUrl.openConnection();
158+
conn.setRequestMethod("POST");
159+
conn.setRequestProperty("Content-Type", "application/json");
160+
conn.setDoOutput(true);
161+
String verifyBody = "{\"url\":\"/zitadel.settings.v2.SettingsService/GetGeneralSettings\","
162+
+ "\"headers\":{\"X-Custom-Header\":{\"equalTo\":\"test-value\"}}}";
163+
try (OutputStream os = conn.getOutputStream()) {
164+
os.write(verifyBody.getBytes(StandardCharsets.UTF_8));
165+
}
144166
try (var in = conn.getInputStream()) {
145-
String journal = new String(in.readAllBytes());
146-
assertTrue(journal.contains("X-Custom-Header"),
147-
"Custom header should be present in WireMock request journal");
167+
String result = new String(in.readAllBytes());
168+
assertFalse(result.contains("\"count\" : 0"),
169+
"Custom header should be present on API call, got: " + result);
148170
} finally {
149171
conn.disconnect();
150172
}

0 commit comments

Comments
 (0)