Skip to content

Commit

Permalink
Test reactive + auto ClamAV devservice (#24)
Browse files Browse the repository at this point in the history
* Reactive tests

To prepare a reactive rework of the extention

* Active the ClamAV devservice by default.

This PR fix the *Port already in use* issue
and allow a simplest usage of the ClamAV engine
  • Loading branch information
ggrebert authored Jan 26, 2024
1 parent 77fa7e5 commit 9e664f8
Show file tree
Hide file tree
Showing 27 changed files with 697 additions and 126 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ Or add to you pom.xml directly:
Now that you configured your POM to use the service, now you need to configure which scanner(s) you want to use in `application.properties`:

### ClamAV
[ClamAV](https://www.clamav.net/) is an open source Linux based virus scanning engine. If you configure `quarkus.antivirus.clamav.devservice.enabled=true` a DevService will start a ClamAV instance for you on TCP port 3310, so you can test locally during development.
[ClamAV](https://www.clamav.net/) is an open source Linux based virus scanning engine.
If you don't set a host `quarkus.antivirus.clamav.host` a DevService will start a ClamAV instance for you on a dynamic free port, so you can test locally during development.

```properties
quarkus.antivirus.clamav.enabled=true
quarkus.antivirus.clamav.devservice.enabled=true
quarkus.antivirus.clamav.health.enabled=true
quarkus.antivirus.clamav.host=localhost
quarkus.antivirus.clamav.port=3310
```

### VirusTotal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ClamAVBuildConfig {
* by default, unless there is an existing configuration present.
*/
@WithName("clamav.devservice.enabled")
@WithDefault("false")
@WithDefault("true")
boolean enabled();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -73,8 +74,7 @@ protected void configure() {
withNetwork(Network.SHARED);
}

// this forces the TCP port to match quarkus.antivirus.clamav.port
addFixedExposedPort(getPort(), PORT_TCP);
addExposedPort(PORT_TCP);
}

/**
Expand All @@ -84,8 +84,10 @@ protected void configure() {
*/
public Map<String, String> getExposedConfig() {
Map<String, String> exposed = new HashMap<>(1);
exposed.put(this.config.serviceName() + ".tcp.port", Objects.toString(getEffectivePort()));
exposed.put(this.config.serviceName() + ".tcp.port", Objects.toString(getFirstMappedPort()));
exposed.put(this.config.serviceName() + ".tcp.host", Objects.toString(getEffectiveHost()));
exposed.put("quarkus.antivirus.clamav.port", Objects.toString(getFirstMappedPort()));
exposed.put("quarkus.antivirus.clamav.host", Objects.toString(getEffectiveHost()));
exposed.putAll(super.getEnvMap());
return exposed;
}
Expand All @@ -95,7 +97,7 @@ public String getEffectiveHost() {
return hostName;
}

return getTcpHost();
return getHost();
}

/**
Expand Down Expand Up @@ -124,10 +126,9 @@ public static Integer getPort() {
/**
* Use "quarkus.antivirus.clamav.host" to configure ClamAV server.
*
* @return the host or "localhost" if not found
* @return the host in an Optional.
*/
public static String getTcpHost() {
return ConfigProvider.getConfig().getOptionalValue("quarkus.antivirus.clamav.host",
String.class).orElse("localhost");
public static Optional<String> getTcpHost() {
return ConfigProvider.getConfig().getOptionalValue("quarkus.antivirus.clamav.host", String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private DevServicesResultBuildItem.RunningDevService startClamAV(DockerStatusBui
return null;
}

if (!ClamAVContainer.getTcpHost().equalsIgnoreCase("localhost")) {
if (ClamAVContainer.getTcpHost().isPresent()) {
// no mailer configured
log.warn("Not starting dev services for ClamAV, as 'quarkus.antivirus.clamav.host' has been configured.");
return null;
Expand Down
1 change: 0 additions & 1 deletion deployment/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
quarkus.antivirus.clamav.enabled=true
quarkus.antivirus.clamav.devservice.enabled=true
126 changes: 126 additions & 0 deletions integration-tests/imperative/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.antivirus</groupId>
<artifactId>quarkus-antivirus-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>quarkus-antivirus-integration-tests-imperative</artifactId>
<name>Quarkus Antivirus - Integration Tests - Imperative</name>
<properties>
<skipITs>true</skipITs>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.antivirus</groupId>
<artifactId>quarkus-antivirus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.antivirus</groupId>
<artifactId>quarkus-antivirus-deployment</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
quarkus.http.limits.max-body-size=200m
# ClamAV
quarkus.antivirus.clamav.enabled=true
quarkus.antivirus.clamav.chunk-size=30000
quarkus.antivirus.clamav.devservice.fresh-clam=false
quarkus.antivirus.clamav.health.enabled=true
# VirusTotal
quarkus.antivirus.virustotal.enabled=true
quarkus.antivirus.virustotal.key=<YOUR KEY HERE>
quarkus.antivirus.virustotal.minimum-votes=1
113 changes: 8 additions & 105 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.antivirus</groupId>
Expand All @@ -8,107 +9,9 @@
</parent>
<artifactId>quarkus-antivirus-integration-tests</artifactId>
<name>Quarkus Antivirus - Integration Tests</name>
<properties>
<skipITs>true</skipITs>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.antivirus</groupId>
<artifactId>quarkus-antivirus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
<packaging>pom</packaging>
<modules>
<module>imperative</module>
<module>reactive</module>
</modules>
</project>
Loading

0 comments on commit 9e664f8

Please sign in to comment.