Skip to content
Snippets Groups Projects
Commit 42ad11cf authored by Jan Zickermann's avatar Jan Zickermann
Browse files

Merge remote-tracking branch...

Merge remote-tracking branch 'origin/OZG-5413-Senden-OD-Mantelantrag-an-AFM-Eingangsstelle-via-NB' into OZG-5413-Senden-OD-Mantelantrag-an-AFM-Eingangsstelle-via-NB
parents b26d9ca6 4ecf9672
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ package de.ozgcloud.eingang.common.zip; ...@@ -25,6 +25,7 @@ package de.ozgcloud.eingang.common.zip;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -42,6 +43,7 @@ import java.util.zip.ZipInputStream; ...@@ -42,6 +43,7 @@ import java.util.zip.ZipInputStream;
import org.springframework.util.MimeTypeUtils; import org.springframework.util.MimeTypeUtils;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException; import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.DeleteOnCloseInputStream;
import de.ozgcloud.eingang.common.formdata.IncomingFile; import de.ozgcloud.eingang.common.formdata.IncomingFile;
import lombok.Getter; import lombok.Getter;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -212,10 +214,27 @@ public class ZipAttachmentReader { ...@@ -212,10 +214,27 @@ public class ZipAttachmentReader {
.build(); .build();
} }
@Deprecated
public InputStream getSourceZipAsStream() {
try {
return new DeleteOnCloseInputStream(sourceZipFile);
} catch (FileNotFoundException e) {
throw new TechnicalException("Original ZIP was deleted", e);
}
}
public File getSourceZip() { public File getSourceZip() {
return sourceZipFile; return sourceZipFile;
} }
public long getSourceFileSize() {
try {
return Files.size(sourceZipFile.toPath());
} catch (IOException e) {
throw new TechnicalException("Cannot get size of source ZIP.", e);
}
}
String getContentType(String name) { String getContentType(String name) {
Objects.requireNonNull(name); Objects.requireNonNull(name);
return Objects.requireNonNullElse(URLConnection.guessContentTypeFromName(name), MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE); return Objects.requireNonNullElse(URLConnection.guessContentTypeFromName(name), MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE);
......
...@@ -33,7 +33,6 @@ import java.nio.file.Files; ...@@ -33,7 +33,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.zip.ZipException; import java.util.zip.ZipException;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
...@@ -47,7 +46,6 @@ import org.mockito.Spy; ...@@ -47,7 +46,6 @@ import org.mockito.Spy;
import org.springframework.util.MimeTypeUtils; import org.springframework.util.MimeTypeUtils;
import de.ozgcloud.common.test.TestUtils; import de.ozgcloud.common.test.TestUtils;
import de.ozgcloud.eingang.common.formdata.DeleteOnCloseInputStream;
import de.ozgcloud.eingang.common.formdata.IncomingFile; import de.ozgcloud.eingang.common.formdata.IncomingFile;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -75,11 +73,20 @@ class ZipAttachmentReaderTest { ...@@ -75,11 +73,20 @@ class ZipAttachmentReaderTest {
@SneakyThrows @SneakyThrows
private void verifySourceFileSavedInTmpDirectory() { private void verifySourceFileSavedInTmpDirectory() {
try (Stream<Path> paths = Files.find(Path.of(getTmpDirectoryPath()), 1, List<Path> foundFiles = Files.find(Path.of(getTmpDirectoryPath()), 1,
((path, basicFileAttributes) -> path.getFileName().toString().startsWith(ZipAttachmentReader.SOURCE_ZIP_PREFIX)))) { ((path, basicFileAttributes) -> path.getFileName().toString().startsWith(ZipAttachmentReader.SOURCE_ZIP_PREFIX)))
List<Path> foundFiles = paths.toList(); .toList();
assertThat(foundFiles).hasSize(1); assertThat(foundFiles).hasSize(1).first();
} }
@Test
@DisplayName("should return readable input stream for source zip file")
void shouldReturnSourceStream() {
var expectedContent = TestUtils.loadFile(ZIP_1_FILE_NAME);
var sourceZipAsStream = createZipAttachment(ZIP_1_FILE_NAME).getSourceZipAsStream();
assertThat(sourceZipAsStream).hasSameContentAs(expectedContent);
} }
@Test @Test
...@@ -128,7 +135,7 @@ class ZipAttachmentReaderTest { ...@@ -128,7 +135,7 @@ class ZipAttachmentReaderTest {
var attachmentContentList = new ZipAttachmentReader().readContent(loadZip(ZIP_1_FILE_NAME)); var attachmentContentList = new ZipAttachmentReader().readContent(loadZip(ZIP_1_FILE_NAME));
assertThat(attachmentContentList).hasSize(1); assertThat(attachmentContentList).hasSize(1);
var contentEntry = attachmentContentList.getFirst(); var contentEntry = attachmentContentList.get(0);
assertThat(contentEntry.getName()).isEqualTo(content_file_0_name); assertThat(contentEntry.getName()).isEqualTo(content_file_0_name);
assertThat(contentEntry.getSize()).isEqualTo(content_file_0_size); assertThat(contentEntry.getSize()).isEqualTo(content_file_0_size);
assertThat(contentEntry.getContentStream()).hasSameContentAs(TestUtils.loadFile(content_file_0_name)); assertThat(contentEntry.getContentStream()).hasSameContentAs(TestUtils.loadFile(content_file_0_name));
...@@ -162,7 +169,6 @@ class ZipAttachmentReaderTest { ...@@ -162,7 +169,6 @@ class ZipAttachmentReaderTest {
entry.getContentStreamForFinalRead().close(); entry.getContentStreamForFinalRead().close();
} }
@SneakyThrows
@Test @Test
@DisplayName("should return readable input stream for source zip if cannot extract content") @DisplayName("should return readable input stream for source zip if cannot extract content")
void shouldReturnSourceStreamByError() { void shouldReturnSourceStreamByError() {
...@@ -171,7 +177,7 @@ class ZipAttachmentReaderTest { ...@@ -171,7 +177,7 @@ class ZipAttachmentReaderTest {
assertThrows(ReadZipException.class, attachment::readContent); assertThrows(ReadZipException.class, attachment::readContent);
assertThat(new DeleteOnCloseInputStream(attachment.getSourceZip())).hasSameContentAs(new ByteArrayInputStream(attachmentContent)); assertThat(attachment.getSourceZipAsStream()).hasSameContentAs(new ByteArrayInputStream(attachmentContent));
} }
@Test @Test
...@@ -204,37 +210,32 @@ class ZipAttachmentReaderTest { ...@@ -204,37 +210,32 @@ class ZipAttachmentReaderTest {
private static final String ZIP_BOMB_WITH_MANY_FILES = "zipbombs/filewithmanyfiles.dat.zip"; private static final String ZIP_BOMB_WITH_MANY_FILES = "zipbombs/filewithmanyfiles.dat.zip";
@Test @Test
@SneakyThrows
void shouldFailOnExtremCompressionRatio() { void shouldFailOnExtremCompressionRatio() {
try (var zip = loadZip(ZIP_BOMB_WITH_BIG_NULL_FILE_CONTENT)) { var zip = loadZip(ZIP_BOMB_WITH_BIG_NULL_FILE_CONTENT);
ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip)); ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip));
assertThat(exception.getMessage()).contains("Ratio between compressed and uncompressed data is highly suspicious"); assertThat(exception.getMessage()).contains("Ratio between compressed and uncompressed data is highly suspicious");
} }
}
@Test @Test
@SneakyThrows @SneakyThrows
void shouldFailOnTotalExtractedSize() { void shouldFailOnTotalExtractedSize() {
try (var zip = loadZip(ZIP_1_FILE_NAME)) { var zip = loadZip(ZIP_1_FILE_NAME);
reader.readContent(zip); reader.readContent(zip);
verify(reader).checkTotalExtractedSize(157); verify(reader).checkTotalExtractedSize(157);
} }
}
@Test @Test
@SneakyThrows
void shouldFailOnTotalZipEntries() { void shouldFailOnTotalZipEntries() {
try (var zip = loadZip(ZIP_BOMB_WITH_MANY_FILES)) { var zip = loadZip(ZIP_BOMB_WITH_MANY_FILES);
ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip)); ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip));
assertThat(exception.getMessage()).contains("Total entries in zip file exceeded"); assertThat(exception.getMessage()).contains("Total entries in zip file exceeded");
} }
} }
}
@Nested @Nested
class TestSaveFiles { class TestSaveFiles {
...@@ -299,16 +300,12 @@ class ZipAttachmentReaderTest { ...@@ -299,16 +300,12 @@ class ZipAttachmentReaderTest {
@SneakyThrows @SneakyThrows
private static void cleanupTempFiles() { private static void cleanupTempFiles() {
try (Stream<Path> paths = Files.walk(Path.of(TMP_DIRECTORY_PATH), 1)) { Files.walk(Path.of(TMP_DIRECTORY_PATH), 1).filter(hasNameSuffix).map(Path::toFile).forEach(File::delete);
paths.filter(hasNameSuffix).map(Path::toFile).forEach(File::delete);
}
} }
@SneakyThrows @SneakyThrows
private static boolean noFilesWithSuffixInTempDirectory() { private static boolean noFilesWithSuffixInTempDirectory() {
try (Stream<Path> paths = Files.walk(Path.of(TMP_DIRECTORY_PATH), 1)) { return Files.walk(Path.of(TMP_DIRECTORY_PATH), 1).noneMatch(hasNameSuffix);
return paths.noneMatch(hasNameSuffix);
}
} }
@SneakyThrows @SneakyThrows
......
...@@ -11,7 +11,7 @@ import java.security.cert.CertificateException; ...@@ -11,7 +11,7 @@ import java.security.cert.CertificateException;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer; import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -28,12 +28,12 @@ import lombok.extern.log4j.Log4j2; ...@@ -28,12 +28,12 @@ import lombok.extern.log4j.Log4j2;
@Log4j2 @Log4j2
@Configuration @Configuration
@RequiredArgsConstructor
public class XtaRemoteServiceConfiguration { public class XtaRemoteServiceConfiguration {
static final String URI_TEMPLATE = "%s://%s/MB_XTA-WS/XTA210msgBoxPort.svc"; static final String URI_TEMPLATE = "%s://%s/MB_XTA-WS/XTA210msgBoxPort.svc";
private final XtaProperties properties; @Autowired
private XtaProperties properties;
@Bean @Bean
Jaxb2Marshaller osciTransportMarshaller() { Jaxb2Marshaller osciTransportMarshaller() {
......
package de.ozgcloud.eingang.xta; package de.ozgcloud.eingang.xta;
import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
...@@ -11,15 +11,15 @@ import de.ozgcloud.eingang.semantik.SemantikAdapter; ...@@ -11,15 +11,15 @@ import de.ozgcloud.eingang.semantik.SemantikAdapter;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
@Profile("!itcase") @Profile("!itcase")
@Log4j2 @Log4j2
@Component @Component
@RequiredArgsConstructor
class XtaRunner implements ApplicationListener<ContextRefreshedEvent> { class XtaRunner implements ApplicationListener<ContextRefreshedEvent> {
private final XtaService service; @Autowired
private final SemantikAdapter semantikAdapter; private XtaService service;
@Autowired
private SemantikAdapter semantikAdapter;
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
......
...@@ -5,8 +5,6 @@ import static org.assertj.core.api.InstanceOfAssertFactories.*; ...@@ -5,8 +5,6 @@ import static org.assertj.core.api.InstanceOfAssertFactories.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import de.ozgcloud.eingang.semantik.SemantikAdapter;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
...@@ -122,12 +120,9 @@ class XtaITCase { ...@@ -122,12 +120,9 @@ class XtaITCase {
} }
@RequiredArgsConstructor
class ActivateXTARunnerConfig { class ActivateXTARunnerConfig {
private final XtaService service;
private final SemantikAdapter semantikAdapter;
@Bean @Bean
XtaRunner xtaRunner() { XtaRunner xtaRunner() {
return new XtaRunner(service, semantikAdapter); return new XtaRunner();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment