use of tech.pegasys.web3signer.core.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(any())).thenReturn(artifactSigner);
final List<ArtifactSigner> signerList = Lists.newArrayList(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));
}
use of tech.pegasys.web3signer.core.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(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
assertThat(signerList.size()).isOne();
assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY2);
verify(signerParser, never()).parse(yamlContentKey1);
verify(signerParser).parse(Files.readString(key2, StandardCharsets.UTF_8));
}
use of tech.pegasys.web3signer.core.signing.ArtifactSigner in project web3signer by ConsenSys.
the class SignerLoaderTest method signerReturnedWhenIdentifierHasCaseMismatchToFilename.
@Test
void signerReturnedWhenIdentifierHasCaseMismatchToFilename() throws IOException {
final String filename = "arbitraryFilename." + FILE_EXTENSION;
final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
when(signerParser.parse(any())).thenReturn(artifactSigner);
final List<ArtifactSigner> signerList = Lists.newArrayList(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));
}
use of tech.pegasys.web3signer.core.signing.ArtifactSigner in project web3signer by ConsenSys.
the class SignerLoaderTest method signerReturnedForValidMetadataFile.
@Test
void signerReturnedForValidMetadataFile() throws IOException {
final String filename = PUBLIC_KEY1 + "." + FILE_EXTENSION;
final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
when(signerParser.parse(Files.readString(metadataFile, StandardCharsets.UTF_8))).thenReturn(artifactSigner);
final List<ArtifactSigner> signerList = Lists.newArrayList(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
verify(signerParser).parse(Files.readString(metadataFile, StandardCharsets.UTF_8));
assertThat(signerList.size()).isOne();
assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY1);
}
use of tech.pegasys.web3signer.core.signing.ArtifactSigner in project web3signer by ConsenSys.
the class YamlSignerParserTest method azureSecretMetadataInfoReturnsMetadata.
@Test
void azureSecretMetadataInfoReturnsMetadata() throws IOException {
final BlsArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.AZURE);
when(blsArtifactSignerFactory.create(any(AzureSecretSigningMetadata.class))).thenReturn(artifactSigner);
final Map<String, String> azureMetaDataMap = new HashMap<>();
azureMetaDataMap.put("type", "azure-secret");
azureMetaDataMap.put("clientId", "sample-client-id");
azureMetaDataMap.put("clientSecret", "sample-client-secret");
azureMetaDataMap.put("tenantId", "sample-tenant-id");
azureMetaDataMap.put("vaultName", "sample-vault-name");
azureMetaDataMap.put("secretName", "TEST-KEY");
azureMetaDataMap.put("keyType", "BLS");
final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
assertThat(result).containsOnly(artifactSigner);
verify(blsArtifactSignerFactory).create(hasCorrectAzureMetadataArguments(AzureAuthenticationMode.CLIENT_SECRET));
}
Aggregations