feat(back-end): integration of clamAVS
Some checks failed
Build, Test and Deploy / test-backend (push) Failing after 51s
Build, Test and Deploy / build-and-push (push) Has been skipped
Build, Test and Deploy / deploy (push) Has been skipped

This commit is contained in:
2026-02-12 21:59:48 +01:00
parent f5aa0f298e
commit 59e881c3f4
4 changed files with 43 additions and 2 deletions

View File

@@ -23,7 +23,14 @@ public class ClamAVService {
@Value("${clamav.port:3310}") int port
) {
logger.info("Initializing ClamAV client at {}:{}", 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) {

View File

@@ -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
}
};
}
}

View File

@@ -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");

View File

@@ -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