@Test public void shouldReturnFalseForPhishingLink() { ResponseEntity<String> verifierResult = new ResponseEntity<>(JSON_PHISH_RESULT, HttpStatus.OK); given(restTemplate.postForEntity(anyString(), any(LinkedMultiValueMap.class), eq(String.class))).willReturn(verifierResult); boolean result = phishTankUrlVerifier.isSafe(LONG_URL); assertThat(result).isFalse(); }
@Override public final boolean isSafe(final String url) { boolean safe = true; try { final MultiValueMap<String, String> formParameters = this.config.getParameters(); formParameters.add(PARAMETER_URL, url); final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class); if (response.getStatusCode() == HttpStatus.OK) { final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION); if (phish) { LOGGER.warn("Possible malicious link posted: {}", url); LOGGER.debug("PhishTank response: {}", response); safe = false; } } else { LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response); } } catch (final RestClientException | PathNotFoundException exception) { LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception); } return safe; }
PhishTankUrlVerifier implements UrlVerifier { @Override public final boolean isSafe(final String url) { boolean safe = true; try { final MultiValueMap<String, String> formParameters = this.config.getParameters(); formParameters.add(PARAMETER_URL, url); final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class); if (response.getStatusCode() == HttpStatus.OK) { final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION); if (phish) { LOGGER.warn("Possible malicious link posted: {}", url); LOGGER.debug("PhishTank response: {}", response); safe = false; } } else { LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response); } } catch (final RestClientException | PathNotFoundException exception) { LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception); } return safe; } }
PhishTankUrlVerifier implements UrlVerifier { @Override public final boolean isSafe(final String url) { boolean safe = true; try { final MultiValueMap<String, String> formParameters = this.config.getParameters(); formParameters.add(PARAMETER_URL, url); final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class); if (response.getStatusCode() == HttpStatus.OK) { final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION); if (phish) { LOGGER.warn("Possible malicious link posted: {}", url); LOGGER.debug("PhishTank response: {}", response); safe = false; } } else { LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response); } } catch (final RestClientException | PathNotFoundException exception) { LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception); } return safe; } @Autowired  PhishTankUrlVerifier(final RestTemplate clnt, final PhishTankConfig cnfg); }
PhishTankUrlVerifier implements UrlVerifier { @Override public final boolean isSafe(final String url) { boolean safe = true; try { final MultiValueMap<String, String> formParameters = this.config.getParameters(); formParameters.add(PARAMETER_URL, url); final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class); if (response.getStatusCode() == HttpStatus.OK) { final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION); if (phish) { LOGGER.warn("Possible malicious link posted: {}", url); LOGGER.debug("PhishTank response: {}", response); safe = false; } } else { LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response); } } catch (final RestClientException | PathNotFoundException exception) { LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception); } return safe; } @Autowired  PhishTankUrlVerifier(final RestTemplate clnt, final PhishTankConfig cnfg); @Override final boolean isSafe(final String url); }
PhishTankUrlVerifier implements UrlVerifier { @Override public final boolean isSafe(final String url) { boolean safe = true; try { final MultiValueMap<String, String> formParameters = this.config.getParameters(); formParameters.add(PARAMETER_URL, url); final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class); if (response.getStatusCode() == HttpStatus.OK) { final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION); if (phish) { LOGGER.warn("Possible malicious link posted: {}", url); LOGGER.debug("PhishTank response: {}", response); safe = false; } } else { LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response); } } catch (final RestClientException | PathNotFoundException exception) { LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception); } return safe; } @Autowired  PhishTankUrlVerifier(final RestTemplate clnt, final PhishTankConfig cnfg); @Override final boolean isSafe(final String url);  }