@Test public void test_readAppRoleMetadata_failure() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String role_name = "testapprole01"; String username = "testuser1"; AppRoleMetadata approleMetadataExpected = new AppRoleMetadata(); String _path = "metadata/approle/" + role_name; approleMetadataExpected.setPath(_path); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy(username); appRoleMetadataDetails.setName(role_name); approleMetadataExpected.setAppRoleMetadataDetails(appRoleMetadataDetails); String responseJson = new ObjectMapper().writeValueAsString(approleMetadataExpected); Response response = getMockResponse(HttpStatus.NOT_FOUND, true, responseJson); when(ControllerUtil.parseJson(responseJson)).thenReturn(null); when(reqProcessor.process("/read", "{\"path\":\""+_path+"\"}",token)).thenReturn(response); AppRoleMetadata appRoleMetadataExpected = appRoleService.readAppRoleMetadata(token, role_name); assertEquals(null, appRoleMetadataExpected); }
public AppRoleMetadata readAppRoleMetadata(String token, String rolename) { AppRoleMetadata appRoleMetadata = null; String _path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + rolename; Response readResponse = reqProcessor.process("/read","{\"path\":\""+_path+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } Map<String,Object> appRoleMetadataMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMetadataMap != null) { appRoleMetadata = new AppRoleMetadata(); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy((String)appRoleMetadataMap.get("createdBy")); appRoleMetadataDetails.setName(rolename); appRoleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails); appRoleMetadata.setPath(_path); } return appRoleMetadata; } else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed. AppRole Not found."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; }
AppRoleService { public AppRoleMetadata readAppRoleMetadata(String token, String rolename) { AppRoleMetadata appRoleMetadata = null; String _path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + rolename; Response readResponse = reqProcessor.process("/read","{\"path\":\""+_path+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } Map<String,Object> appRoleMetadataMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMetadataMap != null) { appRoleMetadata = new AppRoleMetadata(); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy((String)appRoleMetadataMap.get("createdBy")); appRoleMetadataDetails.setName(rolename); appRoleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails); appRoleMetadata.setPath(_path); } return appRoleMetadata; } else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed. AppRole Not found."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } }
AppRoleService { public AppRoleMetadata readAppRoleMetadata(String token, String rolename) { AppRoleMetadata appRoleMetadata = null; String _path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + rolename; Response readResponse = reqProcessor.process("/read","{\"path\":\""+_path+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } Map<String,Object> appRoleMetadataMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMetadataMap != null) { appRoleMetadata = new AppRoleMetadata(); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy((String)appRoleMetadataMap.get("createdBy")); appRoleMetadataDetails.setName(rolename); appRoleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails); appRoleMetadata.setPath(_path); } return appRoleMetadata; } else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed. AppRole Not found."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; }  }
AppRoleService { public AppRoleMetadata readAppRoleMetadata(String token, String rolename) { AppRoleMetadata appRoleMetadata = null; String _path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + rolename; Response readResponse = reqProcessor.process("/read","{\"path\":\""+_path+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } Map<String,Object> appRoleMetadataMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMetadataMap != null) { appRoleMetadata = new AppRoleMetadata(); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy((String)appRoleMetadataMap.get("createdBy")); appRoleMetadataDetails.setName(rolename); appRoleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails); appRoleMetadata.setPath(_path); } return appRoleMetadata; } else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed. AppRole Not found."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; }  ResponseEntity<String> createAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> readAppRole(String token, String rolename); ResponseEntity<String> readAppRoles(String token); ResponseEntity<String> listAppRoles(String token,  UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String token, String rolename); String readRoleId(String token, String rolename); List<String> readAccessorIds(String token, String rolename); AppRoleMetadata readAppRoleMetadata(String token, String rolename); AppRole readAppRoleBasicDetails(String token, String rolename); ResponseEntity<String> readAppRoleRoleId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String token, String rolename, UserDetails userDetails); ResponseEntity<String> createsecretId(String token, AppRoleSecretData appRoleSecretData); ResponseEntity<String> readAppRoleSecretId(String token, String rolename); ResponseEntity<String> deleteSecretId(String token, AppRoleNameSecretId appRoleNameSecretId); ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String token, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId); ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> updateAppRole(String token, AppRole appRole, UserDetails userDetails); Response configureApprole(String rolename,String policies,String token ); }
AppRoleService { public AppRoleMetadata readAppRoleMetadata(String token, String rolename) { AppRoleMetadata appRoleMetadata = null; String _path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + rolename; Response readResponse = reqProcessor.process("/read","{\"path\":\""+_path+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } Map<String,Object> appRoleMetadataMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMetadataMap != null) { appRoleMetadata = new AppRoleMetadata(); AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails(); appRoleMetadataDetails.setCreatedBy((String)appRoleMetadataMap.get("createdBy")); appRoleMetadataDetails.setName(rolename); appRoleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails); appRoleMetadata.setPath(_path); } return appRoleMetadata; } else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed. AppRole Not found."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getMetaDataForAppRole"). put(LogMessage.MESSAGE, "Reading Metadata for AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRoleMetadata; }  ResponseEntity<String> createAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> readAppRole(String token, String rolename); ResponseEntity<String> readAppRoles(String token); ResponseEntity<String> listAppRoles(String token,  UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String token, String rolename); String readRoleId(String token, String rolename); List<String> readAccessorIds(String token, String rolename); AppRoleMetadata readAppRoleMetadata(String token, String rolename); AppRole readAppRoleBasicDetails(String token, String rolename); ResponseEntity<String> readAppRoleRoleId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String token, String rolename, UserDetails userDetails); ResponseEntity<String> createsecretId(String token, AppRoleSecretData appRoleSecretData); ResponseEntity<String> readAppRoleSecretId(String token, String rolename); ResponseEntity<String> deleteSecretId(String token, AppRoleNameSecretId appRoleNameSecretId); ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String token, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId); ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> updateAppRole(String token, AppRole appRole, UserDetails userDetails); Response configureApprole(String rolename,String policies,String token );  }