3030import org .opensearch .test .framework .cluster .LocalOpenSearchCluster ;
3131import org .opensearch .test .framework .cluster .TestRestClient ;
3232
33- import static junit .framework .TestCase .fail ;
3433import static org .hamcrest .CoreMatchers .containsString ;
3534import static org .hamcrest .CoreMatchers .is ;
3635import static org .hamcrest .MatcherAssert .assertThat ;
3736import static org .opensearch .security .OpenSearchSecurityPlugin .PLUGINS_PREFIX ;
3837import static org .opensearch .security .dlic .rest .api .RestApiAdminPrivilegesEvaluator .CERTS_INFO_ACTION ;
3938import static org .opensearch .security .support .ConfigConstants .SECURITY_RESTAPI_ADMIN_ENABLED ;
39+ import static junit .framework .TestCase .fail ;
4040
4141public class CertificatesRestApiIntegrationTest extends AbstractApiIntegrationTest {
4242 final static String REST_API_ADMIN_SSL_INFO = "rest-api-admin-ssl-info" ;
@@ -88,7 +88,11 @@ public void forbiddenForAdminUser() throws Exception {
8888
8989 @ Test
9090 public void availableForTlsAdmin () throws Exception {
91- withUser (ADMIN_USER_NAME , localCluster .getAdminCertificate (), verifySSLCertsInfo (List .of (CertType .HTTP , CertType .TRANSPORT , CertType .TRANSPORT_CLIENT )));
91+ withUser (
92+ ADMIN_USER_NAME ,
93+ localCluster .getAdminCertificate (),
94+ verifySSLCertsInfo (List .of (CertType .HTTP , CertType .TRANSPORT , CertType .TRANSPORT_CLIENT ))
95+ );
9296 }
9397
9498 @ Test
@@ -112,14 +116,16 @@ private CheckedConsumer<TestRestClient, Exception> verifySSLCertsInfo(List<CertT
112116 assertSSLCertsInfo (localCluster .nodes (), expectCerts , ok (() -> testRestClient .get (sslCertsPath ())));
113117 if (localCluster .nodes ().size () > 1 ) {
114118 final var randomNodes = randomNodes ();
115- final var nodeIds = randomNodes .stream ().map (n -> n .esNode ().getNodeEnvironment ().nodeId ()).collect (Collectors .joining ("," ));
119+ final var nodeIds = randomNodes .stream ()
120+ .map (n -> n .esNode ().getNodeEnvironment ().nodeId ())
121+ .collect (Collectors .joining ("," ));
116122 assertSSLCertsInfo (randomNodes , expectCerts , ok (() -> testRestClient .get (sslCertsPath (nodeIds ))));
117123 }
118124 final var randomCertType = randomFrom (expectCerts );
119125 assertSSLCertsInfo (
120- localCluster .nodes (),
121- List .of (randomCertType ),
122- ok (() -> testRestClient .get (String .format ("%s?cert_type=%s" , sslCertsPath (), randomCertType )))
126+ localCluster .nodes (),
127+ List .of (randomCertType ),
128+ ok (() -> testRestClient .get (String .format ("%s?cert_type=%s" , sslCertsPath (), randomCertType )))
123129 );
124130 } catch (Exception e ) {
125131 fail ("Verify SSLCerts info failed with exception: " + e .getMessage ());
@@ -161,22 +167,18 @@ private void assertSSLCertsInfo(
161167
162168 private void verifyCertsJson (final int nodeNumber , final JsonNode jsonNode ) {
163169 if (jsonNode .get ("subject_dn" ).asText ().contains (ROOT_CA )) { // handle root cert
164- assertThat (
165- jsonNode .toPrettyString (),
166- jsonNode .get ("subject_dn" ).asText (),
167- is (TestCertificates .CA_SUBJECT )
168- );
170+ assertThat (jsonNode .toPrettyString (), jsonNode .get ("subject_dn" ).asText (), is (TestCertificates .CA_SUBJECT ));
169171 assertThat (jsonNode .toPrettyString (), jsonNode .get ("san" ).asText ().isEmpty ());
170172 } else { // handle non-root
171173 assertThat (
172- jsonNode .toPrettyString (),
173- jsonNode .get ("subject_dn" ).asText (),
174- is (String .format (TestCertificates .NODE_SUBJECT_PATTERN , nodeNumber ))
174+ jsonNode .toPrettyString (),
175+ jsonNode .get ("subject_dn" ).asText (),
176+ is (String .format (TestCertificates .NODE_SUBJECT_PATTERN , nodeNumber ))
175177 );
176178 assertThat (
177- jsonNode .toPrettyString (),
178- jsonNode .get ("san" ).asText (),
179- containsString (String .format ("node-%s.example.com" , nodeNumber ))
179+ jsonNode .toPrettyString (),
180+ jsonNode .get ("san" ).asText (),
181+ containsString (String .format ("node-%s.example.com" , nodeNumber ))
180182 );
181183 }
182184 assertThat (jsonNode .toPrettyString (), jsonNode .get ("issuer_dn" ).asText (), is (TestCertificates .CA_SUBJECT ));
0 commit comments