Search in sources :

Example 6 with ArtifactSigner

use of tech.pegasys.web3signer.signing.ArtifactSigner in project web3signer by ConsenSys.

the class DefaultArtifactSignerProviderTest method signerReturnedForMatchingIdentifer.

@Test
void signerReturnedForMatchingIdentifer() {
    final ArtifactSigner mockSigner = mock(ArtifactSigner.class);
    when(mockSigner.getIdentifier()).thenReturn(PUBLIC_KEY1);
    signerProvider = new DefaultArtifactSignerProvider(() -> List.of(mockSigner));
    assertThatCode(() -> signerProvider.load().get()).doesNotThrowAnyException();
    final Optional<ArtifactSigner> signer = signerProvider.getSigner(PUBLIC_KEY1);
    assertThat(signer).isNotEmpty();
    assertThat(signerProvider.availableIdentifiers()).containsOnly(PUBLIC_KEY1);
}
Also used : ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 7 with ArtifactSigner

use of tech.pegasys.web3signer.signing.ArtifactSigner in project web3signer by ConsenSys.

the class DefaultArtifactSignerProviderTest method signerProviderCanMapInTwoSigners.

@Test
void signerProviderCanMapInTwoSigners() {
    final ArtifactSigner mockSigner1 = mock(ArtifactSigner.class);
    when(mockSigner1.getIdentifier()).thenReturn(PUBLIC_KEY1);
    final ArtifactSigner mockSigner2 = mock(ArtifactSigner.class);
    when(mockSigner2.getIdentifier()).thenReturn(PUBLIC_KEY2);
    signerProvider = new DefaultArtifactSignerProvider(() -> List.of(mockSigner1, mockSigner2));
    assertThatCode(() -> signerProvider.load().get()).doesNotThrowAnyException();
    assertThat(signerProvider.availableIdentifiers()).hasSize(2);
    assertThat(signerProvider.availableIdentifiers()).containsOnly(PUBLIC_KEY1, PUBLIC_KEY2);
}
Also used : ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 8 with ArtifactSigner

use of tech.pegasys.web3signer.signing.ArtifactSigner in project web3signer by ConsenSys.

the class SignerLoaderTest method signerIdentifiersNotReturnedForHiddenFiles.

@Test
void signerIdentifiersNotReturnedForHiddenFiles() throws IOException {
    final Path key1 = createFileInConfigsDirectory(PUBLIC_KEY1 + "." + FILE_EXTENSION, PRIVATE_KEY1);
    FileHiddenUtil.makeFileHidden(key1);
    final Path key2 = createFileInConfigsDirectory(PUBLIC_KEY2 + "." + FILE_EXTENSION, PRIVATE_KEY2);
    // Using lenient so it's clear key is not returned due file being hidden instead no stub
    final Map<String, String> unencryptedKeyMetadataFile = new HashMap<>();
    unencryptedKeyMetadataFile.put("type", "file-raw");
    unencryptedKeyMetadataFile.put("privateKey", "0x" + PRIVATE_KEY1);
    final String yamlContentKey1 = YAML_OBJECT_MAPPER.writeValueAsString(unencryptedKeyMetadataFile);
    lenient().when(signerParser.parse(yamlContentKey1)).thenReturn(createArtifactSigner(PRIVATE_KEY1));
    when(signerParser.parse(Files.readString(key2, StandardCharsets.UTF_8))).thenReturn(createArtifactSigner(PRIVATE_KEY2));
    final List<ArtifactSigner> signerList = Lists.newArrayList(new SignerLoader().load(configsDirectory, FILE_EXTENSION, signerParser));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY2);
    verify(signerParser, Mockito.never()).parse(yamlContentKey1);
    verify(signerParser).parse(Files.readString(key2, StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 9 with ArtifactSigner

use of tech.pegasys.web3signer.signing.ArtifactSigner in project web3signer by ConsenSys.

the class SignerLoaderTest method failedWithDirectoryErrorReturnEmptySigner.

@Test
void failedWithDirectoryErrorReturnEmptySigner() throws IOException {
    final Path missingDir = configsDirectory.resolve("idontexist");
    createFileInConfigsDirectory(PUBLIC_KEY1 + "." + FILE_EXTENSION, PRIVATE_KEY1);
    final List<ArtifactSigner> signerList = Lists.newArrayList(new SignerLoader().load(missingDir, FILE_EXTENSION, signerParser));
    assertThat(signerList).isEmpty();
}
Also used : Path(java.nio.file.Path) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 10 with ArtifactSigner

use of tech.pegasys.web3signer.signing.ArtifactSigner in project web3signer by ConsenSys.

the class SignerLoaderTest method signerReturnedWhenFileExtensionIsUpperCase.

@Test
void signerReturnedWhenFileExtensionIsUpperCase() throws IOException {
    final String filename = PUBLIC_KEY1 + ".YAML";
    final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
    when(signerParser.parse(ArgumentMatchers.any())).thenReturn(artifactSigner);
    final List<ArtifactSigner> signerList = Lists.newArrayList(new SignerLoader().load(configsDirectory, FILE_EXTENSION, signerParser));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY1);
    verify(signerParser).parse(Files.readString(metadataFile, StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) Test(org.junit.jupiter.api.Test)

Aggregations

ArtifactSigner (tech.pegasys.web3signer.signing.ArtifactSigner)22 Test (org.junit.jupiter.api.Test)18 BlsArtifactSigner (tech.pegasys.web3signer.signing.BlsArtifactSigner)17 Path (java.nio.file.Path)10 HashMap (java.util.HashMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)6 AzureSecretSigningMetadata (tech.pegasys.web3signer.signing.config.metadata.AzureSecretSigningMetadata)3 Bytes (org.apache.tuweni.bytes.Bytes)2 FileRawSigningMetadata (tech.pegasys.web3signer.signing.config.metadata.FileRawSigningMetadata)2 JsonRpcMethod (com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 AwsSecretsManagerProvider (tech.pegasys.signers.aws.AwsSecretsManagerProvider)1 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)1 ArtifactSignature (tech.pegasys.web3signer.signing.ArtifactSignature)1 BlsArtifactSignature (tech.pegasys.web3signer.signing.BlsArtifactSignature)1