aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChengkai Yan <martin.c.yan@est.tech>2018-10-29 12:57:47 +0100
committerChengkai Yan <martin.c.yan@est.tech>2018-11-01 14:06:09 +0100
commitcf1221cac89cc3310017d6c72ee0638ddec24cea (patch)
tree7e56bddf2827dbd7f0c4a1de90179c0f907eeae8
parentf964ebd72b28c29d2b00cf09803e2076996376fe (diff)
Add test for FtpsClient, Improve code coverage.
Fix a security vulnerability risk Change-Id: I71560dfd9977a7e96ac4441e468602b616c7e7a6 Issue-ID: DCAEGEN2-889 Signed-off-by: Chengkai Yan <martin.c.yan@est.tech>
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java2
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java57
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java22
-rw-r--r--pom.xml4
4 files changed, 82 insertions, 3 deletions
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
index c5962172..9b6eacb0 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
@@ -44,6 +44,6 @@ public class FileCollectResult {
@Override
public String toString() {
- return "Download successful: " + result + " Error data: " + getErrorData();
+ return "FileCollectResult: " + result + " Error data: " + getErrorData();
}
}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java
new file mode 100644
index 00000000..e40d7d78
--- /dev/null
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
+ * ===============================================================================================
+ * 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.
+ * ============LICENSE_END========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ErrorDataTest {
+ private List<String> errorMessages = new ArrayList<>();
+ private List<Throwable> errorCauses = new ArrayList<>();
+ private ErrorData errorData = new ErrorData();
+
+ @BeforeEach
+ protected void setUp() {
+ int testSize = 3;
+ for (int i = 0; i < testSize; i++) {
+ errorMessages.add("test");
+ errorCauses.add(mock(Throwable.class));
+ }
+ for (int i = 0; i < testSize; i++) {
+ errorData.addError(errorMessages.get(i), errorCauses.get(i));
+ }
+ }
+
+ public String getMessageAsString() {
+ StringBuilder message = new StringBuilder();
+ for (int i = 0; i < errorMessages.size(); i++) {
+ message.append(errorMessages.get(i)).append(" Cause: ").append(errorCauses.get(i)).append("\n");
+ }
+ return message.toString();
+ }
+
+ @Test
+ public void testToString_returnExpectedString() {
+ Assertions.assertEquals(getMessageAsString(), errorData.toString());
+ }
+}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
index e5693d50..66d3b00c 100644
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
@@ -233,4 +233,26 @@ public class FtpsClientTest {
assertFalse(result.downloadSuccessful());
verify(localFileMock, times(1)).delete();
}
+
+ @Test
+ public void collectFileFailingFileRetrieve_shouldFail() throws Exception {
+ when(keyManagerUtilsMock.getClientKeyManager()).thenReturn(keyManagerMock);
+ when(fileResourceMock.getInputStream()).thenReturn(inputStreamMock);
+ when(keyStoreWrapperMock.getKeyStore()).thenReturn(keyStoreMock);
+ when(trustManagerFactoryMock.getTrustManagers()).thenReturn(new TrustManager[] {trustManagerMock});
+ when(ftpsClientMock.login(USERNAME, PASSWORD)).thenReturn(true);
+ when(ftpsClientMock.getReplyCode()).thenReturn(HttpStatus.OK.value());
+ File fileMock = mock(File.class);
+ when(localFileMock.getFile()).thenReturn(fileMock);
+ OutputStream osMock = mock(OutputStream.class);
+ when(outputStreamMock.getOutputStream(fileMock)).thenReturn(osMock);
+ when(ftpsClientMock.retrieveFile(REMOTE_FILE_PATH, osMock)).thenReturn(false);
+
+ ImmutableFileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS)
+ .userId(USERNAME).password(PASSWORD).port(PORT).build();
+
+ FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
+
+ assertFalse(result.downloadSuccessful());
+ }
} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 51b1ab44..5af67d60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
<immutable.version>2.7.1</immutable.version>
<spring.version>5.1.0.RELEASE</spring.version>
<spring-boot.version>2.1.0.M4</spring-boot.version>
- <tomcat.version>8.5.32</tomcat.version>
+ <tomcat.version>8.5.34</tomcat.version>
<docker.maven.version>1.0.0</docker.maven.version>
<resource.maven.plugin.version>3.1.0</resource.maven.plugin.version>
@@ -271,7 +271,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>2.16.0</version>
+ <version>2.23.0</version>
<scope>test</scope>
</dependency>
<dependency>