feat(back-end): integration of clamAVS
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user