Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ protected boolean isManagementPortEqual() {

protected String getServiceHost() {
InetAddress address = this.server.getAddress();
if (address == null) {
if (address == null || address.isAnyLocalAddress()) {
address = getLocalHost();
}
return getHost(address);
}

protected String getManagementHost() {
InetAddress address = this.management.getAddress();
if (address != null) {
if (address != null && !address.isAnyLocalAddress()) {
return getHost(address);
}
return getServiceHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.EndpointId;
Expand Down Expand Up @@ -132,6 +134,24 @@ void test_preferIpAddress_management_address_missing() {
assertThat(app.getManagementUrl()).matches("http://\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}:8081/actuator");
}

@ParameterizedTest
@ValueSource(strings = { "0.0.0.0", "::" })
void should_advertise_a_host_when_listening_on_all_interfaces(String wildcard) throws UnknownHostException {
instanceProperties.setPreferIp(true);
when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
publishApplicationReadyEvent(factory, 8080, 8081);

Application expected = factory.createApplication();
server.setAddress(InetAddress.getByName(wildcard));
management.setAddress(InetAddress.getByName(wildcard));
Application app = factory.createApplication();
assertThat(app.getServiceUrl()).isEqualTo(expected.getServiceUrl());
assertThat(app.getHealthUrl()).isEqualTo(expected.getHealthUrl());

server.setAddress(InetAddress.getByName("192.0.2.12"));
assertThat(factory.createApplication().getManagementUrl()).isEqualTo("http://192.0.2.12:8081/actuator");
}

@Test
void test_preferIpAddress() throws UnknownHostException {
instanceProperties.setPreferIp(true);
Expand Down
Loading