|
4 | 4 | import io.github.easy4j.hermes.HermesClientConfig; |
5 | 5 | import io.github.easy4j.hermes.HermesCliConfig; |
6 | 6 | import io.github.easy4j.hermes.HermesHttpClientConfig; |
| 7 | +import io.github.easy4j.hermes.HermesOkHttpClientFactory; |
7 | 8 | import io.github.easy4j.hermes.api.model.ChatRequest; |
| 9 | +import okhttp3.MediaType; |
| 10 | +import okhttp3.OkHttpClient; |
| 11 | +import okhttp3.Protocol; |
| 12 | +import okhttp3.Response; |
| 13 | +import okhttp3.ResponseBody; |
8 | 14 | import okhttp3.mockwebserver.MockResponse; |
9 | 15 | import okhttp3.mockwebserver.MockWebServer; |
10 | 16 | import okhttp3.mockwebserver.RecordedRequest; |
@@ -127,6 +133,35 @@ void credentialSnapshotDoesNotExposeSecretInToString() { |
127 | 133 | assertFalse(snapshot.toString().contains("super-secret-token")); |
128 | 134 | } |
129 | 135 |
|
| 136 | + @Test |
| 137 | + void statefulExternalInterceptorIsRejectedForIsolatedProfiles() { |
| 138 | + OkHttpClient external = new OkHttpClient.Builder() |
| 139 | + .addInterceptor(chain -> new Response.Builder() |
| 140 | + .request(chain.request()) |
| 141 | + .protocol(Protocol.HTTP_1_1) |
| 142 | + .code(200) |
| 143 | + .message("OK") |
| 144 | + .body(ResponseBody.create( |
| 145 | + "{\"status\":\"ok\"}", |
| 146 | + MediaType.get("application/json"))) |
| 147 | + .build()) |
| 148 | + .build(); |
| 149 | + |
| 150 | + HermesHttpClientConfig http = new HermesHttpClientConfig(); |
| 151 | + http.markUnsafeBaseUrlOverriddenForTest(true); |
| 152 | + http.setBaseUrl("http://127.0.0.1:8642"); |
| 153 | + |
| 154 | + ProfileBinding binding = ProfileBinding.of( |
| 155 | + "team-a", "credential-a", |
| 156 | + identity -> CredentialSnapshot.of("profile-token", "1")); |
| 157 | + |
| 158 | + try (HermesClient root = new HermesClient(http, disabledCli(), external)) { |
| 159 | + assertThrows(IllegalStateException.class, () -> root.forProfile(binding)); |
| 160 | + } finally { |
| 161 | + HermesOkHttpClientFactory.shutdown(external); |
| 162 | + } |
| 163 | + } |
| 164 | + |
130 | 165 | @Test |
131 | 166 | void businessHeadersCannotOverrideBoundAuthorization() throws Exception { |
132 | 167 | try (MockWebServer server = new MockWebServer()) { |
|
0 commit comments