File tree Expand file tree Collapse file tree
src/test/java/io/github/easy4j/hermes/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments