use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by cdapio.
the class MonitorHandlerAuthorizationTest method testRestartServiceInstanceAuthorization.
@Test
public void testRestartServiceInstanceAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(ApplicationPermission.EXECUTE));
FullHttpRequest request = mock(FullHttpRequest.class);
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.restartServiceInstance(request, responder, SERVICE_NAME, 0);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.restartServiceInstance(request, responder, SERVICE_NAME, 0);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by cdapio.
the class MonitorHandlerAuthorizationTest method createMonitorHandler.
private static MonitorHandler createMonitorHandler(Authorizable authorizable, List<Permission> requiredPermissions) {
Map<String, MasterServiceManager> masterServiceManagerMap = new HashMap<>();
MasterServiceManager mockMasterServiceManager = mock(MasterServiceManager.class);
when(mockMasterServiceManager.getInstances()).thenReturn(1);
when(mockMasterServiceManager.isServiceEnabled()).thenReturn(true);
when(mockMasterServiceManager.getMinInstances()).thenReturn(1);
when(mockMasterServiceManager.getMaxInstances()).thenReturn(1);
when(mockMasterServiceManager.setInstances(any(Integer.class))).thenReturn(true);
masterServiceManagerMap.put(SERVICE_NAME, mockMasterServiceManager);
ServiceStore mockServiceStore = mock(ServiceStore.class);
InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
inMemoryAccessController.grant(authorizable, MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(requiredPermissions)));
AuthenticationContext authenticationContext = new AuthenticationTestContext();
DefaultContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(authenticationContext, inMemoryAccessController);
return new MonitorHandler(masterServiceManagerMap, mockServiceStore, contextAccessEnforcer);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by cdapio.
the class MonitorHandlerAuthorizationTest method testRestartAllServiceInstancesAuthorization.
@Test
public void testRestartAllServiceInstancesAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(ApplicationPermission.EXECUTE));
FullHttpRequest request = mock(FullHttpRequest.class);
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.restartAllServiceInstances(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.restartAllServiceInstances(request, responder, SERVICE_NAME);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by cdapio.
the class MonitorHandlerAuthorizationTest method testGetSystemServiceLiveInfoAuthorization.
@Test
public void testGetSystemServiceLiveInfoAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.GET));
HttpRequest request = mock(HttpRequest.class);
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.getServiceLiveInfo(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.getServiceLiveInfo(request, responder, SERVICE_NAME);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by caskdata.
the class MonitorHandlerAuthorizationTest method testUpdateServiceLogLevelsAuthorization.
@Test
public void testUpdateServiceLogLevelsAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
Map<String, String> bodyArgs = new HashMap<>();
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/system/services/service/loglevels", Unpooled.copiedBuffer(GSON.toJson(bodyArgs), StandardCharsets.UTF_8));
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.updateServiceLogLevels(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.updateServiceLogLevels(request, responder, SERVICE_NAME);
}
Aggregations