ClamAvService.java

1
package com.edtech.service;
2
3
import java.io.IOException;
4
import org.springframework.beans.factory.annotation.Value;
5
import org.springframework.stereotype.Service;
6
import org.springframework.web.multipart.MultipartFile;
7
import xyz.capybara.clamav.ClamavClient;
8
import xyz.capybara.clamav.commands.scan.result.ScanResult;
9
10
/** Service for malware scanning using ClamAV. */
11
@Service
12
public class ClamAvService {
13
  private final ClamavClient clamavClient;
14
15
  /**
16
   * Initializes the ClamAV client.
17
   *
18
   * @param host ClamAV host
19
   * @param port ClamAV port
20
   */
21
  public ClamAvService(
22
      @Value("${clamav.host:localhost}") String host, @Value("${clamav.port:3310}") int port) {
23
    this.clamavClient = new ClamavClient(host, port);
24
  }
25
26
  /**
27
   * Scans a file for malware.
28
   *
29
   * @param file The file to scan
30
   * @return true if the file is safe, false otherwise
31
   */
32
  public boolean isFileSafe(MultipartFile file) {
33
    try {
34
      ScanResult result = clamavClient.scan(file.getInputStream());
35 2 1. isFileSafe : replaced boolean return with true for com/edtech/service/ClamAvService::isFileSafe → NO_COVERAGE
2. isFileSafe : replaced boolean return with false for com/edtech/service/ClamAvService::isFileSafe → NO_COVERAGE
      return result instanceof ScanResult.OK;
36
    } catch (IOException e) {
37
      throw new RuntimeException("Failed to extract InputStream from the file to scan.");
38
    } catch (Exception e) {
39
      throw new RuntimeException("Failed at the communication with antivirus service.");
40
    }
41
  }
42
}

Mutations

35

1.1
Location : isFileSafe
Killed by : none
replaced boolean return with true for com/edtech/service/ClamAvService::isFileSafe → NO_COVERAGE

2.2
Location : isFileSafe
Killed by : none
replaced boolean return with false for com/edtech/service/ClamAvService::isFileSafe → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.25.9 support