use of io.cdap.cdap.proto.id.SystemServiceId in project cdap by cdapio.
the class MonitorHandlerAuthorizationTest method testResetServiceLogLevelsAuthorization.
@Test
public void testResetServiceLogLevelsAuthorization() throws Exception {
SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
List<String> bodyArgs = new ArrayList<>();
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "system/services/service/resetloglevels", Unpooled.copiedBuffer(GSON.toJson(bodyArgs), StandardCharsets.UTF_8));
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
}
use of io.cdap.cdap.proto.id.SystemServiceId in project cdap by cdapio.
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.proto.id.SystemServiceId in project cdap by cdapio.
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