diff --git a/docs/modules/plugins/pages/plugin-web-app-to-rest-api.adoc b/docs/modules/plugins/pages/plugin-web-app-to-rest-api.adoc index 7ef89ab243..b0dda47c4a 100644 --- a/docs/modules/plugins/pages/plugin-web-app-to-rest-api.adoc +++ b/docs/modules/plugins/pages/plugin-web-app-to-rest-api.adoc @@ -454,6 +454,8 @@ Then SSL rating for URL `$url` is $comparisonRule `$gradeName` * `$comparisonRule` - xref:parameters:comparison-rule.adoc[The comparison rule]. * `$gradeName` - The name of {grade}. The possible values: `A+`, `A`, `A-`, `B`, `C`, `D`, `E`, `F`, `T`, `M`. +NOTE: The properties marked with *bold* are mandatory. + .Properties [cols="3,1,1,3", options="header"] |=== @@ -467,6 +469,11 @@ Then SSL rating for URL `$url` is $comparisonRule `$gradeName` |`https://api.ssllabs.com` |SSL Labs endpoint. +|[subs=+quotes]`*ssl-labs.email*` +|`string` +|`` +|The email address registered via the https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v4.md#register-for-scan-api-initiation-and-result-fetching-[SSL Labs registration API]. + |=== .Validate SSL rating for `https://www.google.com` diff --git a/vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/ssllabs/SslLabsClient.java b/vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/ssllabs/SslLabsClient.java index d71d3c60e2..4940de7f6d 100644 --- a/vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/ssllabs/SslLabsClient.java +++ b/vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/ssllabs/SslLabsClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 the original author or authors. + * Copyright 2019-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import java.util.List; import java.util.Optional; +import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.core5.http.HttpStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +38,7 @@ public class SslLabsClient private static final String SSL_SCAN_FAILURE = "SSL scan has not been performed successfully during specified waiting period"; private static final String ERROR_MESSAGE = "Status message '{}' received for host {}"; - private static final String API_VERSION = "/api/v3"; + private static final String API_VERSION = "/api/v4"; private static final String ANALYZE_CALL = "/analyze?host=%s&fromCache=on&maxAge=1"; private static final int SERVICE_IS_OVERLOADED = 529; private static final DurationBasedWaiter WAITER = new DurationBasedWaiter(Duration.ofMinutes(10), @@ -46,12 +47,14 @@ public class SslLabsClient private final IHttpClient httpClient; private final JsonUtils jsonUtils; private final String sslLabHost; + private final String email; - public SslLabsClient(IHttpClient httpClient, JsonUtils jsonUtils, String sslLabHost) + public SslLabsClient(IHttpClient httpClient, JsonUtils jsonUtils, String sslLabHost, String email) { this.httpClient = httpClient; this.jsonUtils = jsonUtils; this.sslLabHost = sslLabHost; + this.email = email; } public Optional performSslScan(String host) @@ -89,8 +92,10 @@ private Optional analyze(String host) { try { - HttpResponse response = httpClient.doHttpGet(URI.create( + HttpGet httpGet = new HttpGet(URI.create( String.format("%s%s%s", sslLabHost, API_VERSION, String.format(ANALYZE_CALL, host)))); + httpGet.addHeader("email", email); + HttpResponse response = httpClient.execute(httpGet); return Optional.of(response); } catch (IOException e) diff --git a/vividus-plugin-web-app-to-rest-api/src/main/resources/properties/defaults/default.properties b/vividus-plugin-web-app-to-rest-api/src/main/resources/properties/defaults/default.properties index a0aa383b10..59cea20ceb 100644 --- a/vividus-plugin-web-app-to-rest-api/src/main/resources/properties/defaults/default.properties +++ b/vividus-plugin-web-app-to-rest-api/src/main/resources/properties/defaults/default.properties @@ -22,3 +22,4 @@ resource-checker.uri-to-ignore-regex= resource-checker.attributes-to-check=href,src ssl-labs.api-endpoint=https://api.ssllabs.com +ssl-labs.email= diff --git a/vividus-plugin-web-app-to-rest-api/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-web-app-to-rest-api/src/main/resources/vividus-plugin/spring.xml index d79a0821c2..67a6028c3b 100644 --- a/vividus-plugin-web-app-to-rest-api/src/main/resources/vividus-plugin/spring.xml +++ b/vividus-plugin-web-app-to-rest-api/src/main/resources/vividus-plugin/spring.xml @@ -20,6 +20,7 @@ + diff --git a/vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/ssllabs/SslLabsClientTests.java b/vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/ssllabs/SslLabsClientTests.java index 90a07615e9..5754115dc2 100644 --- a/vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/ssllabs/SslLabsClientTests.java +++ b/vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/ssllabs/SslLabsClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 the original author or authors. + * Copyright 2019-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import static org.mockito.Mockito.when; import java.io.IOException; -import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.List; @@ -41,6 +40,7 @@ import com.github.valfirst.slf4jtest.TestLoggerFactory; import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension; +import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.HttpStatus; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -57,6 +57,7 @@ class SslLabsClientTests { private static final String SSL_LABS_HOST = "https://api.ssllabs.com"; + private static final String SSL_LABS_EMAIL = "test@example.com"; private static final String ANALYZED_HOST = "www.example.com"; private static final int SERVICE_IS_OVERLOADED = 529; @@ -75,7 +76,7 @@ public void beforeEach() { duration.when(() -> Duration.ofMinutes(10)).thenReturn(Duration.ZERO); duration.when(() -> Duration.ofSeconds(30)).thenReturn(Duration.ZERO); - client = new SslLabsClient(httpClient, new JsonUtils(), SSL_LABS_HOST); + client = new SslLabsClient(httpClient, new JsonUtils(), SSL_LABS_HOST, SSL_LABS_EMAIL); } } @@ -95,7 +96,7 @@ void shouldPerformSslScanWithIOException() throws IOException try (var grade = mockStatic(Grade.class)) { var ioException = mock(IOException.class); - when(httpClient.doHttpGet(any(URI.class))).thenThrow(ioException); + when(httpClient.execute(any(ClassicHttpRequest.class))).thenThrow(ioException); assertEquals(Optional.empty(), client.performSslScan(ANALYZED_HOST)); grade.verify(() -> Grade.fromString(anyString()), never()); assertThat(logger.getLoggingEvents(), @@ -119,7 +120,7 @@ void testPerformSslScanWithUnexpectedStatus(int statusCode) throws IOException HttpResponse httpResponse = new HttpResponse(); httpResponse.setStatusCode(statusCode); httpResponse.setResponseBody(response.getBytes(StandardCharsets.UTF_8)); - when(httpClient.doHttpGet(any(URI.class))).thenReturn(httpResponse); + when(httpClient.execute(any(ClassicHttpRequest.class))).thenReturn(httpResponse); assertEquals(Optional.empty(), client.performSslScan(ANALYZED_HOST)); grade.verify(() -> Grade.fromString(anyString()), never()); assertThat(logger.getLoggingEvents(), hasItems( @@ -175,6 +176,6 @@ private void mockResponse(String response) throws IOException HttpResponse httpResponse = new HttpResponse(); httpResponse.setStatusCode(HttpStatus.SC_OK); httpResponse.setResponseBody(response.getBytes(StandardCharsets.UTF_8)); - when(httpClient.doHttpGet(any(URI.class))).thenReturn(httpResponse); + when(httpClient.execute(any(ClassicHttpRequest.class))).thenReturn(httpResponse); } }