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 2020/08/15 17:51:47 UTC
[sling-org-apache-sling-commons-clam] branch master updated
(2a3c9c5 -> 50d73d3)
This is an automated email from the ASF dual-hosted git repository.
olli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git.
from 2a3c9c5 SLING-9241 Update Pax Exam to 4.13.3
new 93d0694 style
new ecee393 SLING-9667 Update to Sling Bundle Parent 39
new 50d73d3 SLING-9668 Make clamd service a content analyzer
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pom.xml | 8 ++-
.../org/apache/sling/commons/clam/ClamService.java | 3 +-
.../sling/commons/clam/internal/ClamdService.java | 35 +++++++++++--
.../commons/clam/it/tests/ClamTestSupport.java | 1 +
.../commons/clam/it/tests/ClamdServiceIT.java | 57 ++++++++++++++++++++--
5 files changed, 94 insertions(+), 10 deletions(-)
[sling-org-apache-sling-commons-clam] 01/03: style
Posted by ol...@apache.org.
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 93d06946eaf02b1ac45a59db73d410a26358622a
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Aug 15 17:15:56 2020 +0200
style
---
src/main/java/org/apache/sling/commons/clam/ClamService.java | 3 +--
src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/commons/clam/ClamService.java b/src/main/java/org/apache/sling/commons/clam/ClamService.java
index d0cfd52..99f9680 100644
--- a/src/main/java/org/apache/sling/commons/clam/ClamService.java
+++ b/src/main/java/org/apache/sling/commons/clam/ClamService.java
@@ -32,7 +32,6 @@ public interface ClamService {
* @return The scan result from Clam
* @throws IOException if scanning data or parsing reply fails
*/
- @NotNull
- ScanResult scan(@NotNull final InputStream data) throws IOException;
+ @NotNull ScanResult scan(@NotNull final InputStream data) throws IOException;
}
diff --git a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
index 78cd189..54a77d4 100644
--- a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
+++ b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
@@ -94,8 +94,7 @@ public class ClamdService implements ClamService {
}
@Override
- @NotNull
- public ScanResult scan(@NotNull final InputStream inputStream) throws IOException {
+ public @NotNull ScanResult scan(@NotNull final InputStream inputStream) throws IOException {
try {
return doInstream(inputStream);
} catch (InstreamSizeLimitExceededException e) {
[sling-org-apache-sling-commons-clam] 03/03: SLING-9668 Make clamd
service a content analyzer
Posted by ol...@apache.org.
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 50d73d35bc3f52b37cf3ea56d90a03512670c029
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Aug 15 19:51:14 2020 +0200
SLING-9668 Make clamd service a content analyzer
---
pom.xml | 6 +++
.../sling/commons/clam/internal/ClamdService.java | 32 +++++++++++-
.../commons/clam/it/tests/ClamTestSupport.java | 1 +
.../commons/clam/it/tests/ClamdServiceIT.java | 57 ++++++++++++++++++++--
4 files changed, 91 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index e4f8f5d..95b68a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -144,6 +144,12 @@
<!-- Apache Sling -->
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.content.analyzing</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
<version>3.1.0</version>
<scope>test</scope>
diff --git a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
index 54a77d4..43992e6 100644
--- a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
+++ b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
@@ -26,12 +26,17 @@ import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
import org.apache.commons.io.IOUtils;
import org.apache.sling.commons.clam.ClamService;
import org.apache.sling.commons.clam.ScanResult;
import org.apache.sling.commons.clam.ScanResult.Status;
+import org.apache.sling.commons.content.analyzing.ContentAnalyzer;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -44,13 +49,16 @@ import org.slf4j.LoggerFactory;
@Component(
property = {
Constants.SERVICE_DESCRIPTION + "=Sling Commons Clamd Service",
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+ "operation=malware detection",
+ "provider=clam",
+ "provider=clamd",
}
)
@Designate(
ocd = ClamdServiceConfiguration.class
)
-public class ClamdService implements ClamService {
+public class ClamdService implements ClamService, ContentAnalyzer {
private ClamdServiceConfiguration configuration;
@@ -103,6 +111,26 @@ public class ClamdService implements ClamService {
}
}
+ @Override
+ public @NotNull CompletableFuture<Void> analyze(@NotNull InputStream input, @Nullable Map<String, Object> parameters, @NotNull Map<String, Object> report) {
+ return CompletableFuture.runAsync(() -> {
+ try {
+ scan(input, report);
+ } catch (IOException e) {
+ throw new CompletionException(e);
+ }
+ });
+ }
+
+ private void scan(@NotNull final InputStream inputStream, @NotNull Map<String, Object> report) throws IOException {
+ final ScanResult scanResult = scan(inputStream);
+ report.put("sling.commons.clam.scanresult.timestamp", scanResult.getTimestamp());
+ report.put("sling.commons.clam.scanresult.status", scanResult.getStatus());
+ report.put("sling.commons.clam.scanresult.message", scanResult.getMessage());
+ report.put("sling.commons.clam.scanresult.started", scanResult.getStarted());
+ report.put("sling.commons.clam.scanresult.size", scanResult.getSize());
+ }
+
private byte[] doPing() throws IOException {
logger.info("pinging clam daemon at {}:{}", configuration.clamd_host(), configuration.clamd_port());
try (final Socket socket = new Socket(configuration.clamd_host(), configuration.clamd_port());
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 f38dda1..dd6bf08 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
@@ -67,6 +67,7 @@ public abstract class ClamTestSupport extends TestSupport {
.asOption(),
testBundle("bundle.filename"),
mavenBundle().groupId("commons-io").artifactId("commons-io").versionAsInProject(),
+ mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.content.analyzing").versionAsInProject(),
scr(),
// testing
testcontainers(),
diff --git a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamdServiceIT.java b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamdServiceIT.java
index 4fdb198..e17b5a1 100644
--- a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamdServiceIT.java
+++ b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamdServiceIT.java
@@ -19,22 +19,27 @@
package org.apache.sling.commons.clam.it.tests;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.io.IOUtils;
import org.apache.sling.commons.clam.ClamService;
import org.apache.sling.commons.clam.ScanResult;
+import org.apache.sling.commons.content.analyzing.ContentAnalyzer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
import org.ops4j.pax.exam.util.PathUtils;
import static org.junit.Assert.assertEquals;
@@ -47,8 +52,20 @@ public class ClamdServiceIT extends ClamTestSupport {
@Inject
private ClamService clamService;
+ @Inject
+ @Filter(value = "(&(operation=malware detection)(provider=clamd))")
+ private ContentAnalyzer contentAnalyzer;
+
private static final String INSTREAM_SIZE_LIMIT_EXCEEDED_ERROR_MESSAGE = "INSTREAM size limit exceeded. ERROR";
+ private byte[] readEicarFile() throws IOException {
+ final byte[] xaa = Files.readAllBytes(Paths.get(PathUtils.getBaseDir(), "src/test/resources/eicar/eicarcom2.zip/xaa"));
+ final byte[] xab = Files.readAllBytes(Paths.get(PathUtils.getBaseDir(), "src/test/resources/eicar/eicarcom2.zip/xab"));
+ return ByteBuffer.allocate(xaa.length + xab.length).put(xaa).put(xab).array();
+ }
+
+ // ClamService
+
@Test
public void testClamService() {
assertNotNull(clamService);
@@ -65,9 +82,7 @@ public class ClamdServiceIT extends ClamTestSupport {
@Test
public void testScan_eicarcom2_zip() throws Exception {
- final byte[] xaa = Files.readAllBytes(Paths.get(PathUtils.getBaseDir(), "src/test/resources/eicar/eicarcom2.zip/xaa"));
- final byte[] xab = Files.readAllBytes(Paths.get(PathUtils.getBaseDir(), "src/test/resources/eicar/eicarcom2.zip/xab"));
- byte[] eicarcom2_zip = ByteBuffer.allocate(xaa.length + xab.length).put(xaa).put(xab).array();
+ final byte[] eicarcom2_zip = readEicarFile();
try (final InputStream fileInputStream = new ByteArrayInputStream(eicarcom2_zip)) {
final ScanResult result = clamService.scan(fileInputStream);
assertEquals(ScanResult.Status.FOUND, result.getStatus());
@@ -83,4 +98,40 @@ public class ClamdServiceIT extends ClamTestSupport {
}
}
+ // ContentAnalyzer
+
+ @Test
+ public void testContentAnalyzer() {
+ assertNotNull(contentAnalyzer);
+ }
+
+ @Test
+ public void testAnalyze_ok() throws Exception {
+ final String data = "ok – no malware here";
+ final Map<String, Object> report = new HashMap<>();
+ try (final InputStream inputStream = IOUtils.toInputStream(data, StandardCharsets.UTF_8)) {
+ contentAnalyzer.analyze(inputStream, null, report).get();
+ assertEquals(ScanResult.Status.OK, report.get("sling.commons.clam.scanresult.status"));
+ }
+ }
+
+ @Test
+ public void testAnalyze_eicarcom2_zip() throws Exception {
+ final byte[] eicarcom2_zip = readEicarFile();
+ final Map<String, Object> report = new HashMap<>();
+ try (final InputStream inputStream = new ByteArrayInputStream(eicarcom2_zip)) {
+ contentAnalyzer.analyze(inputStream, null, report).get();
+ assertEquals(ScanResult.Status.FOUND, report.get("sling.commons.clam.scanresult.status"));
+ }
+ }
+
+ @Test
+ public void testAnalyze_infiniteStream() throws Exception {
+ final Map<String, Object> report = new HashMap<>();
+ try (final InputStream inputStream = new InfiniteInputStream()) {
+ contentAnalyzer.analyze(inputStream, null, report).get();
+ assertEquals(INSTREAM_SIZE_LIMIT_EXCEEDED_ERROR_MESSAGE, report.get("sling.commons.clam.scanresult.message"));
+ }
+ }
+
}
[sling-org-apache-sling-commons-clam] 02/03: SLING-9667 Update to
Sling Bundle Parent 39
Posted by ol...@apache.org.
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 ecee393dc25dbb1b64b44b81ed56859e76d5a1ec
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Aug 15 17:29:02 2020 +0200
SLING-9667 Update to Sling Bundle Parent 39
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 37eded5..e4f8f5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling-bundle-parent</artifactId>
- <version>38</version>
+ <version>39</version>
<relativePath />
</parent>