You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/07/01 18:27:00 UTC
[sling-org-apache-sling-commons-clam] 04/04: SLING-8549 Improve
ClamTestSupport
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git
commit f3b948d9b8472757e1f600ebcc25f45f1ff44550
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Jul 1 20:26:20 2019 +0200
SLING-8549 Improve ClamTestSupport
* Support custom host and port for Clam daemon
* Use local Docker container by default
---
README.md | 26 +++++++++++++++++--
pom.xml | 14 +++++++++-
.../commons/clam/it/tests/ClamTestSupport.java | 30 ++++++++++++++++++++--
3 files changed, 65 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index dc3bcd5..2d84250 100644
--- a/README.md
+++ b/README.md
@@ -8,14 +8,36 @@ This module is part of the [Apache Sling](https://sling.apache.org) project.
Scans data for malware using [ClamAV](https://www.clamav.net).
+Please see [Apache Sling Clam](https://github.com/apache/sling-org-apache-sling-clam) for an integration into Apache Sling to scan data in JCR.
+
+
+## Integration Tests
+
Integration tests require a running Clam daemon and are not enabled by default.
-Please see [Apache Sling Clam](https://github.com/apache/sling-org-apache-sling-clam) for an integration into Apache Sling to scan data in JCR.
+
+### Use [Testcontainers](https://www.testcontainers.org/) and local [Docker](https://www.docker.com/) Engine
+
+Enable the `it` profile to run integration tests with Docker container:
+
+ mvn clean install -Pit
+
+
+### Use external Clam daemon
+
+To disable *Testcontainers* and use an external Clam daemon set `clamd.testcontainer` to `false`:
+
+ mvn clean install -Pit -Dclamd.testcontainer=false
+
+To override default Clam daemon host `localhost` and port `3310` set `clamd.host` and `clamd.port`:
+
+ mvn clean install -Pit -Dclamd.testcontainer=false -Dclamd.host=localhost -Dclamd.port=3310
+
## EICAR
[EICAR](http://www.eicar.org) provides anti-malware [test files](http://www.eicar.org/85-0-Download.html) which are used by this module. Read carefully about [intended use](http://www.eicar.org/86-0-Intended-use.html).
-The test files are split to prevent alarms on development and build systems.
+The test files are split to prevent alarms on development and build systems and concatenated in memory during test execution.
split -b 154 eicarcom2.zip
diff --git a/pom.xml b/pom.xml
index b08adac..e020630 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,7 +155,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>3.0.0</version>
+ <version>3.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- nullability -->
@@ -217,6 +217,18 @@
<version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-wrap</artifactId>
+ <version>2.6.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>1.11.3</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
index 490a70e..5186204 100644
--- a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
+++ b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
@@ -20,30 +20,56 @@ package org.apache.sling.commons.clam.it.tests;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Duration;
import java.util.Arrays;
import org.apache.sling.testing.paxexam.TestSupport;
import org.jetbrains.annotations.NotNull;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
+import org.testcontainers.containers.GenericContainer;
import static org.apache.sling.testing.paxexam.SlingOptions.scr;
+import static org.apache.sling.testing.paxexam.SlingOptions.testcontainers;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
public abstract class ClamTestSupport extends TestSupport {
+ private static GenericContainer clamContainer;
+
+ private static final String CLAM_CONTAINER_IMAGE_NAME = "mk0x/docker-clamav:alpine";
+
@Configuration
public Option[] configuration() {
+ final boolean testcontainer = Boolean.parseBoolean(System.getProperty("clamd.testcontainer", "true"));
+ final String host;
+ final Integer port;
+ if (testcontainer) {
+ clamContainer = new GenericContainer<>(CLAM_CONTAINER_IMAGE_NAME)
+ .withExposedPorts(3310)
+ .withStartupTimeout(Duration.ofMinutes(3));
+ clamContainer.start();
+ host = clamContainer.getContainerIpAddress();
+ port = clamContainer.getFirstMappedPort();
+ } else {
+ host = System.getProperty("clamd.host", "localhost");
+ port = Integer.parseInt(System.getProperty("clamd.port", "3310"));
+ }
return new Option[]{
baseConfiguration(),
// Sling Commons Clam
+ newConfiguration("org.apache.sling.commons.clam.internal.ClamdService")
+ .put("clamd.host", host)
+ .put("clamd.port", port)
+ .asOption(),
testBundle("bundle.filename"),
mavenBundle().groupId("commons-io").artifactId("commons-io").versionAsInProject(),
scr(),
// testing
- mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
- junitBundles(),
+ testcontainers(),
+ junitBundles()
};
}