Search in sources :

Example 1 with SignerConfiguration

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);
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with SignerConfiguration

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);
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with SignerConfiguration

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");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) ECKeyPair(org.web3j.crypto.ECKeyPair) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) MetadataFileHelpers(tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SignerConfiguration

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");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SignerConfiguration

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");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) MetadataFileHelpers(tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SignerConfiguration (tech.pegasys.web3signer.dsl.signer.SignerConfiguration)11 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)11 Test (org.junit.jupiter.api.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 MetadataFileHelpers (tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 ECKeyPair (org.web3j.crypto.ECKeyPair)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)1 Signer (tech.pegasys.web3signer.dsl.signer.Signer)1