test_class.declarator: DITTO_HEADERS = DittoHeaders.newBuilder().correlationId("ditto").build()
test_class.modifier: private static final
test_class.original_string: private static final DittoHeaders DITTO_HEADERS = DittoHeaders.newBuilder().correlationId("ditto").build();
test_class.type: DittoHeaders
test_class.var_name: DITTO_HEADERS
test_class.declarator: connectionConfig
test_class.modifier: private
test_class.original_string: private ConnectionConfig connectionConfig;
test_class.type: ConnectionConfig
test_class.var_name: connectionConfig
test_class.declarator: connectivityConfig
test_class.modifier: private
test_class.original_string: private ConnectivityConfig connectivityConfig;
test_class.type: ConnectivityConfig
test_class.var_name: connectivityConfig
test_class.declarator: loggingAdapter
test_class.modifier: private
test_class.original_string: private LoggingAdapter loggingAdapter;
test_class.type: LoggingAdapter
test_class.var_name: loggingAdapter
test_class.file: services/connectivity/messaging/src/test/java/org/eclipse/ditto/services/connectivity/messaging/validation/HostValidatorTest.java
test_class.identifier: HostValidatorTest
test_case.body: @Test
      public void expectValidationFailsForInvalidHost() {
          final HostValidator underTest = getHostValidatorWithAllowlist();
          final HostValidationResult validationResult = underTest.validateHost("ditto");
          assertThat(validationResult).extracting(HostValidationResult::isValid).isEqualTo(false);
          final ConnectionConfigurationInvalidException exception = validationResult.toException(DITTO_HEADERS);
          assertThat(exception.getDittoHeaders()).isEqualTo(DITTO_HEADERS);
          assertThat(exception.getMessage()).contains("The configured host 'ditto' is invalid");
      }
test_case.class_method_signature: HostValidatorTest.expectValidationFailsForInvalidHost()
test_case.full_signature: @Test public void expectValidationFailsForInvalidHost()
test_case.identifier: expectValidationFailsForInvalidHost
test_case.invocations: getHostValidatorWithAllowlist validateHost isEqualTo extracting assertThat toException isEqualTo assertThat getDittoHeaders contains assertThat getMessage
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void expectValidationFailsForInvalidHost()
focal_class.declarator: allowedHostnames
focal_class.modifier: private final
focal_class.original_string: private final Collection<String> allowedHostnames;
focal_class.type: Collection<String>
focal_class.var_name: allowedHostnames
focal_class.declarator: blockedAddresses
focal_class.modifier: private final
focal_class.original_string: private final Collection<InetAddress> blockedAddresses;
focal_class.type: Collection<InetAddress>
focal_class.var_name: blockedAddresses
focal_class.declarator: resolver
focal_class.modifier: private final
focal_class.original_string: private final AddressResolver resolver;
focal_class.type: AddressResolver
focal_class.var_name: resolver
focal_class.file: services/connectivity/messaging/src/main/java/org/eclipse/ditto/services/connectivity/messaging/validation/HostValidator.java
focal_class.identifier: HostValidator
focal_class.class_method_signature: HostValidator.HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter)
focal_class.full_signature:   HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter)
focal_class.identifier: HostValidator
focal_class.parameters: (final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter)
focal_class.signature:  HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter)
focal_class.class_method_signature: HostValidator.HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter,
              final AddressResolver resolver)
focal_class.full_signature:   HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter,
              final AddressResolver resolver)
focal_class.identifier: HostValidator
focal_class.parameters: (final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter,
              final AddressResolver resolver)
focal_class.signature:  HostValidator(final ConnectivityConfig connectivityConfig, final LoggingAdapter loggingAdapter,
              final AddressResolver resolver)
focal_class.class_method_signature: HostValidator.validateHost(final String host)
focal_class.full_signature:  HostValidationResult validateHost(final String host)
focal_class.identifier: validateHost
focal_class.parameters: (final String host)
focal_class.return: HostValidationResult
focal_class.signature: HostValidationResult validateHost(final String host)
focal_class.class_method_signature: HostValidator.calculateBlockedAddresses(final Collection<String> blockedHostnames,
              final LoggingAdapter log)
focal_class.full_signature: private Collection<InetAddress> calculateBlockedAddresses(final Collection<String> blockedHostnames,
              final LoggingAdapter log)
focal_class.identifier: calculateBlockedAddresses
focal_class.modifiers: private
focal_class.parameters: (final Collection<String> blockedHostnames,
              final LoggingAdapter log)
focal_class.return: Collection<InetAddress>
focal_class.signature: Collection<InetAddress> calculateBlockedAddresses(final Collection<String> blockedHostnames,
              final LoggingAdapter log)
focal_class.class_method_signature: HostValidator.validateHostname(final String connectionHost, final DittoHeaders dittoHeaders)
focal_class.full_signature:  void validateHostname(final String connectionHost, final DittoHeaders dittoHeaders)
focal_class.identifier: validateHostname
focal_class.parameters: (final String connectionHost, final DittoHeaders dittoHeaders)
focal_class.return: void
focal_class.signature: void validateHostname(final String connectionHost, final DittoHeaders dittoHeaders)
focal_method.body: HostValidationResult validateHost(final String host) {
          if (blockedAddresses.isEmpty()) {
              // If not even localhost is blocked, then permit even private, loopback, multicast and wildcard IPs.
              return HostValidationResult.valid();
          } else if (allowedHostnames.contains(host)) {
              // the host is contained in the allow-list, do not block
              return HostValidationResult.valid();
          } else {
              // Forbid blocked, private, loopback, multicast and wildcard IPs.
              try {
                  final InetAddress[] inetAddresses = resolver.resolve(host);
                  for (final InetAddress requestAddress : inetAddresses) {
                      if (requestAddress.isLoopbackAddress()) {
                          return HostValidationResult.blocked(host, "the hostname resolved to a loopback address.");
                      } else if (requestAddress.isSiteLocalAddress()) {
                          return HostValidationResult.blocked(host, "the hostname resolved to a site local address.");
                      } else if (requestAddress.isMulticastAddress()) {
                          return HostValidationResult.blocked(host, "the hostname resolved to a multicast address.");
                      } else if (requestAddress.isAnyLocalAddress()) {
                          return HostValidationResult.blocked(host, "the hostname resolved to a wildcard address.");
                      } else if (blockedAddresses.contains(requestAddress)) {
                          // host is contained in the blocklist --> block
                          return HostValidationResult.blocked(host);
                      }
                  }
                  return HostValidationResult.valid();
              } catch (UnknownHostException e) {
                  final String reason = String.format("The configured host '%s' is invalid: %s", host, e.getMessage());
                  return HostValidationResult.invalid(host, reason);
              }
          }
      }
focal_method.class_method_signature: HostValidator.validateHost(final String host)
focal_method.full_signature:  HostValidationResult validateHost(final String host)
focal_method.identifier: validateHost
focal_method.invocations: isEmpty valid contains valid resolve isLoopbackAddress blocked isSiteLocalAddress blocked isMulticastAddress blocked isAnyLocalAddress blocked contains blocked valid format getMessage invalid
focal_method.parameters: (final String host)
focal_method.return: HostValidationResult
focal_method.signature: HostValidationResult validateHost(final String host)