use of org.apache.metron.hbase.mock.MockHTable in project metron by apache.
the class TaxiiIntegrationTest method testTaxii.
@Test
public void testTaxii() throws Exception {
final MockHBaseTableProvider provider = new MockHBaseTableProvider();
final Configuration config = HBaseConfiguration.create();
Extractor extractor = new TransformFilterExtractorDecorator(new StixExtractor());
TaxiiHandler handler = new TaxiiHandler(TaxiiConnectionConfig.load(taxiiConnectionConfig), extractor, config) {
@Override
protected synchronized HTableInterface createHTable(String tableInfo) throws IOException {
return provider.addToCache("threat_intel", "cf");
}
};
// UnitTestHelper.verboseLogging();
handler.run();
Set<String> maliciousDomains;
{
MockHTable table = (MockHTable) provider.getTable(config, "threat_intel");
maliciousDomains = getIndicators("domainname:FQDN", table.getPutLog(), "cf");
}
Assert.assertTrue(maliciousDomains.contains("www.office-112.com"));
Assert.assertEquals(numStringsMatch(MockTaxiiService.pollMsg, "DomainNameObj:Value condition=\"Equals\""), maliciousDomains.size());
Set<String> maliciousAddresses;
{
MockHTable table = (MockHTable) provider.getTable(config, "threat_intel");
maliciousAddresses = getIndicators("address:IPV_4_ADDR", table.getPutLog(), "cf");
}
Assert.assertTrue(maliciousAddresses.contains("94.102.53.142"));
Assert.assertEquals(numStringsMatch(MockTaxiiService.pollMsg, "AddressObj:Address_Value condition=\"Equal\""), maliciousAddresses.size());
MockHBaseTableProvider.clear();
// Ensure that the handler can be run multiple times without connection issues.
handler.run();
}
use of org.apache.metron.hbase.mock.MockHTable in project metron by apache.
the class UpdateControllerIntegrationTest method test.
@Test
public void test() throws Exception {
String guid = "bro_2";
ResultActions result = this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0));
try {
result.andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").doesNotExist()).andExpect(jsonPath("$.timestamp").value(2));
} catch (Throwable t) {
System.err.println(result.andReturn().getResponse().getContentAsString());
throw t;
}
MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE);
Assert.assertEquals(0, table.size());
this.mockMvc.perform(patch(updateUrl + "/patch").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(patch)).andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").value("metron")).andExpect(jsonPath("$.timestamp").value(2));
Assert.assertEquals(1, table.size());
{
// ensure hbase is up to date
Get g = new Get(new HBaseDao.Key(guid, "bro").toBytes());
Result r = table.get(g);
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(1, columns.size());
}
this.mockMvc.perform(post(updateUrl + "/replace").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(replace)).andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").doesNotExist()).andExpect(jsonPath("$.timestamp").value(200));
Assert.assertEquals(1, table.size());
{
// ensure hbase is up to date
Get g = new Get(new HBaseDao.Key(guid, "bro").toBytes());
Result r = table.get(g);
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(2, columns.size());
}
}
use of org.apache.metron.hbase.mock.MockHTable in project metron by apache.
the class HBaseProfilerClientTest method setup.
@Before
public void setup() throws Exception {
table = new MockHTable(tableName, columnFamily);
executor = new DefaultStellarStatefulExecutor();
// used to write values to be read during testing
RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
// what we're actually testing
client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
}
use of org.apache.metron.hbase.mock.MockHTable in project metron by apache.
the class ThreatIntelAdapterTest method setup.
@Before
public void setup() throws Exception {
final MockHTable trackerTable = (MockHTable) MockHBaseTableProvider.addToCache(atTableName, cf);
final MockHTable threatIntelTable = (MockHTable) MockHBaseTableProvider.addToCache(threatIntelTableName, cf);
EnrichmentHelper.INSTANCE.load(threatIntelTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {
{
add(new LookupKV<>(new EnrichmentKey("10.0.2.3", "10.0.2.3"), new EnrichmentValue(new HashMap<>())));
}
});
BloomAccessTracker bat = new BloomAccessTracker(threatIntelTableName, 100, 0.03);
PersistentAccessTracker pat = new PersistentAccessTracker(threatIntelTableName, "0", trackerTable, cf, bat, 0L);
lookup = new EnrichmentLookup(threatIntelTable, cf, pat);
JSONParser jsonParser = new JSONParser();
expectedMessage = (JSONObject) jsonParser.parse(expectedMessageString);
}
use of org.apache.metron.hbase.mock.MockHTable in project metron by apache.
the class SimpleHBaseEnrichmentWriterTest method getValues.
public static List<LookupKV<EnrichmentKey, EnrichmentValue>> getValues() throws IOException {
MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE_NAME);
Assert.assertNotNull(table);
List<LookupKV<EnrichmentKey, EnrichmentValue>> ret = new ArrayList<>();
EnrichmentConverter converter = new EnrichmentConverter();
for (Result r : table.getScanner(Bytes.toBytes(TABLE_CF))) {
ret.add(converter.fromResult(r, TABLE_CF));
}
return ret;
}
Aggregations