@Test public void test_AssociateAppRole_failed_403() throws Exception { ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"messages\":[\"Approle : approle1 failed to be associated with SDB.. Invalid Path specified\"]}"); String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; SafeAppRoleAccess safeAppRoleAccess = new SafeAppRoleAccess("approle1", "shared/mysafe01", "write"); String jsonStr = "{\"role_name\":\"approle1\",\"path\":\"shared/mysafe01\",\"access\":\"write\"}"; Map<String, Object> requestMap = new ObjectMapper().readValue(jsonStr, new TypeReference<Map<String, Object>>(){}); when(ControllerUtil.parseJson(Mockito.anyString())).thenReturn(requestMap); when(ControllerUtil.areSafeAppRoleInputsValid(Mockito.anyMap())).thenReturn(true); when(ControllerUtil.canAddPermission(Mockito.anyString(), Mockito.anyString())).thenReturn(false); ResponseEntity<String> responseEntityActual = appRoleService.associateApprole(token, safeAppRoleAccess); assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode()); assertTrue(responseEntityActual.getBody().contains("Approle :approle1 failed to be associated with SDB.. Invalid Path specified")); }
public ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to associate this AppRole to any safe\"]}"); } ResponseEntity<String> response = associateApproletoSafe(token,safeAppRoleAccess); if(response.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else if(response.getStatusCode().equals(HttpStatus.OK)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else { return ResponseEntity.status(response.getStatusCode()).body(response.getBody()); } }
AppRoleService { public ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to associate this AppRole to any safe\"]}"); } ResponseEntity<String> response = associateApproletoSafe(token,safeAppRoleAccess); if(response.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else if(response.getStatusCode().equals(HttpStatus.OK)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else { return ResponseEntity.status(response.getStatusCode()).body(response.getBody()); } } }
AppRoleService { public ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to associate this AppRole to any safe\"]}"); } ResponseEntity<String> response = associateApproletoSafe(token,safeAppRoleAccess); if(response.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else if(response.getStatusCode().equals(HttpStatus.OK)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else { return ResponseEntity.status(response.getStatusCode()).body(response.getBody()); } }  }
AppRoleService { public ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to associate this AppRole to any safe\"]}"); } ResponseEntity<String> response = associateApproletoSafe(token,safeAppRoleAccess); if(response.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else if(response.getStatusCode().equals(HttpStatus.OK)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else { return ResponseEntity.status(response.getStatusCode()).body(response.getBody()); } }  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 ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to associate this AppRole to any safe\"]}"); } ResponseEntity<String> response = associateApproletoSafe(token,safeAppRoleAccess); if(response.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else if(response.getStatusCode().equals(HttpStatus.OK)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Approle associated to SDB\"]}"); } else { return ResponseEntity.status(response.getStatusCode()).body(response.getBody()); } }  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 );  }