use of tech.pegasys.web3signer.dsl.signer.SignerConfiguration in project web3signer by ConsenSys.
the class HttpHostAllowListAcceptanceTest method httpEndpointForNonAllowedHostRespondsWithForbiddenResponse.
@Test
void httpEndpointForNonAllowedHostRespondsWithForbiddenResponse() {
final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withHttpAllowHostList(Collections.singletonList("127.0.0.1")).withMode("eth2").build();
startSigner(signerConfiguration);
given().baseUri(signer.getUrl()).contentType(ContentType.JSON).when().header("Host", "bar").get(UPCHECK_ENDPOINT).then().assertThat().statusCode(403);
}
use of tech.pegasys.web3signer.dsl.signer.SignerConfiguration in project web3signer by ConsenSys.
the class HttpHostAllowListAcceptanceTest method httpEndpointForAllowedHostRespondsWithOkResponse.
@Test
void httpEndpointForAllowedHostRespondsWithOkResponse() {
final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withHttpAllowHostList(Collections.singletonList("127.0.0.1, foo")).withMode("eth2").build();
startSigner(signerConfiguration);
given().baseUri(signer.getUrl()).contentType(ContentType.JSON).when().header("Host", "foo").get(UPCHECK_ENDPOINT).then().assertThat().statusCode(200);
}
use of tech.pegasys.web3signer.dsl.signer.SignerConfiguration in project web3signer by ConsenSys.
the class MetricsAcceptanceTest method signMetricIncrementsWhenSecpSignRequestReceived.
@Test
void signMetricIncrementsWhenSecpSignRequestReceived(@TempDir Path testDirectory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
final MetadataFileHelpers fileHelpers = new MetadataFileHelpers();
final ECKeyPair keyPair = Keys.createEcKeyPair();
fileHelpers.createUnencryptedYamlFileAt(testDirectory.resolve(keyPair.getPublicKey().toString() + ".yaml"), Numeric.toHexStringWithPrefixZeroPadded(keyPair.getPrivateKey(), 64), SECP256K1);
final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("SIGNING").withMetricsEnabled(true).withKeyStoreDirectory(testDirectory).withMode("eth1").build();
startSigner(signerConfiguration);
final List<String> metricsOfInterest = List.of("signing_" + SECP256K1.name().toLowerCase() + "_signing_duration_count", "signing_" + SECP256K1.name().toLowerCase() + "_missing_identifier_count");
final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
assertThat(initialMetrics).hasSize(metricsOfInterest.size());
assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
signer.eth1Sign(Numeric.toHexStringWithPrefixZeroPadded(keyPair.getPublicKey(), 128), Bytes.fromHexString("1122"));
final Set<String> metricsAfterSign = signer.getMetricsMatching(metricsOfInterest);
assertThat(metricsAfterSign).containsOnly("signing_" + SECP256K1.name().toLowerCase() + "_signing_duration_count 1.0", "signing_" + SECP256K1.name().toLowerCase() + "_missing_identifier_count 0.0");
}
use of tech.pegasys.web3signer.dsl.signer.SignerConfiguration in project web3signer by ConsenSys.
the class MetricsAcceptanceTest method filecoinApisAreCounted.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void filecoinApisAreCounted(final boolean useConfigFile) {
final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("FILECOIN").withMetricsEnabled(true).withMode("filecoin").withUseConfigFile(useConfigFile).build();
startSigner(signerConfiguration);
final List<String> metricsOfInterest = List.of("filecoin_" + SECP256K1.name().toLowerCase() + "_signing_request_count", "filecoin_" + BLS.name().toLowerCase() + "_signing_request_count", "filecoin_total_request_count", "filecoin_wallet_has_count", "filecoin_wallet_list_count", "filecoin_wallet_sign_message_count");
final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
assertThat(initialMetrics).hasSize(metricsOfInterest.size());
assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
signer.walletHas("t01234");
final Set<String> metricsAfterWalletHas = signer.getMetricsMatching(metricsOfInterest);
metricsAfterWalletHas.removeAll(initialMetrics);
assertThat(metricsAfterWalletHas).containsOnly("filecoin_total_request_count 1.0", "filecoin_wallet_has_count 1.0");
signer.walletList();
final Set<String> metricsAfterWalletList = signer.getMetricsMatching(metricsOfInterest);
metricsAfterWalletList.removeAll(initialMetrics);
metricsAfterWalletList.removeAll(metricsAfterWalletHas);
assertThat(metricsAfterWalletList).containsOnly("filecoin_total_request_count 2.0", "filecoin_wallet_list_count 1.0");
try {
signer.walletSign("t01234", Bytes.fromHexString("0x1234"));
} catch (final Exception e) {
// it is known that the signing will fail.
}
final Set<String> metricsAfterWalletSign = signer.getMetricsMatching(metricsOfInterest);
metricsAfterWalletSign.removeAll(initialMetrics);
metricsAfterWalletSign.removeAll(metricsAfterWalletList);
metricsAfterWalletSign.removeAll(metricsAfterWalletHas);
assertThat(metricsAfterWalletSign).containsOnly("filecoin_total_request_count 3.0");
}
use of tech.pegasys.web3signer.dsl.signer.SignerConfiguration in project web3signer by ConsenSys.
the class MetricsAcceptanceTest method signMetricIncrementsWhenBlsSignRequestReceived.
@Test
void signMetricIncrementsWhenBlsSignRequestReceived(@TempDir Path testDirectory) throws JsonProcessingException {
final MetadataFileHelpers fileHelpers = new MetadataFileHelpers();
final BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(1);
fileHelpers.createUnencryptedYamlFileAt(testDirectory.resolve(keyPair.getPublicKey().toBytesCompressed().toHexString() + ".yaml"), keyPair.getSecretKey().toBytes().toHexString(), BLS);
final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("SIGNING").withMetricsEnabled(true).withKeyStoreDirectory(testDirectory).withMode("eth2").build();
startSigner(signerConfiguration);
final List<String> metricsOfInterest = List.of("signing_" + BLS.name().toLowerCase() + "_signing_duration_count", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count");
final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
assertThat(initialMetrics).hasSize(metricsOfInterest.size());
assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
signer.eth2Sign(keyPair.getPublicKey().toBytesCompressed().toHexString(), Eth2RequestUtils.createBlockRequest(UInt64.valueOf(1), Bytes32.fromHexString("0x1111")));
final Set<String> metricsAfterSign = signer.getMetricsMatching(metricsOfInterest);
assertThat(metricsAfterSign).containsOnly("signing_" + BLS.name().toLowerCase() + "_signing_duration_count 1.0", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count 0.0");
}
Aggregations