metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmerri...@apache.org
Subject [36/51] [partial] incubator-metron git commit: METRON-113 Project Reorganization (merrimanr) closes apache/incubator-metron#88
Date Tue, 26 Apr 2016 14:46:24 GMT
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
new file mode 100644
index 0000000..18e6ee8
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.common.configuration;
+
+import junit.framework.Assert;
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+import org.apache.metron.common.configuration.Configurations;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class ConfigurationsTest {
+
+  @Test
+  public void test() throws IOException {
+    EqualsVerifier.forClass(Configurations.class).suppress(Warning.NONFINAL_FIELDS, Warning.NULL_FIELDS).usingGetClass().verify();
+    Configurations configurations = new Configurations();
+    try {
+      configurations.updateConfig("someConfig", (byte[]) null);
+      Assert.fail("Updating a config with null should throw an IllegalStateException");
+    } catch(IllegalStateException e) {}
+    Assert.assertTrue(configurations.toString() != null && configurations.toString().length()
> 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
new file mode 100644
index 0000000..b7e3e02
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
@@ -0,0 +1,211 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.common.configuration;
+
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.common.Constants;
+import org.apache.metron.common.utils.JSONUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class EnrichmentConfigTest {
+  /**
+   {
+      "index": "bro",
+      "batchSize": 5,
+      "enrichmentFieldMap": {
+        "geo": ["ip_dst_addr", "ip_src_addr"],
+        "host": ["host"]
+                            },
+      "threatIntelFieldMap": {
+        "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
+                             },
+      "fieldToThreatIntelTypeMap": {
+        "ip_dst_addr" : [ "malicious_ip" ]
+       ,"ip_src_addr" : [ "malicious_ip" ]
+                                   }
+    }
+   */
+  @Multiline
+  public static String sourceConfigStr;
+
+  /**
+{
+  "zkQuorum" : "localhost:2181"
+ ,"sensorToFieldList" : {
+  "bro" : {
+           "type" : "THREAT_INTEL"
+          ,"fieldToEnrichmentTypes" : {
+            "ip_src_addr" : [ "playful" ]
+           ,"ip_dst_addr" : [ "playful" ]
+                                      }
+          }
+                        }
+}
+     */
+  @Multiline
+  public static String threatIntelConfigStr;
+
+  @Test
+  public void testThreatIntel() throws Exception {
+
+    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+
+
+    EnrichmentConfig config = JSONUtils.INSTANCE.load(threatIntelConfigStr, EnrichmentConfig.class);
+    final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
+    EnrichmentConfig.SourceConfigHandler scHandler = new EnrichmentConfig.SourceConfigHandler()
{
+      @Override
+      public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
+        if(sensor.equals("bro")) {
+          return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+        }
+        else {
+          throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
+        }
+      }
+
+      @Override
+      public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception
{
+        outputScs.put(sensor, config);
+      }
+    };
+    EnrichmentConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
+    Assert.assertNotNull(outputScs.get("bro"));
+    Assert.assertNotSame(outputScs.get("bro"), broSc);
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getThreatIntelFieldMap().get(Constants.SIMPLE_HBASE_THREAT_INTEL).size()
+                       , 2
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getThreatIntelFieldMap()
+                                  .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
+                                  .contains("ip_src_addr")
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getThreatIntelFieldMap()
+                                  .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
+                                  .contains("ip_dst_addr")
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().keySet().size()
+                       , 2
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").size()
+                       , 2
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").contains("playful")
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").contains("malicious_ip")
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").size()
+                       , 2
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").contains("playful")
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").contains("malicious_ip")
+                       );
+  }
+
+  /**
+   {
+  "zkQuorum" : "localhost:2181"
+ ,"sensorToFieldList" : {
+  "bro" : {
+           "type" : "ENRICHMENT"
+          ,"fieldToEnrichmentTypes" : {
+            "ip_src_addr" : [ "playful" ]
+           ,"ip_dst_addr" : [ "playful" ]
+                                      }
+          }
+                        }
+   }
+   */
+  @Multiline
+  public static String enrichmentConfigStr;
+  @Test
+  public void testEnrichment() throws Exception {
+
+    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+
+    EnrichmentConfig config = JSONUtils.INSTANCE.load(enrichmentConfigStr, EnrichmentConfig.class);
+    final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
+    EnrichmentConfig.SourceConfigHandler scHandler = new EnrichmentConfig.SourceConfigHandler()
{
+      @Override
+      public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
+        if(sensor.equals("bro")) {
+          return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+        }
+        else {
+          throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
+        }
+      }
+
+      @Override
+      public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception
{
+        outputScs.put(sensor, config);
+      }
+    };
+    EnrichmentConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
+    Assert.assertNotNull(outputScs.get("bro"));
+    Assert.assertNotSame(outputScs.get("bro"), broSc);
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getEnrichmentFieldMap().get(Constants.SIMPLE_HBASE_ENRICHMENT).size()
+                       , 2
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getEnrichmentFieldMap()
+                                  .get(Constants.SIMPLE_HBASE_ENRICHMENT)
+                                  .contains("ip_src_addr")
+                       );
+    Assert.assertTrue( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getEnrichmentFieldMap()
+                                  .get(Constants.SIMPLE_HBASE_ENRICHMENT)
+                                  .contains("ip_dst_addr")
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToEnrichmentTypeMap().keySet().size()
+                       , 2
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_src_addr").size()
+                       , 1
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_src_addr").get(0)
+                       , "playful"
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_dst_addr").size()
+                       , 1
+                       );
+    Assert.assertEquals( outputScs.get("bro").toJSON()
+                       , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_dst_addr").get(0)
+                       , "playful"
+                       );
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
new file mode 100644
index 0000000..93a3d54
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.common.configuration;
+
+import junit.framework.Assert;
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+import org.apache.metron.TestConstants;
+import org.apache.metron.common.cli.ConfigurationsUtils;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class SensorEnrichmentConfigTest {
+
+  @Test
+  public void test() throws IOException {
+    EqualsVerifier.forClass(SensorEnrichmentConfig.class).suppress(Warning.NONFINAL_FIELDS).usingGetClass().verify();
+    Map<String, byte[]> testSensorConfigMap = ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.SAMPLE_CONFIG_PATH);
+    byte[] sensorConfigBytes = testSensorConfigMap.get("yaf");
+    SensorEnrichmentConfig sensorEnrichmentConfig = SensorEnrichmentConfig.fromBytes(sensorConfigBytes);
+    Assert.assertNotNull(sensorEnrichmentConfig);
+    Assert.assertTrue(sensorEnrichmentConfig.toString() != null && sensorEnrichmentConfig.toString().length()
> 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/resources/config/BasicTldExtractorTest.config
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/resources/config/BasicTldExtractorTest.config
b/metron-platform/metron-common/src/test/resources/config/BasicTldExtractorTest.config
new file mode 100644
index 0000000..317add3
--- /dev/null
+++ b/metron-platform/metron-common/src/test/resources/config/BasicTldExtractorTest.config
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#BasicTldExtractorConfig
+logFile=effective_tld_names.dat

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/resources/config/global.json
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/resources/config/global.json b/metron-platform/metron-common/src/test/resources/config/global.json
new file mode 100644
index 0000000..44ce6b1
--- /dev/null
+++ b/metron-platform/metron-common/src/test/resources/config/global.json
@@ -0,0 +1,3 @@
+{
+  "configuration.class.test.property": "Configuration"
+}

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/0117987e/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/resources/config/sensors/bro.json b/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
new file mode 100644
index 0000000..8886495
--- /dev/null
+++ b/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
@@ -0,0 +1,19 @@
+{
+  "index": "bro",
+  "batchSize": 5,
+  "enrichmentFieldMap":
+  {
+    "geo": ["ip_dst_addr", "ip_src_addr"],
+    "host": ["host"]
+  },
+  "threatIntelFieldMap":
+  {
+    "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
+  },
+  "fieldToThreatIntelTypeMap":
+  {
+    "ip_dst_addr" : [ "malicious_ip" ]
+    ,"ip_src_addr" : [ "malicious_ip" ]
+  }
+}
+


Mime
View raw message