Skip to content

Commit d7292ef

Browse files
committed
test(transport): cover endpoint policy integration gaps
1 parent 02f5cf8 commit d7292ef

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎src/test/java/io/github/easy4j/hermes/api/sse/SseLifecycleContractTest.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,31 @@ void sessionDisconnectDoesNotReplayOriginalPost() throws Exception {
131131
}
132132
}
133133
}
134+
135+
@Test
136+
void runIdentifierIsEncodedAsOneSsePathSegment() throws Exception {
137+
try (MockWebServer server = new MockWebServer()) {
138+
server.enqueue(new MockResponse()
139+
.setResponseCode(200)
140+
.setHeader("Content-Type", "text/event-stream")
141+
.setBody("data: [DONE]\\n\\n"));
142+
server.start();
143+
144+
HermesHttpClientConfig config = new HermesHttpClientConfig()
145+
.setEndpointPolicy(io.github.easy4j.hermes.security.EndpointPolicy
146+
.trustedLocal("127.0.0.1", server.getPort()))
147+
.setBaseUrl("http://127.0.0.1:" + server.getPort());
148+
149+
try (HermesSseClient sse = new HermesSseClient(config, null, null)) {
150+
SseSubscription subscription =
151+
sse.subscribeRunEvents("run/alpha?x=1", ignored -> { });
152+
okhttp3.mockwebserver.RecordedRequest request =
153+
server.takeRequest(3, TimeUnit.SECONDS);
154+
assertNotNull(request);
155+
assertEquals("/v1/runs/run%2Falpha%3Fx%3D1/events", request.getPath());
156+
subscription.cancel();
157+
}
158+
}
159+
}
160+
134161
}

‎src/test/java/io/github/easy4j/hermes/security/EndpointPolicyContractTest.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.easy4j.hermes.security;
22

3+
import io.github.easy4j.hermes.HermesClient;
4+
import io.github.easy4j.hermes.HermesCliConfig;
35
import io.github.easy4j.hermes.HermesHttpClientConfig;
46
import io.github.easy4j.hermes.api.HermesHttpClient;
57
import io.github.easy4j.hermes.exception.HermesHttpException;
@@ -143,4 +145,23 @@ void testEp003S2EncodesReservedRunIdentifierAsOnePathSegment() throws Exception
143145
}
144146
}
145147

148+
149+
@Test
150+
void trustedLocalPolicySurvivesHermesClientConfigSnapshot() throws Exception {
151+
try (MockWebServer server = new MockWebServer()) {
152+
server.start();
153+
HermesHttpClientConfig config = new HermesHttpClientConfig()
154+
.setEndpointPolicy(EndpointPolicy.trustedLocal("127.0.0.1", server.getPort()))
155+
.setBaseUrl("http://127.0.0.1:" + server.getPort());
156+
HermesCliConfig cliConfig = new HermesCliConfig();
157+
cliConfig.setEnabled(false);
158+
159+
assertDoesNotThrow(() -> {
160+
try (HermesClient ignored = new HermesClient(config, cliConfig)) {
161+
// Construction is the contract: the copied config must retain the policy.
162+
}
163+
});
164+
}
165+
}
166+
146167
}

0 commit comments

Comments
 (0)