From eff5c14511cb32d4ed91d3472be2430e8e71621e Mon Sep 17 00:00:00 2001 From: Azar Fazel Date: Mon, 9 Aug 2021 11:35:09 -0700 Subject: [PATCH] Define a variable for expected message in checkNullElementsInArray() unit test --- .../security/dlic/rest/api/RolesApiTest.java | 13 +++++++------ .../security/dlic/rest/api/RolesMappingApiTest.java | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java index fff42682c5..a8001caba2 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java @@ -528,36 +528,37 @@ public void checkNullElementsInArray() throws Exception{ setup(); rh.keystore = "restapi/kirk-keystore.jks"; rh.sendAdminCertificate = true; + String expectedMessage = "`null` is not allowed as json array element"; 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); } } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java index 17a7453070..5909247e00 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java @@ -417,23 +417,24 @@ public void checkNullElementsInArray() throws Exception{ setup(); rh.keystore = "restapi/kirk-keystore.jks"; rh.sendAdminCertificate = true; + String expectedMessage = "`null` is not allowed as json array element"; String body = FileHelper.loadFile("restapi/rolesmapping_null_array_element_users.json"); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); 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("`null` is not allowed as json array element")); + Assert.assertTrue(response.getBody().contains(expectedMessage)); } }