From 59e881c3f41bfe13751f187020509da5a6d15872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20K=C3=BCng?= Date: Thu, 12 Feb 2026 21:59:48 +0100 Subject: [PATCH] feat(back-end): integration of clamAVS --- .../service/ClamAVService.java | 9 +++++++- .../printcalculator/config/TestConfig.java | 23 +++++++++++++++++++ .../controller/OrderIntegrationTest.java | 11 +++++++++ docker-compose.yml | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 backend/src/test/java/com/printcalculator/config/TestConfig.java diff --git a/backend/src/main/java/com/printcalculator/service/ClamAVService.java b/backend/src/main/java/com/printcalculator/service/ClamAVService.java index 0306730..8d5dec5 100644 --- a/backend/src/main/java/com/printcalculator/service/ClamAVService.java +++ b/backend/src/main/java/com/printcalculator/service/ClamAVService.java @@ -23,7 +23,14 @@ public class ClamAVService { @Value("${clamav.port:3310}") int port ) { logger.info("Initializing ClamAV client at {}:{}", host, port); - this.clamavClient = new ClamavClient(host, port); + try { + this.clamavClient = new ClamavClient(host, port); + } catch (Exception e) { + logger.error("Failed to initialize ClamAV client: " + e.getMessage()); + // We don't throw exception here to allow app to start even if ClamAV is down/unreachable + // scan() method will handle null client or failure + throw new RuntimeException("ClamAV initialization failed", e); + } } public boolean scan(InputStream inputStream) { diff --git a/backend/src/test/java/com/printcalculator/config/TestConfig.java b/backend/src/test/java/com/printcalculator/config/TestConfig.java new file mode 100644 index 0000000..50c2b3e --- /dev/null +++ b/backend/src/test/java/com/printcalculator/config/TestConfig.java @@ -0,0 +1,23 @@ +package com.printcalculator.config; + +import com.printcalculator.service.ClamAVService; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; + +import java.io.InputStream; + +@TestConfiguration +public class TestConfig { + + @Bean + @Primary + public ClamAVService mockClamAVService() { + return new ClamAVService("localhost", 3310) { + @Override + public boolean scan(InputStream inputStream) { + return true; // Always clean for tests + } + }; + } +} diff --git a/backend/src/test/java/com/printcalculator/controller/OrderIntegrationTest.java b/backend/src/test/java/com/printcalculator/controller/OrderIntegrationTest.java index 12f52b1..652a078 100644 --- a/backend/src/test/java/com/printcalculator/controller/OrderIntegrationTest.java +++ b/backend/src/test/java/com/printcalculator/controller/OrderIntegrationTest.java @@ -31,10 +31,18 @@ import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.springframework.boot.test.mock.mockito.MockBean; +import com.printcalculator.service.ClamAVService; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + @SpringBootTest @AutoConfigureMockMvc class OrderIntegrationTest { + @MockBean + private ClamAVService clamAVService; + @Autowired private MockMvc mockMvc; @@ -56,6 +64,9 @@ class OrderIntegrationTest { @BeforeEach void setup() throws Exception { + // Mock ClamAV to always return true (safe) + when(clamAVService.scan(any())).thenReturn(true); + // 1. Create Quote Session QuoteSession session = new QuoteSession(); session.setStatus("ACTIVE"); diff --git a/docker-compose.yml b/docker-compose.yml index 5e636f8..1f90f60 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: - MARKUP_PERCENT=20 - TEMP_DIR=/app/temp - PROFILES_DIR=/app/profiles - - CLAMAV_HOST=clamav + - CLAMAV_HOST=192.168.1.147 - CLAMAV_PORT=3310 depends_on: - db