use of io.druid.audit.AuditInfo in project druid by druid-io.
the class LookupCoordinatorResourceTest method testExceptionalNew.
@Test
public void testExceptionalNew() throws Exception {
final String author = "some author";
final String comment = "some comment";
final String ip = "127.0.0.1";
final String errMsg = "some error";
final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.updateLookups(EasyMock.eq(SINGLE_TIER_MAP), EasyMock.capture(auditInfoCapture))).andThrow(new RuntimeException(errMsg)).once();
EasyMock.replay(lookupCoordinatorManager, request);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
final Response response = lookupCoordinatorResource.updateAllLookups(SINGLE_TIER_MAP_SOURCE.openStream(), author, comment, request);
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
Assert.assertTrue(auditInfoCapture.hasCaptured());
final AuditInfo auditInfo = auditInfoCapture.getValue();
Assert.assertEquals(author, auditInfo.getAuthor());
Assert.assertEquals(comment, auditInfo.getComment());
Assert.assertEquals(ip, auditInfo.getIp());
EasyMock.verify(lookupCoordinatorManager, request);
}
use of io.druid.audit.AuditInfo in project druid by druid-io.
the class LookupCoordinatorResourceTest method testDBErrNewLookup.
@Test
public void testDBErrNewLookup() throws Exception {
final String author = "some author";
final String comment = "some comment";
final String ip = "127.0.0.1";
final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.updateLookup(EasyMock.eq(LOOKUP_TIER), EasyMock.eq(LOOKUP_NAME), EasyMock.eq(ImmutableMap.<String, Object>of()), EasyMock.capture(auditInfoCapture))).andReturn(false).once();
EasyMock.replay(lookupCoordinatorManager, request);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
final Response response = lookupCoordinatorResource.createOrUpdateLookup(LOOKUP_TIER, LOOKUP_NAME, author, comment, EMPTY_MAP_SOURCE.openStream(), request);
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
Assert.assertTrue(auditInfoCapture.hasCaptured());
final AuditInfo auditInfo = auditInfoCapture.getValue();
Assert.assertEquals(author, auditInfo.getAuthor());
Assert.assertEquals(comment, auditInfo.getComment());
Assert.assertEquals(ip, auditInfo.getIp());
EasyMock.verify(lookupCoordinatorManager, request);
}
use of io.druid.audit.AuditInfo in project druid by druid-io.
the class LookupCoordinatorResourceTest method testFailedNew.
@Test
public void testFailedNew() throws Exception {
final String author = "some author";
final String comment = "some comment";
final String ip = "127.0.0.1";
final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.updateLookups(EasyMock.eq(SINGLE_TIER_MAP), EasyMock.capture(auditInfoCapture))).andReturn(false).once();
EasyMock.replay(lookupCoordinatorManager, request);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
final Response response = lookupCoordinatorResource.updateAllLookups(SINGLE_TIER_MAP_SOURCE.openStream(), author, comment, request);
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
Assert.assertTrue(auditInfoCapture.hasCaptured());
final AuditInfo auditInfo = auditInfoCapture.getValue();
Assert.assertEquals(author, auditInfo.getAuthor());
Assert.assertEquals(comment, auditInfo.getComment());
Assert.assertEquals(ip, auditInfo.getIp());
EasyMock.verify(lookupCoordinatorManager, request);
}
use of io.druid.audit.AuditInfo in project druid by druid-io.
the class LookupCoordinatorResourceTest method testMissingDelete.
@Test
public void testMissingDelete() {
final String author = "some author";
final String comment = "some comment";
final String ip = "127.0.0.1";
final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.deleteLookup(EasyMock.eq(LOOKUP_TIER), EasyMock.eq(LOOKUP_NAME), EasyMock.capture(auditInfoCapture))).andReturn(false).once();
EasyMock.replay(lookupCoordinatorManager, request);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
final Response response = lookupCoordinatorResource.deleteLookup(LOOKUP_TIER, LOOKUP_NAME, author, comment, request);
Assert.assertEquals(404, response.getStatus());
Assert.assertTrue(auditInfoCapture.hasCaptured());
final AuditInfo auditInfo = auditInfoCapture.getValue();
Assert.assertEquals(author, auditInfo.getAuthor());
Assert.assertEquals(comment, auditInfo.getComment());
Assert.assertEquals(ip, auditInfo.getIp());
EasyMock.verify(lookupCoordinatorManager, request);
}
use of io.druid.audit.AuditInfo in project druid by druid-io.
the class SQLAuditManagerTest method testFetchAuditHistoryByTypeWithLimit.
@Test(timeout = 10_000L)
public void testFetchAuditHistoryByTypeWithLimit() throws IOException {
AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-02T00:00:00Z"));
AuditEntry entry3 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-03T00:00:00Z"));
auditManager.doAudit(entry1);
auditManager.doAudit(entry2);
auditManager.doAudit(entry3);
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testType", 2);
Assert.assertEquals(2, auditEntries.size());
Assert.assertEquals(entry3, auditEntries.get(0));
Assert.assertEquals(entry2, auditEntries.get(1));
}
Aggregations