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);
}
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);
}
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));
}
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();
}
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));
}
Aggregations