From a9960adeadce18be0672ef4033a50bda50ef417b Mon Sep 17 00:00:00 2001 From: cliu123 Date: Mon, 16 May 2022 14:04:22 -0700 Subject: [PATCH] Introduce new API _plugins/_security/ssl/certs Signed-off-by: cliu123 --- .../ssl/rest/SecuritySSLCertsInfoAction.java | 14 ++++++++------ .../ssl/SecuritySSLCertsInfoActionTests.java | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opensearch/security/ssl/rest/SecuritySSLCertsInfoAction.java b/src/main/java/org/opensearch/security/ssl/rest/SecuritySSLCertsInfoAction.java index 915f8a03e2..060504a7ce 100644 --- a/src/main/java/org/opensearch/security/ssl/rest/SecuritySSLCertsInfoAction.java +++ b/src/main/java/org/opensearch/security/ssl/rest/SecuritySSLCertsInfoAction.java @@ -18,11 +18,11 @@ import java.io.IOException; import java.security.cert.X509Certificate; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -44,16 +44,18 @@ import org.opensearch.security.user.User; import org.opensearch.threadpool.ThreadPool; +import static org.opensearch.security.dlic.rest.support.Utils.addRoutesPrefix; + /** * Rest API action to get SSL certificate information related to http and transport encryption. * Only super admin users are allowed to access this API. - * Currently this action serves GET request for _opendistro/_security/api/ssl/certs endpoint + * Currently this action serves GET request for _plugins/_security/api/ssl/certs endpoint */ public class SecuritySSLCertsInfoAction extends BaseRestHandler { - private static final List routes = Collections.singletonList( - new Route(Method.GET, "/_opendistro/_security/api/ssl/certs") - ); + private static final List routes = addRoutesPrefix(ImmutableList.of( + new Route(Method.GET, "/ssl/certs") + )); private final Logger log = LogManager.getLogger(this.getClass()); private Settings settings; @@ -82,7 +84,7 @@ public List routes() { * GET request to fetch transport certificate details * * Sample request: - * GET _opendistro/_security/api/ssl/certs + * GET _plugins/_security/api/ssl/certs * * Sample response: * { diff --git a/src/test/java/org/opensearch/security/ssl/SecuritySSLCertsInfoActionTests.java b/src/test/java/org/opensearch/security/ssl/SecuritySSLCertsInfoActionTests.java index 4151374d4e..8df6cbdc54 100644 --- a/src/test/java/org/opensearch/security/ssl/SecuritySSLCertsInfoActionTests.java +++ b/src/test/java/org/opensearch/security/ssl/SecuritySSLCertsInfoActionTests.java @@ -23,6 +23,8 @@ import net.minidev.json.JSONObject; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.opensearch.common.settings.Settings; import org.opensearch.security.ssl.util.SSLConfigConstants; @@ -31,9 +33,24 @@ import org.opensearch.security.test.helper.file.FileHelper; import org.opensearch.security.test.helper.rest.RestHelper; +import static org.opensearch.security.OpenSearchSecurityPlugin.LEGACY_OPENDISTRO_PREFIX; +import static org.opensearch.security.OpenSearchSecurityPlugin.PLUGINS_PREFIX; + +@RunWith(Parameterized.class) public class SecuritySSLCertsInfoActionTests extends SingleClusterTest { + private final String ENDPOINT; + + public SecuritySSLCertsInfoActionTests(String endpoint){ + ENDPOINT = endpoint; + } - private final String ENDPOINT = "_opendistro/_security/api/ssl/certs"; + @Parameterized.Parameters + public static Iterable endpoints() { + return ImmutableList.of( + LEGACY_OPENDISTRO_PREFIX + "/api/ssl/certs", + PLUGINS_PREFIX + "/api/ssl/certs" + ); + } private final List> NODE_CERT_DETAILS = ImmutableList.of( ImmutableMap.of(