mirror of https://github.com/apache/druid.git
Audit create/update of a supervisor spec (#15636)
Changes - Audit create or update of a supervisor spec. The purpose of the audit is to track which user made change to a supervisor and when. - The audit entry does not contain the entire spec or even a diff of the changes as this is already captured in the `druid_supervisors` metadata table.
This commit is contained in:
parent
63bfb3e6c9
commit
f7bd5ba4d3
|
@ -30,6 +30,8 @@ import com.google.common.collect.Lists;
|
|||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.sun.jersey.spi.container.ResourceFilters;
|
||||
import org.apache.druid.audit.AuditEntry;
|
||||
import org.apache.druid.audit.AuditManager;
|
||||
import org.apache.druid.indexing.overlord.DataSourceMetadata;
|
||||
import org.apache.druid.indexing.overlord.TaskMaster;
|
||||
import org.apache.druid.indexing.overlord.http.security.SupervisorResourceFilter;
|
||||
|
@ -90,6 +92,7 @@ public class SupervisorResource
|
|||
private final TaskMaster taskMaster;
|
||||
private final AuthorizerMapper authorizerMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final AuditManager auditManager;
|
||||
private final AuthConfig authConfig;
|
||||
|
||||
@Inject
|
||||
|
@ -97,13 +100,15 @@ public class SupervisorResource
|
|||
TaskMaster taskMaster,
|
||||
AuthorizerMapper authorizerMapper,
|
||||
ObjectMapper objectMapper,
|
||||
AuthConfig authConfig
|
||||
AuthConfig authConfig,
|
||||
AuditManager auditManager
|
||||
)
|
||||
{
|
||||
this.taskMaster = taskMaster;
|
||||
this.authorizerMapper = authorizerMapper;
|
||||
this.objectMapper = objectMapper;
|
||||
this.authConfig = authConfig;
|
||||
this.auditManager = auditManager;
|
||||
}
|
||||
|
||||
@POST
|
||||
|
@ -143,6 +148,19 @@ public class SupervisorResource
|
|||
}
|
||||
|
||||
manager.createOrUpdateAndStartSupervisor(spec);
|
||||
|
||||
final String auditPayload
|
||||
= StringUtils.format("Update supervisor[%s] for datasource[%s]", spec.getId(), spec.getDataSources());
|
||||
auditManager.doAudit(
|
||||
AuditEntry.builder()
|
||||
.key(spec.getId())
|
||||
.type("supervisor")
|
||||
.auditInfo(AuthorizationUtils.buildAuditInfo(req))
|
||||
.request(AuthorizationUtils.buildRequestInfo("overlord", req))
|
||||
.payload(auditPayload)
|
||||
.build()
|
||||
);
|
||||
|
||||
return Response.ok(ImmutableMap.of("id", spec.getId())).build();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.google.common.base.Optional;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.druid.audit.AuditManager;
|
||||
import org.apache.druid.indexing.overlord.DataSourceMetadata;
|
||||
import org.apache.druid.indexing.overlord.TaskMaster;
|
||||
import org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler;
|
||||
|
@ -92,6 +93,9 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
@Mock
|
||||
private AuthConfig authConfig;
|
||||
|
||||
@Mock
|
||||
private AuditManager auditManager;
|
||||
|
||||
private SupervisorResource supervisorResource;
|
||||
|
||||
@Before
|
||||
|
@ -127,7 +131,8 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
}
|
||||
},
|
||||
OBJECT_MAPPER,
|
||||
authConfig
|
||||
authConfig,
|
||||
auditManager
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -146,14 +151,14 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
|
||||
EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
|
||||
EasyMock.expect(supervisorManager.createOrUpdateAndStartSupervisor(spec)).andReturn(true);
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
EasyMock.expect(authConfig.isEnableInputSourceSecurity()).andReturn(false);
|
||||
|
||||
setupMockRequest();
|
||||
setupMockRequestForAudit();
|
||||
|
||||
EasyMock.expect(authConfig.isEnableInputSourceSecurity()).andReturn(true);
|
||||
auditManager.doAudit(EasyMock.anyObject());
|
||||
EasyMock.expectLastCall().once();
|
||||
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specPost(spec, request);
|
||||
|
@ -187,13 +192,12 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
|
||||
EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
|
||||
EasyMock.expect(supervisorManager.createOrUpdateAndStartSupervisor(spec)).andReturn(true);
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
setupMockRequestForAudit();
|
||||
|
||||
auditManager.doAudit(EasyMock.anyObject());
|
||||
EasyMock.expectLastCall().once();
|
||||
|
||||
EasyMock.expect(authConfig.isEnableInputSourceSecurity()).andReturn(true);
|
||||
replayAll();
|
||||
|
||||
|
@ -248,13 +252,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorIds()).andReturn(SUPERVISOR_IDS).atLeastOnce();
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec(SPEC1.getId())).andReturn(Optional.of(SPEC1));
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec(SPEC2.getId())).andReturn(Optional.of(SPEC2));
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAll(null, null, null, request);
|
||||
|
@ -285,13 +283,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec("id2")).andReturn(Optional.of(SPEC2)).anyTimes();
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id1")).andReturn(Optional.of(state1)).anyTimes();
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id2")).andReturn(Optional.of(state2)).anyTimes();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAll("", null, null, request);
|
||||
|
@ -320,13 +312,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec("id2")).andReturn(Optional.of(SPEC2)).anyTimes();
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id1")).andReturn(Optional.of(state1)).anyTimes();
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id2")).andReturn(Optional.of(state2)).anyTimes();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAll(null, null, "", request);
|
||||
|
@ -359,13 +345,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec("id2")).andReturn(Optional.of(SPEC2)).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id1")).andReturn(Optional.of(state1)).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorState("id2")).andReturn(Optional.of(state2)).times(1);
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAll(null, true, null, request);
|
||||
|
@ -598,13 +578,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC1.getId(), true)).andReturn(true);
|
||||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC2.getId(), true)).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.suspendAll(request);
|
||||
|
@ -622,13 +596,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec(SPEC2.getId())).andReturn(Optional.of(SPEC2));
|
||||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC1.getId(), true)).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("notDruid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequestForUser("notDruid");
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.suspendAll(request);
|
||||
|
@ -647,13 +615,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC1.getId(), false)).andReturn(true);
|
||||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC2.getId(), false)).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.resumeAll(request);
|
||||
|
@ -671,13 +633,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec(SPEC2.getId())).andReturn(Optional.of(SPEC2));
|
||||
EasyMock.expect(supervisorManager.suspendOrResumeSupervisor(SPEC1.getId(), false)).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("notDruid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequestForUser("notDruid");
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.resumeAll(request);
|
||||
|
@ -696,13 +652,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.stopAndRemoveSupervisor(SPEC1.getId())).andReturn(true);
|
||||
EasyMock.expect(supervisorManager.stopAndRemoveSupervisor(SPEC2.getId())).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.terminateAll(request);
|
||||
|
@ -720,13 +670,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorSpec(SPEC2.getId())).andReturn(Optional.of(SPEC2));
|
||||
EasyMock.expect(supervisorManager.stopAndRemoveSupervisor(SPEC1.getId())).andReturn(true);
|
||||
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("notDruid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequestForUser("notDruid");
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.terminateAll(request);
|
||||
|
@ -801,13 +745,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorHistory()).andReturn(history);
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec("id1")).andReturn(Optional.of(SPEC1)).atLeastOnce();
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec("id2")).andReturn(Optional.of(SPEC2)).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAllHistory(request);
|
||||
|
@ -912,13 +850,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorHistory()).andReturn(history);
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec("id1")).andReturn(Optional.of(SPEC1)).atLeastOnce();
|
||||
EasyMock.expect(supervisorManager.getSupervisorSpec("id2")).andReturn(Optional.of(SPEC2)).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("wronguser", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequestForUser("wronguser");
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetAllHistory(request);
|
||||
|
@ -1002,13 +934,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id1")).andReturn(versions1).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id2")).andReturn(versions2).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id3")).andReturn(Collections.emptyList()).times(1);
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("druid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequest();
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetHistory(request, "id1");
|
||||
|
@ -1099,13 +1025,7 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id2")).andReturn(versions2).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id3")).andReturn(versions3).times(1);
|
||||
EasyMock.expect(supervisorManager.getSupervisorHistoryForId("id4")).andReturn(Collections.emptyList()).times(1);
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(
|
||||
new AuthenticationResult("notdruid", "druid", null, null)
|
||||
).atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
setupMockRequestForUser("notdruid");
|
||||
replayAll();
|
||||
|
||||
Response response = supervisorResource.specGetHistory(request, "id1");
|
||||
|
@ -1261,6 +1181,33 @@ public class SupervisorResourceTest extends EasyMockSupport
|
|||
Assert.assertEquals(spec, specRoundTrip);
|
||||
}
|
||||
|
||||
private void setupMockRequest()
|
||||
{
|
||||
setupMockRequestForUser("druid");
|
||||
}
|
||||
|
||||
private void setupMockRequestForUser(String user)
|
||||
{
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
|
||||
EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
|
||||
.andReturn(new AuthenticationResult(user, "druid", null, null))
|
||||
.atLeastOnce();
|
||||
request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
}
|
||||
|
||||
private void setupMockRequestForAudit()
|
||||
{
|
||||
EasyMock.expect(request.getHeader(AuditManager.X_DRUID_AUTHOR)).andReturn("author").once();
|
||||
EasyMock.expect(request.getHeader(AuditManager.X_DRUID_COMMENT)).andReturn("comment").once();
|
||||
|
||||
EasyMock.expect(request.getRemoteAddr()).andReturn("127.0.0.1").once();
|
||||
EasyMock.expect(request.getMethod()).andReturn("POST").once();
|
||||
EasyMock.expect(request.getRequestURI()).andReturn("supes").once();
|
||||
EasyMock.expect(request.getQueryString()).andReturn("a=b").once();
|
||||
}
|
||||
|
||||
private static class TestSupervisorSpec implements SupervisorSpec
|
||||
{
|
||||
protected final String id;
|
||||
|
|
Loading…
Reference in New Issue