diff --git a/google/detectors/credentials/generic_weak_credential_detector/src/main/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTester.java b/google/detectors/credentials/generic_weak_credential_detector/src/main/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTester.java index 52af963bc..c36691e4a 100644 --- a/google/detectors/credentials/generic_weak_credential_detector/src/main/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTester.java +++ b/google/detectors/credentials/generic_weak_credential_detector/src/main/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTester.java @@ -25,6 +25,7 @@ import com.google.common.flogger.GoogleLogger; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import com.google.tsunami.common.data.NetworkServiceUtils; import com.google.tsunami.common.net.http.HttpClient; import com.google.tsunami.common.net.http.HttpHeaders; @@ -44,7 +45,6 @@ public final class RabbitMQCredentialTester extends CredentialTester { private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); private final HttpClient httpClient; - private static final String RABBITMQ_SERVICE = "rabbitmq"; private static final String RABBITMQ_PAGE_TITLE = "RabbitMQ Management"; private static final String RABBITMQ_SERVER_HEADER = "Cowboy"; private static final String RABBITMQ_WWW_HEADER = "Basic realm=\"RabbitMQ Management\""; @@ -78,7 +78,7 @@ private static String buildTargetUrl(NetworkService networkService, String path) // Checks if the response body contains the title element of rabbitmq management page. // Custom fingerprint phase. - private static boolean bodyContainsRabbitMQElements(String responseBody) { + private static boolean bodyContainsRabbitMqElements(String responseBody) { Document doc = Jsoup.parse(responseBody); String title = doc.title(); @@ -117,7 +117,7 @@ public boolean canAccept(NetworkService networkService) { && response.headers().get("server").get().trim().equals(RABBITMQ_SERVER_HEADER) && response .bodyString() - .map(RabbitMQCredentialTester::bodyContainsRabbitMQElements) + .map(RabbitMQCredentialTester::bodyContainsRabbitMqElements) .orElse(false); url = buildTargetUrl(networkService, "api/overview"); response = httpClient.send(get(url).withEmptyHeaders().build()); @@ -191,7 +191,7 @@ private static boolean bodyContainsSuccessfulLoginElements(String responseBody) } else { return false; } - } catch (Exception e) { + } catch (JsonSyntaxException e) { logger.atWarning().withCause(e).log( "An error occurred while parsing the json response: %s", responseBody); return false; diff --git a/google/detectors/credentials/generic_weak_credential_detector/src/test/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTesterTest.java b/google/detectors/credentials/generic_weak_credential_detector/src/test/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTesterTest.java index 0253c717c..4f2be8418 100644 --- a/google/detectors/credentials/generic_weak_credential_detector/src/test/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTesterTest.java +++ b/google/detectors/credentials/generic_weak_credential_detector/src/test/java/com/google/tsunami/plugins/detectors/credentials/genericweakcredentialdetector/testers/rabbitmq/RabbitMQCredentialTesterTest.java @@ -60,7 +60,7 @@ public class RabbitMQCredentialTesterTest { private static final String WEAK_CRED_AUTH_1 = "Basic dXNlcjoxMjM0"; private static final String WEAK_CRED_AUTH_2 = "Basic cm9vdDpwYXNz"; - private static final ServiceContext.Builder RABBITMQ_SERVICE_CONTEXT = + private static final ServiceContext.Builder rabbitmqServiceContext = ServiceContext.newBuilder() .setWebServiceContext( WebServiceContext.newBuilder() @@ -84,7 +84,7 @@ public void detect_weakCredentialsExists_returnsWeakCredentials() throws Excepti .setNetworkEndpoint( forHostnameAndPort(mockWebServer.getHostName(), mockWebServer.getPort())) .setServiceName("http") - .setServiceContext(RABBITMQ_SERVICE_CONTEXT) + .setServiceContext(rabbitmqServiceContext) .setSoftware(Software.newBuilder().setName("http")) .build(); @@ -105,7 +105,7 @@ public void detect_weakCredentialsExist_returnsAllWeakCredentials() throws Excep .setNetworkEndpoint( forHostnameAndPort(mockWebServer.getHostName(), mockWebServer.getPort())) .setServiceName("http") - .setServiceContext(RABBITMQ_SERVICE_CONTEXT) + .setServiceContext(rabbitmqServiceContext) .build(); assertThat( tester.testValidCredentials( @@ -126,7 +126,7 @@ public void detect_noWeakCredentials_returnsNoCredentials() throws Exception { .setNetworkEndpoint( forHostnameAndPort(mockWebServer.getHostName(), mockWebServer.getPort())) .setServiceName("http") - .setServiceContext(RABBITMQ_SERVICE_CONTEXT) + .setServiceContext(rabbitmqServiceContext) .build(); assertThat(tester.testValidCredentials(targetNetworkService, ImmutableList.of(WRONG_CRED_1))) .isEmpty();