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