Skip to content

Commit fa769f6

Browse files
committed
test(profile): reject root credential fallback
1 parent c2de075 commit fa769f6

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.github.easy4j.hermes.security;
2+
3+
import io.github.easy4j.hermes.HermesCliConfig;
4+
import io.github.easy4j.hermes.HermesClient;
5+
import io.github.easy4j.hermes.HermesHttpClientConfig;
6+
import okhttp3.mockwebserver.MockWebServer;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertThrows;
11+
12+
class ProfileAuthenticationContractTest {
13+
14+
@Test
15+
void missingNamedProfileCredentialDoesNotBorrowRootApiKey() throws Exception {
16+
try (MockWebServer server = new MockWebServer()) {
17+
server.start();
18+
19+
HermesHttpClientConfig http = new HermesHttpClientConfig()
20+
.setEndpointPolicy(EndpointPolicy.trustedLocal("127.0.0.1", server.getPort()))
21+
.setBaseUrl("http://127.0.0.1:" + server.getPort());
22+
http.setApiKey("root-secret");
23+
24+
HermesCliConfig cli = new HermesCliConfig();
25+
cli.setEnabled(false);
26+
27+
try (HermesClient root = new HermesClient(http, cli)) {
28+
assertThrows(IllegalStateException.class, () -> root.forProfile("team-a"));
29+
assertEquals(0, server.getRequestCount(),
30+
"missing profile credentials must fail before any request is sent");
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)