Skip to content

Commit

Permalink
Use ErrorType.NULL_ARRAY_ELEMENT in checkNullElementsInArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
afazel committed Aug 10, 2021
1 parent e0fc3f1 commit 822bf31
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
import org.junit.Test;

import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator;
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
import org.opensearch.security.test.helper.file.FileHelper;
import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse;
import com.google.common.collect.ImmutableList;

import static org.opensearch.security.dlic.rest.api.RolesApiTest.EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG;

@RunWith(Parameterized.class)
public class ActionGroupsApiTest extends AbstractRestApiUnitTest {

Expand Down Expand Up @@ -387,6 +386,6 @@ public void checkNullElementsInArray() throws Exception{
String body = FileHelper.loadFile("restapi/actiongroup_null_array_element.json");
HttpResponse response = rh.executePutRequest(ENDPOINT + "/CRUD_UT", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.runners.Parameterized;
import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse;
import org.opensearch.security.test.helper.file.FileHelper;
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;

import java.util.Arrays;
import java.util.List;
Expand All @@ -40,7 +41,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.opensearch.security.dlic.rest.api.RolesApiTest.EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG;


@RunWith(Parameterized.class)
public class NodesDnApiTest extends AbstractRestApiUnitTest {
Expand Down Expand Up @@ -123,7 +124,7 @@ private void checkNullElementsInArray(final Header headers) throws Exception{
String body = FileHelper.loadFile("restapi/nodesdn_null_array_element.json");
HttpResponse response = rh.executePutRequest(ENDPOINT + "/nodesdn/cluster1", body, headers);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
@RunWith(Parameterized.class)
public class RolesApiTest extends AbstractRestApiUnitTest {

public final static String EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG = "`null` is not allowed as json array element";
private final String ENDPOINT;

public RolesApiTest(String endpoint){
Expand Down Expand Up @@ -533,32 +532,32 @@ public void checkNullElementsInArray() throws Exception{
String body = FileHelper.loadFile("restapi/roles_null_array_element_cluster_permissions.json");
HttpResponse response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/roles_null_array_element_index_permissions.json");
response = rh.executePutRequest(ENDPOINT+ "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/roles_null_array_element_tenant_permissions.json");
response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/roles_null_array_element_index_patterns.json");
response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/roles_null_array_element_masked_fields.json");
response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/roles_null_array_element_allowed_actions.json");
response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
import org.junit.runners.Parameterized;

import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator;
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
import org.opensearch.security.test.helper.file.FileHelper;
import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse;
import com.google.common.collect.ImmutableList;

import static org.opensearch.security.dlic.rest.api.RolesApiTest.EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG;

@RunWith(Parameterized.class)
public class RolesMappingApiTest extends AbstractRestApiUnitTest {

Expand Down Expand Up @@ -424,18 +423,18 @@ public void checkNullElementsInArray() throws Exception{
HttpResponse response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains",
body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/rolesmapping_null_array_element_backend_roles.json");
response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains",
body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));

body = FileHelper.loadFile("restapi/rolesmapping_null_array_element_hosts.json");
response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains",
body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.opensearch.security.dlic.rest.api;

import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator;
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.security.test.helper.file.FileHelper;
Expand All @@ -34,8 +35,6 @@
import com.google.common.collect.ImmutableList;
import java.util.List;

import static org.opensearch.security.dlic.rest.api.RolesApiTest.EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG;

@RunWith(Parameterized.class)
public class UserApiTest extends AbstractRestApiUnitTest {

Expand Down Expand Up @@ -649,7 +648,7 @@ public void checkNullElementsInArray() throws Exception{
String body = FileHelper.loadFile("restapi/users_null_array_element.json");
HttpResponse response = rh.executePutRequest(ENDPOINT + "/internalusers/picard", body, new Header[0]);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
Assert.assertTrue(response.getBody().contains(EXPECTED_NULL_ELEMENT_IN_ARRAY_MSG));
Assert.assertTrue(response.getBody().contains((ErrorType.NULL_ARRAY_ELEMENT).toString()));
}

}

0 comments on commit 822bf31

Please sign in to comment.