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 @@ -18,7 +18,7 @@
import static tech.pegasys.teku.infrastructure.restapi.SwaggerUIBuilder.SWAGGER_INITIALIZER_JS;

import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -79,18 +79,18 @@ private static Set<String> findAssets(final String url) throws IOException {
Document doc =
Jsoup.connect(url).data("query", "Java").userAgent("Mozilla").timeout(3000).get();

final URL baseUrl = new URL(url);
final URI baseUrl = URI.create(url);

// Resources
Elements resources = doc.select("link[href]");
for (Element element : resources) {
links.add(new URL(baseUrl, element.attr("href")).getPath());
links.add(baseUrl.resolve(element.attr("href")).getPath());
}

// Scripts
Elements scripts = doc.select("script");
for (Element element : scripts) {
links.add(new URL(baseUrl, element.attr("src")).getPath());
links.add(baseUrl.resolve(element.attr("src")).getPath());
}

return links;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.UpnpService;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void registryListenerShouldDetectService() throws Exception {
new RemoteDeviceIdentity(
UDN.valueOf(NatManager.SERVICE_TYPE_WAN_IP_CONNECTION),
3600,
new URL("http://127.63.31.15/"),
URI.create("http://127.63.31.15/").toURL(),
null,
InetAddress.getByName("127.63.31.15")),
new UDADeviceType("WANConnectionDevice"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.base.Strings;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -225,8 +226,8 @@ private URL parseMetricsEndpointUrl() {
return null;
}
try {
return new URL(metricsEndpoint);
} catch (MalformedURLException e) {
return URI.create(metricsEndpoint).toURL();
} catch (IllegalArgumentException | MalformedURLException e) {
throw new InvalidConfigurationException(
"Invalid configuration. Metrics Endpoint has invalid syntax", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.base.Strings;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Duration;
Expand Down Expand Up @@ -131,8 +132,8 @@ private URL parseValidatorExternalSignerUrl() {
return null;
}
try {
return new URL(validatorExternalSignerUrl);
} catch (MalformedURLException e) {
return URI.create(validatorExternalSignerUrl).toURL();
} catch (IllegalArgumentException | MalformedURLException e) {
throw new InvalidConfigurationException(
"Invalid configuration. Signer URL has invalid syntax", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static tech.pegasys.teku.validator.api.ValidatorConfig.DEFAULT_BUILDER_REGISTRATION_GAS_LIMIT;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.time.Duration;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
Expand Down Expand Up @@ -48,7 +48,8 @@ public void shouldReadFromConfigurationFile() throws MalformedURLException {
assertThat(config.getValidatorExternalSignerPublicKeySources())
.containsExactly(
"0xad113a7d152dc74ae2b26db65bfb89ed07501c818bf47671c6d34e5a2f7224e4c5525dd4fddaa93aa328da86b7205009");
assertThat(config.getValidatorExternalSignerUrl()).isEqualTo(new URL("https://signer.url/"));
assertThat(config.getValidatorExternalSignerUrl())
.isEqualTo(URI.create("https://signer.url/").toURL());
assertThat(config.getValidatorExternalSignerTimeout()).isEqualTo(Duration.ofMillis(1234));
assertThat(config.getGraffitiProvider().get()).isEqualTo(Optional.of(graffiti));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package tech.pegasys.teku.validator.client.signer;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.http.HttpClient;
import java.time.Duration;
import java.util.List;
Expand Down Expand Up @@ -60,7 +60,8 @@ void setup(final ClientAndServer client) throws MalformedURLException {
final ValidatorConfig config =
ValidatorConfig.builder()
.validatorExternalSignerPublicKeySources(List.of(KEYPAIR.getPublicKey().toString()))
.validatorExternalSignerUrl(new URL("http://127.0.0.1:" + client.getLocalPort()))
.validatorExternalSignerUrl(
URI.create("http://127.0.0.1:" + client.getLocalPort()).toURL())
.validatorExternalSignerTimeout(TIMEOUT)
.build();
final Supplier<HttpClient> externalSignerHttpClientFactory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.io.Resources;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpClient;
Expand Down Expand Up @@ -126,6 +127,6 @@ void tearDown() {
}

protected URL getUrl() throws MalformedURLException {
return new URL("https://127.0.0.1:" + client.getLocalPort());
return URI.create("https://127.0.0.1:" + client.getLocalPort()).toURL();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.base.Splitter;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
Expand All @@ -37,8 +38,9 @@ public class ExternalSignerBasicAuthIntegrationTest

@Override
protected URL getUrl() throws MalformedURLException {
return new URL(
String.format("https://%s:%s@127.0.0.1:%s", username, password, client.getLocalPort()));
return URI.create(
String.format("https://%s:%s@127.0.0.1:%s", username, password, client.getLocalPort()))
.toURL();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static org.mockserver.model.HttpResponse.response;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import org.junit.jupiter.api.Test;

public class ExternalSignerUpcheckTLSIntegrationTest
Expand Down Expand Up @@ -48,7 +48,7 @@ void upcheckReturnsFalseWhenServerIsDown() throws MalformedURLException {
new ExternalSignerUpcheck(
externalSignerHttpClientFactory.get(),
// an unused port
new URL("https://127.0.0.1:79"),
URI.create("https://127.0.0.1:79").toURL(),
validatorConfig.getValidatorExternalSignerTimeout());
assertThat(externalSignerUpcheck.upcheck()).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public List<BLSPublicKey> getPublicKeys(final List<String> sources) {

private Stream<BLSPublicKey> readKeysFromUrl(final String url) {
try {
final String[] keys = objectMapper.readValue(new URL(url), String[].class);
final String[] keys = objectMapper.readValue(URI.create(url).toURL(), String[].class);
return Arrays.stream(keys).map(key -> BLSPublicKey.fromSSZBytes(Bytes.fromHexString(key)));
} catch (IOException ex) {
} catch (IllegalArgumentException | IOException ex) {
throw new InvalidConfigurationException("Failed to load public keys from URL " + url, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
Expand All @@ -36,10 +37,10 @@ static ProposerConfigProvider create(
if (source.isPresent()) {
URL sourceUrl;
try {
sourceUrl = new URL(source.get());
sourceUrl = URI.create(source.get()).toURL();
return new UrlProposerConfigProvider(
asyncRunner, refresh, proposerConfigLoader, timeProvider, sourceUrl);
} catch (MalformedURLException e1) {
} catch (IllegalArgumentException | MalformedURLException e1) {
try {
sourceUrl = new File(source.get()).toURI().toURL();
} catch (MalformedURLException e2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition.listOf;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -111,7 +112,7 @@ public class ValidatorTypes {
.parser(
url -> {
try {
return new URL(url);
return URI.create(url).toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -274,9 +275,13 @@ void shouldReturnRemoteValidatorsList() throws MalformedURLException {
List<ExternalValidator> externalValidators =
Arrays.asList(
new ExternalValidator(
keyPair1.getPublicKey(), Optional.of(new URL("http://example.com/")), true),
keyPair1.getPublicKey(),
Optional.of(URI.create("http://example.com/").toURL()),
true),
new ExternalValidator(
keyPair2.getPublicKey(), Optional.of(new URL("http://example.com/")), false));
keyPair2.getPublicKey(),
Optional.of(URI.create("http://example.com/").toURL()),
false));
assertThat(result).isEqualTo(externalValidators);
}

Expand Down Expand Up @@ -404,7 +409,8 @@ void shouldAddLocalKeysWhenDoppelgangerDetectionException()
@Test
void shouldDetectDoppelgangerAndIgnoreExternalKey() throws MalformedURLException {

when(signer.getSigningServiceUrl()).thenReturn(Optional.of(new URL("https://url.test")));
when(signer.getSigningServiceUrl())
.thenReturn(Optional.of(URI.create("https://url.test").toURL()));

ExternalValidatorImportResult externalDoppelgangerImportResult =
new ExternalValidatorImportResult.Builder(
Expand Down Expand Up @@ -456,7 +462,8 @@ void shouldDetectDoppelgangerAndIgnoreExternalKey() throws MalformedURLException

@Test
void shouldAddExternalKeysWhenDoppelgangerDetectionException() throws MalformedURLException {
when(signer.getSigningServiceUrl()).thenReturn(Optional.of(new URL("https://url.test")));
when(signer.getSigningServiceUrl())
.thenReturn(Optional.of(URI.create("https://url.test").toURL()));

ExternalValidatorImportResult doppelgangerImportResult =
new ExternalValidatorImportResult.Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.common.base.Charsets;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpResponse;
Expand Down Expand Up @@ -81,7 +82,7 @@ public ExternalValidatorSourceTest() {}
void setup(@TempDir final Path tempDir) throws IOException, InterruptedException {
config =
ValidatorConfig.builder()
.validatorExternalSignerUrl(new URL("http://localhost:9000"))
.validatorExternalSignerUrl(URI.create("http://localhost:9000").toURL())
.build();
externalSignerTaskQueue =
ThrottlingTaskQueueWithPriority.create(
Expand Down Expand Up @@ -117,7 +118,7 @@ void shouldDeleteValidator(@TempDir final Path tempDir) throws IOException {

final AddValidatorResult addValidatorResult =
externalValidatorSource.addValidator(publicKey, Optional.empty());
assertImportedSuccessfully(addValidatorResult, new URL("http://localhost:9000"));
assertImportedSuccessfully(addValidatorResult, URI.create("http://localhost:9000").toURL());
assertFileContent(tempDir, publicKey, "{\"pubkey\":\"" + publicKey + "\"}");

final DeleteKeyResult result = externalValidatorSource.deleteValidator(publicKey);
Expand Down Expand Up @@ -167,7 +168,7 @@ void addValidator_shouldGetConfigUrlWhenNotProvided(@TempDir final Path tempDir)
@Test
void addValidator_shouldGetUrlIfProvided(@TempDir final Path tempDir) throws IOException {
final BLSPublicKey publicKey = dataStructureUtil.randomPublicKey();
final URL url = new URL("http://host.com");
final URL url = URI.create("http://host.com").toURL();

final ExternalValidatorSource externalValidatorSource =
newExternalValidatorSource(tempDir, false);
Expand Down Expand Up @@ -204,7 +205,8 @@ void shouldLoadExternalValidators(@TempDir final Path tempDir) throws IOExceptio
newExternalValidatorSource(tempDir, false);

final BLSPublicKey publicKey1 = dataStructureUtil.randomPublicKey();
createRemoteKeyFile(dataDirLayout, publicKey1, Optional.of(new URL("http://host.com")));
createRemoteKeyFile(
dataDirLayout, publicKey1, Optional.of(URI.create("http://host.com").toURL()));

final BLSPublicKey publicKey2 = dataStructureUtil.randomPublicKey();
createRemoteKeyFile(dataDirLayout, publicKey2, Optional.empty());
Expand All @@ -225,8 +227,8 @@ void shouldLoadExternalValidators(@TempDir final Path tempDir) throws IOExceptio

assertThat(result)
.containsExactlyInAnyOrder(
new ValidatorProviderInfo(publicKey1, new URL("http://host.com")),
new ValidatorProviderInfo(publicKey2, new URL("http://localhost:9000")));
new ValidatorProviderInfo(publicKey1, URI.create("http://host.com").toURL()),
new ValidatorProviderInfo(publicKey2, URI.create("http://localhost:9000").toURL()));
}

@Test
Expand All @@ -253,8 +255,8 @@ void shouldGetAvailableReadOnlyValidators(@TempDir final Path tempDir) throws IO

assertThat(result)
.containsExactlyInAnyOrder(
new ValidatorProviderInfo(publicKey1, new URL("http://localhost:9000")),
new ValidatorProviderInfo(publicKey2, new URL("http://localhost:9000")));
new ValidatorProviderInfo(publicKey1, URI.create("http://localhost:9000").toURL()),
new ValidatorProviderInfo(publicKey2, URI.create("http://localhost:9000").toURL()));
}

private void createRemoteKeyFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
import java.net.http.HttpClient;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class PublicKeyLoaderTest {
private final BLSPublicKey secondKey =
BLSPublicKey.fromBytesCompressed(Bytes48.fromHexString(secondKeyStr));

private final URL externalSignerUrl = new URL("http://external.sigener");
private final URL externalSignerUrl = URI.create("http://external.sigener").toURL();
private final ObjectMapper mapper = mock(ObjectMapper.class);
private final HttpClient httpClient = mock(HttpClient.class);

Expand All @@ -71,7 +72,7 @@ public PublicKeyLoaderTest() throws MalformedURLException {}
void setUp() throws IOException, InterruptedException {
// URL response
final String[] values = {firstKeyStr, secondKeyStr};
when(mapper.readValue(new URL(urlSource), String[].class)).thenReturn(values);
when(mapper.readValue(URI.create(urlSource).toURL(), String[].class)).thenReturn(values);

// external signer response
final String jsonValues = String.format("[%s, %s]", firstKeyStr, secondKeyStr);
Expand Down Expand Up @@ -116,14 +117,14 @@ void shouldHandleDuplicatesAcrossSources() {
@Test
void shouldHandleEmptyResponseFromUrl() throws IOException {
final String[] values = {};
when(mapper.readValue(new URL(urlSource), String[].class)).thenReturn(values);
when(mapper.readValue(URI.create(urlSource).toURL(), String[].class)).thenReturn(values);
assertThat(loader.getPublicKeys(List.of(urlSource, secondKeyStr))).containsExactly(secondKey);
}

@Test
void shouldThrowInvalidConfigurationExceptionWhenUrlFailsToLoad() throws Exception {
final UnknownHostException exception = new UnknownHostException("Unknown host");
when(mapper.readValue(new URL(urlSource), String[].class)).thenThrow(exception);
when(mapper.readValue(URI.create(urlSource).toURL(), String[].class)).thenThrow(exception);
assertThatThrownBy(() -> loader.getPublicKeys(List.of(urlSource)))
.isInstanceOf(InvalidConfigurationException.class)
.hasRootCause(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.mockito.Mockito.when;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.http.HttpClient;
import java.time.Duration;
import java.util.ArrayList;
Expand Down Expand Up @@ -168,7 +168,7 @@ private Validator createUnProtectedValidator(final BLSPublicKey publicKey) {
new ExternalSigner(
spec,
mock(HttpClient.class),
new URL("http://127.0.0.1/"),
URI.create("http://127.0.0.1/").toURL(),
publicKey,
TIMEOUT,
mock(ThrottlingTaskQueueWithPriority.class),
Expand Down
Loading