diff options
author | Tomasz Wrobel <tomasz.wrobel@nokia.com> | 2021-03-18 15:03:51 +0100 |
---|---|---|
committer | Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com> | 2021-03-19 08:54:08 +0000 |
commit | 92c83fe593132a522cb26a872d94612373e46315 (patch) | |
tree | be8cb71d333a3b6ba7d19b26015463e5ed6e3e2c /src/test | |
parent | 6df36c389d23a73f46fafb8cc1b70e510bdfbaeb (diff) |
Fix sonar issues
-Fix thread interrupt bug
-Fix security vulnerabilities
Issue-ID: SDC-3185
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Change-Id: I0e32215a6de9e04a26acfad580701b36278270b0
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/onap/sdc/helmvalidator/helm/validation/FileManagerTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/java/org/onap/sdc/helmvalidator/helm/validation/FileManagerTest.java b/src/test/java/org/onap/sdc/helmvalidator/helm/validation/FileManagerTest.java index 2d05cd9..89eab80 100644 --- a/src/test/java/org/onap/sdc/helmvalidator/helm/validation/FileManagerTest.java +++ b/src/test/java/org/onap/sdc/helmvalidator/helm/validation/FileManagerTest.java @@ -21,6 +21,7 @@ package org.onap.sdc.helmvalidator.helm.validation; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; @@ -37,6 +38,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.sdc.helmvalidator.helm.validation.exception.SaveFileException; import org.springframework.web.multipart.MultipartFile; @ExtendWith(MockitoExtension.class) @@ -93,6 +95,23 @@ class FileManagerTest { assertThat(Files.exists(Paths.get(filePath))).isFalse(); } + @Test + void shouldThrowExceptionWhenFileContainsSlash() { + when(multipartFile.getOriginalFilename()).thenReturn(SAMPLE_FILE_NAME + "/"); + Exception exception = assertThrows(SaveFileException.class, + () -> fileManager.saveFile(multipartFile)); + assertThat(exception).hasMessageContaining("Not allowed file name"); + } + + @Test + void shouldThrowExceptionWhenFileNameIsNull() { + when(multipartFile.getOriginalFilename()).thenReturn(null); + + Exception exception = assertThrows(SaveFileException.class, + () -> fileManager.saveFile(multipartFile)); + assertThat(exception).hasMessageContaining("Not allowed file name"); + } + private void mockMultipartFile() throws IOException { when(multipartFile.getOriginalFilename()).thenReturn(SAMPLE_FILE_NAME); when(multipartFile.getInputStream()).thenReturn(TEST_INPUT_STREAM); |