use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testFetchAuditHistory.
@Test(timeout = 60_000L)
public void testFetchAuditHistory() {
String entry1Key = "testKey";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "testPayload";
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey", "testType", Intervals.of("2000-01-01T00:00:00Z/2100-01-03T00:00:00Z"));
Assert.assertEquals(2, auditEntries.size());
Assert.assertEquals(entry1Key, auditEntries.get(0).getKey());
Assert.assertEquals(entry1Payload, auditEntries.get(0).getPayload());
Assert.assertEquals(entry1Type, auditEntries.get(0).getType());
Assert.assertEquals(entry1AuditInfo, auditEntries.get(0).getAuditInfo());
Assert.assertEquals(entry1Key, auditEntries.get(1).getKey());
Assert.assertEquals(entry1Payload, auditEntries.get(1).getPayload());
Assert.assertEquals(entry1Type, auditEntries.get(1).getType());
Assert.assertEquals(entry1AuditInfo, auditEntries.get(1).getAuditInfo());
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testCreateAuditEntryWithPayloadOverSkipPayloadLimit.
@Test(timeout = 60_000L)
public void testCreateAuditEntryWithPayloadOverSkipPayloadLimit() throws IOException {
int maxPayloadSize = 10;
SQLAuditManager auditManagerWithMaxPayloadSizeBytes = new SQLAuditManager(connector, derbyConnectorRule.metadataTablesConfigSupplier(), new NoopServiceEmitter(), mapper, new SQLAuditManagerConfig() {
@Override
public long getMaxPayloadSizeBytes() {
return maxPayloadSize;
}
});
String entry1Key = "testKey";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "payload audit to store";
auditManagerWithMaxPayloadSizeBytes.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
byte[] payload = connector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getAuditTable(), "audit_key", "payload", "testKey");
AuditEntry dbEntry = mapper.readValue(payload, AuditEntry.class);
Assert.assertEquals(entry1Key, dbEntry.getKey());
Assert.assertNotEquals(entry1Payload, dbEntry.getPayload());
Assert.assertEquals(StringUtils.format(AuditManager.PAYLOAD_SKIP_MSG_FORMAT, maxPayloadSize), dbEntry.getPayload());
Assert.assertEquals(entry1Type, dbEntry.getType());
Assert.assertEquals(entry1AuditInfo, dbEntry.getAuditInfo());
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testFetchAuditHistoryByKeyAndTypeWithLimit.
@Test(timeout = 60_000L)
public void testFetchAuditHistoryByKeyAndTypeWithLimit() {
String entry1Key = "testKey1";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "testPayload";
String entry2Key = "testKey2";
String entry2Type = "testType";
AuditInfo entry2AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry2Payload = "testPayload";
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
auditManager.doAudit(entry2Key, entry2Type, entry2AuditInfo, entry2Payload, stringConfigSerde);
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey1", "testType", 1);
Assert.assertEquals(1, auditEntries.size());
Assert.assertEquals(entry1Key, auditEntries.get(0).getKey());
Assert.assertEquals(entry1Payload, auditEntries.get(0).getPayload());
Assert.assertEquals(entry1Type, auditEntries.get(0).getType());
Assert.assertEquals(entry1AuditInfo, auditEntries.get(0).getAuditInfo());
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testFetchAuditHistoryByTypeWithLimit.
@Test(timeout = 60_000L)
public void testFetchAuditHistoryByTypeWithLimit() {
String entry1Key = "testKey";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "testPayload1";
String entry2Key = "testKey";
String entry2Type = "testType";
AuditInfo entry2AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry2Payload = "testPayload2";
String entry3Key = "testKey";
String entry3Type = "testType";
AuditInfo entry3AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry3Payload = "testPayload3";
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
auditManager.doAudit(entry2Key, entry2Type, entry2AuditInfo, entry2Payload, stringConfigSerde);
auditManager.doAudit(entry3Key, entry3Type, entry3AuditInfo, entry3Payload, stringConfigSerde);
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testType", 2);
Assert.assertEquals(2, auditEntries.size());
Assert.assertEquals(entry3Key, auditEntries.get(0).getKey());
Assert.assertEquals(entry3Payload, auditEntries.get(0).getPayload());
Assert.assertEquals(entry3Type, auditEntries.get(0).getType());
Assert.assertEquals(entry3AuditInfo, auditEntries.get(0).getAuditInfo());
Assert.assertEquals(entry2Key, auditEntries.get(1).getKey());
Assert.assertEquals(entry2Payload, auditEntries.get(1).getPayload());
Assert.assertEquals(entry2Type, auditEntries.get(1).getType());
Assert.assertEquals(entry2AuditInfo, auditEntries.get(1).getAuditInfo());
}
Aggregations