From 392d41cdfc989d08cf5b79ea9a20e1f82665b447 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Wed, 26 Sep 2018 11:58:30 +0100 Subject: Implement client authentication to ElasticSearch Add configuration to the existing Elastic Search properties to allow Basic Authentication and/or TLS (SSL) connectivity using HTTPS. The new configuration is optional and this commit is intended to be backwards compatible with existing deployments. Change-Id: I19ec3da9ff810c3f6eabd6f5faf71adde182c861 Issue-ID: AAI-1650 Signed-off-by: mark.j.leonard --- .../dao/ElasticSearchHttpControllerTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java index 3cfb58a..1c75af2 100644 --- a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java +++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java @@ -1,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -29,6 +29,7 @@ import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; import java.util.Properties; +import org.eclipse.jetty.util.security.Password; import org.json.JSONObject; import org.junit.Before; import org.junit.Ignore; @@ -62,6 +63,9 @@ public class ElasticSearchHttpControllerTest { Properties properties = new Properties(); properties.put(ElasticSearchConfig.ES_IP_ADDRESS, "127.0.0.1"); properties.put(ElasticSearchConfig.ES_HTTP_PORT, "9200"); + properties.put(ElasticSearchConfig.ES_URI_SCHEME, "http"); + properties.put(ElasticSearchConfig.ES_AUTH_USER, "your_user_here"); + properties.put(ElasticSearchConfig.ES_AUTH_ENC, Password.obfuscate("your_password_here")); elasticSearch = new ElasticSearchHttpController(new ElasticSearchConfig(properties)); testDocument = new AAIEntityTestObject(); @@ -155,7 +159,12 @@ public class ElasticSearchHttpControllerTest { @Test public void testDeleteDocument() throws Exception { - OperationResult result = elasticSearch.deleteDocument(TEST_INDEX_NAME, testDocument); + OperationResult result = elasticSearch.getDocument(TEST_INDEX_NAME, testDocument); + if (result.getResultCode() == 404) { + testCreateDocument(); + } + + result = elasticSearch.deleteDocument(TEST_INDEX_NAME, testDocument); assertThat(result.getResult(), containsString(TEST_INDEX_NAME)); result = elasticSearch.getDocument(TEST_INDEX_NAME, testDocument); @@ -173,8 +182,8 @@ public class ElasticSearchHttpControllerTest { doc.setSearchTagIDs("" + i); doc.setSearchTags("service-instance-id"); - // OperationResult result = elasticSearch.createDocument(TEST_INDEX_NAME, doc, false); - // assertThat(result.getResultCode(), anyOf(equalTo(201), equalTo(400))); + OperationResult result = elasticSearch.createDocument(TEST_INDEX_NAME, doc, false); + assertThat(result.getResultCode(), anyOf(equalTo(201), equalTo(400))); } } -- cgit 1.2.3-korg