use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by caskdata.
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 caskdata.
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 testGetServiceSpecAuthorization.
@Test
public void testGetServiceSpecAuthorization() throws Exception {
InstanceId instanceId = InstanceId.SELF;
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(instanceId, EntityType.SYSTEM_SERVICE), Arrays.asList(StandardPermission.LIST));
HttpRequest request = mock(HttpRequest.class);
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.getServiceSpec(request, responder);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.getServiceSpec(request, responder);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by caskdata.
the class MonitorHandlerAuthorizationTest method testGetLatestRestartServiceInstanceStatusAuthorization.
@Test
public void testGetLatestRestartServiceInstanceStatusAuthorization() 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.getLatestRestartServiceInstanceStatus(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.getLatestRestartServiceInstanceStatus(request, responder, SERVICE_NAME);
}
use of io.cdap.cdap.gateway.handlers.MonitorHandler in project cdap by caskdata.
the class MonitorHandlerAuthorizationTest method testSetServiceInstanceAuthorization.
@Test
public void testSetServiceInstanceAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
Instances instances = new Instances(1);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "system/services/service/instances", Unpooled.copiedBuffer(GSON.toJson(instances), StandardCharsets.UTF_8));
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.setServiceInstance(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.setServiceInstance(request, responder, SERVICE_NAME);
}
Aggregations