|
33 | 33 | class HermesOkHttpClientTest { |
34 | 34 |
|
35 | 35 | @Test |
36 | | - void shouldRouteManagedProfilesThroughOneSharedTransport() { |
37 | | - AtomicReference<String> requestedPath = new AtomicReference<>(); |
38 | | - OkHttpClient external = new OkHttpClient.Builder() |
39 | | - .addInterceptor(chain -> { |
40 | | - requestedPath.set(chain.request().url().encodedPath()); |
41 | | - return new Response.Builder() |
42 | | - .request(chain.request()) |
43 | | - .protocol(Protocol.HTTP_1_1) |
44 | | - .code(200) |
45 | | - .message("OK") |
46 | | - .body(ResponseBody.create( |
47 | | - "{\"id\":\"response-1\",\"choices\":[]}", |
48 | | - MediaType.get("application/json"))) |
49 | | - .build(); |
50 | | - }) |
51 | | - .build(); |
| 36 | + void shouldNotDeriveNamedProfileFromUncredentialedExternalTransport() { |
| 37 | + OkHttpClient external = new OkHttpClient.Builder().build(); |
52 | 38 | HermesHttpClientConfig httpConfig = new HermesHttpClientConfig(); |
53 | 39 | httpConfig.markUnsafeBaseUrlOverriddenForTest(true); |
54 | 40 | httpConfig.setBaseUrl("http://127.0.0.1:8642/"); |
55 | 41 | HermesCliConfig cliConfig = new HermesCliConfig(); |
56 | 42 | cliConfig.setEnabled(false); |
57 | 43 |
|
58 | 44 | try (HermesClient client = new HermesClient(httpConfig, cliConfig, new ObjectMapper(), external)) { |
59 | | - HermesClient sales = client.forProfile("sales"); |
60 | | - assertSame(sales, client.forProfile("sales")); |
61 | | - assertSame(external, sales.getOkHttpClient()); |
62 | | - assertFalse(sales.isCliEnabled()); |
63 | | - sales.chatCompletion(new ChatRequest()); |
64 | | - assertEquals("/p/sales/v1/chat/completions", requestedPath.get()); |
| 45 | + assertSame(external, client.getOkHttpClient()); |
| 46 | + assertThrows(IllegalStateException.class, () -> client.forProfile("sales")); |
65 | 47 | assertThrows(IllegalArgumentException.class, () -> client.forProfile("../sales")); |
66 | | - assertThrows(IllegalStateException.class, () -> sales.forProfile("care")); |
67 | | - |
68 | | - sales.close(); |
69 | | - assertSame(sales, client.forProfile("sales")); |
70 | 48 | } finally { |
71 | 49 | HermesOkHttpClientFactory.shutdown(external); |
72 | 50 | } |
|
0 commit comments