diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/security/dlic/rest/api/NodesDnApiTest.java b/src/test/java/com/amazon/opendistroforelasticsearch/security/dlic/rest/api/NodesDnApiTest.java index eabc2b4f88..698f91a86e 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/security/dlic/rest/api/NodesDnApiTest.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/security/dlic/rest/api/NodesDnApiTest.java @@ -18,15 +18,18 @@ import com.amazon.opendistroforelasticsearch.security.auditlog.impl.AuditCategory; import com.amazon.opendistroforelasticsearch.security.auditlog.impl.AuditMessage; import com.amazon.opendistroforelasticsearch.security.auditlog.integration.TestAuditlogImpl; +import com.amazon.opendistroforelasticsearch.security.dlic.rest.validation.AbstractConfigurationValidator; import com.amazon.opendistroforelasticsearch.security.support.ConfigConstants; import com.amazon.opendistroforelasticsearch.security.test.helper.file.FileHelper; import com.amazon.opendistroforelasticsearch.security.test.helper.rest.RestHelper.HttpResponse; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import org.apache.http.Header; import org.apache.http.HttpStatus; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.junit.Test; import java.util.Arrays; @@ -98,6 +101,15 @@ private void testCrudScenarios(final int expectedStatus, final Header... headers assertThat(response.getBody(), response.getStatusCode(), equalTo(expectedStatus)); } + private void checkNullElementsInArray(final Header headers) throws Exception{ + + String body = FileHelper.loadFile("restapi/nodesdn_null_array_element.json"); + HttpResponse response = rh.executePutRequest("_opendistro/_security/api/nodesdn/cluster1", body, headers); + Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); + Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); + } + @Test public void testNodesDnApiWithDynamicConfigDisabled() throws Exception { setup(); @@ -139,6 +151,12 @@ public void testNodesDnApi() throws Exception { testCrudScenarios(HttpStatus.SC_OK, nonAdminCredsHeader); } + { + rh.keystore = "restapi/kirk-keystore.jks"; + rh.sendAdminCertificate = true; + checkNullElementsInArray(nonAdminCredsHeader); + } + { // any creds, admin certificate, disallowed key - FORBIDDEN rh.keystore = "restapi/kirk-keystore.jks"; @@ -195,15 +213,4 @@ public void testNodesDnApiAuditComplianceLogging() throws Exception { assertThat(actualCategoryCounts, equalTo(expectedCategoryCounts)); } - @Test - public void checkNullElementsInArray() throws Exception{ - setup(); - rh.keystore = "restapi/kirk-keystore.jks"; - rh.sendAdminCertificate = true; - - String body = FileHelper.loadFile("restapi/nodesdn_null_array_element.json"); - HttpResponse response = rh.executePutRequest("_opendistro/_security/api/nodesdn", body, new Header[0]); - Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - } - }