aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node/src/test/java
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2022-12-07 10:56:27 +0000
committerefiacor <fiachra.corcoran@est.tech>2022-12-07 15:59:59 +0000
commitbda6aeaa60607ab4fe5af508156019d7bd5c0ce4 (patch)
tree24bae3847c1139ba9aed95ce286277202aae9a93 /datarouter-node/src/test/java
parentb37d32a39c7096e39fc389f15d150e8c2b8c54c2 (diff)
[DMAAP-DR] Remove AAF/TLS phase 1
Signed-off-by: efiacor <fiachra.corcoran@est.tech> Change-Id: Ifeae01dd8e7f0a737d8b74594a8061ae3d4ea647 Issue-ID: DMAAP-1642
Diffstat (limited to 'datarouter-node/src/test/java')
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java130
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java2
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java4
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java8
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServerTest.java7
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java40
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java2
7 files changed, 29 insertions, 164 deletions
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
deleted file mode 100644
index 0796aa56..00000000
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dmaap.datarouter.node;
-
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.filter.CadiFilter;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
-@PrepareForTest({CadiFilter.class})
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
-public class DRNodeCadiFilterTest {
-
- @Mock
- private PropAccess access;
-
- @Mock
- private HttpServletRequest request;
-
- @Mock
- private HttpServletResponse response;
-
- @Mock
- private FilterChain chain;
-
- private DRNodeCadiFilter cadiFilter;
-
-
- @Before
- public void setUp() throws ServletException {
- cadiFilter = new DRNodeCadiFilter(false, access);
- }
-
- @Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called()
- throws Exception {
- PowerMockito.mockStatic(NodeConfigManager.class);
- NodeConfigManager config = mock(NodeConfigManager.class);
-
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
- PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");
- when(request.getPathInfo()).thenReturn("/publish/5");
- when(request.getMethod()).thenReturn("GET");
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called()
- throws Exception {
- PowerMockito.mockStatic(NodeConfigManager.class);
- NodeConfigManager config = mock(NodeConfigManager.class);
-
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
- PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");
- when(request.getPathInfo()).thenReturn("/internal/5");
- when(request.getMethod()).thenReturn("GET");
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called()
- throws Exception {
- PowerMockito.mockStatic(NodeConfigManager.class);
- NodeConfigManager config = mock(NodeConfigManager.class);
-
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
- PowerMockito.when(config.getAafInstance("5")).thenReturn("EXISTS");
- when(request.getPathInfo()).thenReturn("/publish/5/fileId");
- when(request.getMethod()).thenReturn("GET");
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(0)).doFilter(request, response);
- }
-
- @Test
- public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter()
- throws Exception {
- PowerMockito.mockStatic(NodeConfigManager.class);
- NodeConfigManager config = mock(NodeConfigManager.class);
-
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
- when(request.getPathInfo()).thenReturn("/publish/5");
- when(request.getMethod()).thenReturn("DELETE");
- doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND,
- "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
index fa4966c9..d1194279 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
@@ -68,7 +68,7 @@ public class DeliveryQueueTest {
when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
NodeConfigManager configManager = mockNodeConfigManager();
- FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", configManager, true);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", configManager, true);
}
@Test
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
index 7eacd838..cb3c88a4 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
@@ -55,7 +55,6 @@ public class LogManagerTest {
@Before
public void setUp() throws IllegalAccessException {
mockNodeConfigManager();
- FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", config, true);
logManager = new LogManager(config);
}
@@ -94,7 +93,7 @@ public class LogManagerTest {
assertNull(worker.getFeedId(""));
}
- private void mockNodeConfigManager() {
+ private void mockNodeConfigManager() throws IllegalAccessException {
PowerMockito.when(config.getLogDir()).thenReturn(System.getProperty("user.dir") + "/src/test/resources");
PowerMockito.when(config.getTimer()).thenReturn(new Timer("Node Configuration Timer", true));
PowerMockito.when(config.getEventLogPrefix())
@@ -104,6 +103,7 @@ public class LogManagerTest {
PowerMockito.when(config.getEventLogInterval()).thenReturn("30s");
PowerMockito.when(config.getPublishId()).thenReturn("123456789.dmaap-dr-node");
PowerMockito.when(config.getEventLogUrl()).thenReturn("https://dmaap-dr-prov:8443/internal/logs");
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java
index 82038fba..046a56e2 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java
@@ -47,7 +47,9 @@ import org.junit.Test;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.NodeConfigManager"})
@PowerMockIgnore({"javax.net.ssl.*", "javax.security.auth.x500.X500Principal", "javax.crypto.*"})
@PrepareForTest({InetAddress.class})
public class NodeConfigManagerTest {
@@ -75,7 +77,6 @@ public class NodeConfigManagerTest {
String href = "https://dmaap-dr-prov:8443/internal/prov";
URLConnection urlConnection = mock(URLConnection.class);
httpUrlStreamHandler.addConnection(new URL(href), urlConnection);
- //File prov = new File("src/test/resources/prov_data.json");
InputStream anyInputStream = new ByteArrayInputStream(Files.readAllBytes(Paths.get("src/test/resources/prov_data.json")));
when(urlConnection.getInputStream()).thenReturn(anyInputStream);
}
@@ -92,7 +93,7 @@ public class NodeConfigManagerTest {
}
@Test
- public void Verify_NodeConfigMan_Getters() {
+ public void Verify_NodeConfigMan_Getters_Secure() {
NodeConfigManager nodeConfigManager = NodeConfigManager.getInstance();
Assert.assertEquals("legacy", nodeConfigManager.getAafInstance());
Assert.assertEquals("src/test/resources/spool/f", nodeConfigManager.getSpoolDir());
@@ -110,11 +111,10 @@ public class NodeConfigManagerTest {
Assert.assertEquals(new String[] {"TLSv1.1", "TLSv1.2"}, nodeConfigManager.getEnabledprotocols());
Assert.assertEquals("org.onap.dmaap-dr.feed", nodeConfigManager.getAafType());
Assert.assertEquals("publish", nodeConfigManager.getAafAction());
- Assert.assertFalse(nodeConfigManager.getCadiEnabled());
+ Assert.assertTrue(nodeConfigManager.getCadiEnabled());
Assert.assertFalse(nodeConfigManager.isShutdown());
Assert.assertTrue(nodeConfigManager.isTlsEnabled());
Assert.assertTrue(nodeConfigManager.isConfigured());
- Assert.assertEquals("legacy", nodeConfigManager.getAafInstance("1"));
Assert.assertNotNull(nodeConfigManager.getPublishId());
Assert.assertNotNull(nodeConfigManager.getAllDests());
Assert.assertEquals(10000, nodeConfigManager.getInitFailureTimer());
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServerTest.java
index 153753e9..af43e5d8 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServerTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServerTest.java
@@ -43,7 +43,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class NodeServerTest {
- private NodeConfigManager config = mock(NodeConfigManager.class);
+ private final NodeConfigManager config = mock(NodeConfigManager.class);
@Before
public void setUp() throws Exception {
setUpConfig();
@@ -58,7 +58,7 @@ public class NodeServerTest {
@Test
public void Verify_Node_Server_Is_Configured_Correctly() {
- Assert.assertNotNull(NodeServer.getServerInstance());
+ Assert.assertNotNull(NodeServer.getServerInstance(config));
}
private void setUpConfig() throws IllegalAccessException {
@@ -73,14 +73,13 @@ public class NodeServerTest {
when(config.getEventLogInterval()).thenReturn("40");
when(config.isDeletePermitted("1")).thenReturn(true);
when(config.getAllDests()).thenReturn(new DestInfo[0]);
+ when(config.isTlsEnabled()).thenReturn(true);
when(config.getKSType()).thenReturn("PKCS12");
when(config.getKSFile()).thenReturn("src/test/resources/aaf/org.onap.dmaap-dr.p12");
when(config.getKSPass()).thenReturn("tVac2#@Stx%tIOE^x[c&2fgZ");
when(config.getTstype()).thenReturn("jks");
when(config.getTsfile()).thenReturn("src/test/resources/aaf/org.onap.dmaap-dr.trust.jks");
when(config.getTspass()).thenReturn("XHX$2Vl?Lk*2CB.i1+ZFAhZd");
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
- FieldUtils.writeDeclaredStaticField(NodeRunner.class, "nodeConfigManager", config, true);
PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
index f7e3d7c8..0dcc0a19 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
@@ -23,6 +23,8 @@
package org.onap.dmaap.datarouter.node;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyString;
@@ -41,22 +43,27 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.BDDMockito;
import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.internal.matchers.Any;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.LoggerFactory;
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
+@PrepareForTest(NodeServer.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
public class NodeServletTest {
@@ -84,7 +91,8 @@ public class NodeServletTest {
setUpNodeMainDelivery();
delivery = mock(Delivery.class);
when(delivery.markTaskSuccess("spool/s/0/1", "dmaap-dr-node.1234567")).thenReturn(true);
- nodeServlet = new NodeServlet(delivery);
+ PowerMockito.mockStatic(NodeServer.class);
+ nodeServlet = new NodeServlet(delivery, config);
when(request.getHeader("Authorization")).thenReturn("User1");
when(request.getHeader("X-DMAAP-DR-PUBLISH-ID")).thenReturn("User1");
}
@@ -332,31 +340,23 @@ public class NodeServletTest {
when(config.getEventLogInterval()).thenReturn("40");
when(config.isDeletePermitted("1")).thenReturn(true);
when(config.getAllDests()).thenReturn(new DestInfo[0]);
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
- FieldUtils.writeDeclaredStaticField(NodeRunner.class, "nodeConfigManager", config, true);
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
private void setUpConfigToReturnUnprivilegedSubscriber() throws IllegalAccessException {
- NodeConfigManager config = mock(NodeConfigManager.class);
PowerMockito.mockStatic(NodeConfigManager.class);
when(config.isShutdown()).thenReturn(false);
when(config.isConfigured()).thenReturn(true);
when(config.isDeletePermitted("1")).thenReturn(false);
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
- FieldUtils.writeDeclaredStaticField(NodeRunner.class, "nodeConfigManager", config, true);
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
private void setUpConfigToReturnNullOnIsDeletePermitted() throws IllegalAccessException {
- NodeConfigManager config = mock(NodeConfigManager.class);
PowerMockito.mockStatic(NodeConfigManager.class);
when(config.isShutdown()).thenReturn(false);
when(config.isConfigured()).thenReturn(true);
when(config.isDeletePermitted("1")).thenThrow(new NullPointerException());
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
- FieldUtils.writeDeclaredStaticField(NodeRunner.class, "nodeConfigManager", config, true);
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
private void setUpNodeMainDelivery() throws IllegalAccessException{
@@ -365,14 +365,12 @@ public class NodeServletTest {
FieldUtils.writeDeclaredStaticField(NodeServer.class, "delivery", delivery, true);
}
- private void setNodeConfigManagerIsConfiguredToReturnFalse() throws IllegalAccessException{
- NodeConfigManager config = mock(NodeConfigManager.class);
+ private void setNodeConfigManagerIsConfiguredToReturnFalse() throws IllegalAccessException {
when(config.isConfigured()).thenReturn(false);
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
private void setNodeConfigManagerIsPublishPermittedToReturnAReason() throws IllegalAccessException{
- NodeConfigManager config = mock(NodeConfigManager.class);
when(config.isShutdown()).thenReturn(false);
when(config.getMyName()).thenReturn("dmaap-dr-node");
when(config.isConfigured()).thenReturn(true);
@@ -380,11 +378,10 @@ public class NodeServletTest {
when(config.getLogDir()).thenReturn("log/dir");
when(config.isPublishPermitted(anyString(), anyString(), anyString())).thenReturn("Publisher not permitted for this feed");
when(config.isAnotherNode(anyString(), anyString())).thenReturn(false);
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ FieldUtils.writeDeclaredStaticField(NodeConfigManager.class, "base", config, true);
}
- private void setNodeConfigManagerToAllowRedirectOnIngressNode() throws IllegalAccessException{
- NodeConfigManager config = mock(NodeConfigManager.class);
+ private void setNodeConfigManagerToAllowRedirectOnIngressNode() {
when(config.isShutdown()).thenReturn(false);
when(config.isConfigured()).thenReturn(true);
when(config.getSpoolDir()).thenReturn("spool/dir");
@@ -394,7 +391,6 @@ public class NodeServletTest {
when(config.getAuthUser(anyString(), anyString())).thenReturn("User1");
when(config.getIngressNode(anyString(), anyString(), anyString())).thenReturn("NewNode");
when(config.getExtHttpsPort()).thenReturn(8080);
- FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
}
private String createLargeMetaDataString() {
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
index f3d14df7..40cb11fb 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
@@ -24,7 +24,7 @@ package org.onap.dmaap.datarouter.node;
import static org.mockito.Mockito.when;
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;