|
15 | 15 | import java.nio.charset.StandardCharsets; |
16 | 16 | import java.nio.file.Path; |
17 | 17 |
|
| 18 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
18 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue; |
@@ -76,6 +77,15 @@ static void setUp() throws Exception { |
76 | 77 | + "\"jsonBody\":{\"access_token\":\"test-token-12345\",\"token_type\":\"Bearer\",\"expires_in\":3600}" |
77 | 78 | + "}" |
78 | 79 | + "}"); |
| 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 | + + "}"); |
79 | 89 | } |
80 | 90 |
|
81 | 91 | @AfterAll |
@@ -139,12 +149,24 @@ void testDefaultHeaders() throws Exception { |
139 | 149 |
|
140 | 150 | assertNotNull(zitadel); |
141 | 151 |
|
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 | + } |
144 | 166 | 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); |
148 | 170 | } finally { |
149 | 171 | conn.disconnect(); |
150 | 172 | } |
|
0 commit comments