AWSAuthService { public ResponseEntity<String> deleteRole(String token, String role, UserDetails userDetails){ Response permissionResponse = ControllerUtil.canDeleteRole(role, token, userDetails, TVaultConstants.AWSROLE_METADATA_MOUNT_PATH); if (HttpStatus.INTERNAL_SERVER_ERROR.equals(permissionResponse.getHttpstatus()) || HttpStatus.UNAUTHORIZED.equals(permissionResponse.getHttpstatus())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\""+permissionResponse.getResponse()+"\"]}"); } Response response = reqProcessor.process("/auth/aws/roles/delete","{\"role\":\""+role+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)){ String metaJson = ControllerUtil.populateAWSMetaJson(role, userDetails.getUsername()); Response resp = reqProcessor.process("/delete",metaJson,token); if (HttpStatus.NO_CONTENT.equals(resp.getHttpstatus())) { logger.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete AWS Role"). put(LogMessage.MESSAGE, "Metadata deleted"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Role deleted \"]}"); } return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Role deleted, metadata delete failed\"]}"); }else{ return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }  ResponseEntity<String> authenticateEC2(AWSLogin login); ResponseEntity<String> createRole(String token, AWSLoginRole awsLoginRole, UserDetails userDetails); ResponseEntity<String> updateRole(String token, AWSLoginRole awsLoginRole); ResponseEntity<String> deleteRole(String token, String role, UserDetails userDetails); ResponseEntity<String> fetchRole(String token, String role); ResponseEntity<String> listRoles(String token); ResponseEntity<String> configureClient(AWSClientConfiguration awsClientConfiguration, String token); ResponseEntity<String> readClientConfiguration(String token); ResponseEntity<String> createSTSRole(AWSStsRole awsStsRole, String token); ResponseEntity<String> authenticateIAM(AWSIAMLogin awsiamLogin); ResponseEntity<String> authenticate(AWSAuthType authType, AWSAuthLogin awsAuthLogin); Response configureAWSRole(String roleName,String policies,String token );  }
@Test public void test_deleteRole_successfully() { Response response = getMockResponse(HttpStatus.NO_CONTENT, true, ""); String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Role deleted \"]}"); when(reqProcessor.process("/auth/aws/roles/delete", "{\"role\":\"mytestawsrole\"}", token)).thenReturn(response); UserDetails userDetails = getMockUser(false); String metadatajson = "{ \"path\": \"metadata/awsrole/mytestawsrole\", \"data\": {\"createdBy\":\"normaluser\"}}"; when(ControllerUtil.populateAWSMetaJson("mytestawsrole", userDetails.getUsername())).thenReturn(metadatajson); when(reqProcessor.process("/delete",metadatajson,token)).thenReturn(response); Response permissonResponse = getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole("mytestawsrole", token, userDetails, TVaultConstants.AWSROLE_METADATA_MOUNT_PATH)).thenReturn(permissonResponse); ResponseEntity<String> responseEntity = awsAuthService.deleteRole(token, "mytestawsrole", userDetails); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }