allow domain names with dashes in ethstats (#1379)

The NETSTATS_URL_REGEX allows domain names but only allows dots, letters and numbers.
Modified the NETSTATS_URL_REGEX to allow dashes

Signed-off-by: Roderik van der Veer <roderik@settlemint.com>

Co-authored-by: matkt <karim.t2am@gmail.com>
pull/1382/head
Roderik van der Veer 4 years ago committed by GitHub
parent f89f7ee660
commit fd98049969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/NetstatsUrl.java
  2. 11
      ethereum/ethstats/src/test/java/org/hyperledger/besu/ethstats/util/NetstatsUrlTest.java

@ -26,7 +26,7 @@ import org.immutables.value.Value;
@Value.Immutable @Value.Immutable
public interface NetstatsUrl { public interface NetstatsUrl {
Pattern NETSTATS_URL_REGEX = Pattern.compile("([-\\w]+):([\\w]+)?@([.\\w]+):([\\d]+)"); Pattern NETSTATS_URL_REGEX = Pattern.compile("([-\\w]+):([\\w]+)?@([-.\\w]+):([\\d]+)");
String getNodeName(); String getNodeName();

@ -38,6 +38,17 @@ public class NetstatsUrlTest {
assertThat(netstatsUrl.getContact()).isEqualTo(CONTACT); assertThat(netstatsUrl.getContact()).isEqualTo(CONTACT);
} }
@Test
public void buildWithValidHost() {
final String[] validHosts =
new String[] {"url-test.test.com", "url.test.com", "test.com", "10.10.10.15"};
for (String host : validHosts) {
final NetstatsUrl netstatsUrl =
NetstatsUrl.fromParams("Dev-Node-1:secret@" + host + ":3001", CONTACT);
assertThat(netstatsUrl.getHost()).isEqualTo(host);
}
}
@Test @Test
public void shouldDetectEmptyParams() { public void shouldDetectEmptyParams() {
assertThatThrownBy(() -> NetstatsUrl.fromParams("", CONTACT)) assertThatThrownBy(() -> NetstatsUrl.fromParams("", CONTACT))

Loading…
Cancel
Save