Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Update hardcoded Azure values (#521)
Browse files Browse the repository at this point in the history
* Change hardcoded values
* Remove duplication from hardcoded values
  • Loading branch information
siladu authored Jul 28, 2023
1 parent 5f57ac3 commit d2f5443
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
public class AcceptanceTestBase {

private static final String ENCLAVE_PUBLIC_KEY_FILENAME = "enclave_key.pub";
public static final String AZURE_PUBLIC_KEY = "3d93035f56685fd609415654beccfcaf166ea382";
public static final String AZURE_GENESIS_ACCOUNT_ONE_PUBLIC_KEY = "0x" + AZURE_PUBLIC_KEY;

private static Node ethNode;
private static Signer ethSigner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TransactionSignerParamsSupplier {
private final HashicorpSigningParams hashicorpNode;
private final String azureKeyVault;
private final Path multiKeySignerDirectory;
public static final String AZURE_KEY_NAME = "TestKey2";

public TransactionSignerParamsSupplier(
final HashicorpSigningParams hashicorpNode,
Expand Down Expand Up @@ -81,7 +82,7 @@ public Collection<String> get() {
params.add("--key-vault-name");
params.add(azureKeyVault);
params.add("--key-name");
params.add("TestKey2");
params.add(AZURE_KEY_NAME);
params.add("--key-version");
params.add("");
params.add("--client-id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.ethsigner.tests.multikeysigner;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.ethsigner.tests.AcceptanceTestBase.AZURE_PUBLIC_KEY;

import java.nio.file.Path;

Expand All @@ -26,23 +27,24 @@ public class AzureBasedTomlLoadingAcceptanceTest extends MultiKeyAcceptanceTestB
static final String clientId = System.getenv("AZURE_CLIENT_ID");
static final String clientSecret = System.getenv("AZURE_CLIENT_SECRET");
static final String tenantId = System.getenv("AZURE_TENANT_ID");
static final String FILENAME = "8c250253147a091cfcb7e9425022bcd03a329ce6";
static final String AZURE_ETHEREUM_ADDRESS = "0x" + FILENAME;
static final String clientKeyVaultName = System.getenv("AZURE_KEY_VAULT_NAME");
static final String AZURE_ETHEREUM_ADDRESS = "0x" + AZURE_PUBLIC_KEY;

@BeforeAll
public static void checkAzureCredentials() {
Assumptions.assumeTrue(
clientId != null && clientSecret != null && tenantId != null,
clientId != null && clientSecret != null && tenantId != null && clientKeyVaultName != null,
"Ensure Azure client id, client secret and tenant_id env variables are set");
}

@Test
void azureSignersAreCreatedAndExpectedAddressIsReported(@TempDir Path tomlDirectory) {
createAzureTomlFileAt(
tomlDirectory.resolve("arbitrary_prefix" + FILENAME + ".toml"),
tomlDirectory.resolve("arbitrary_prefix" + AZURE_PUBLIC_KEY + ".toml"),
clientId,
clientSecret,
tenantId);
tenantId,
clientKeyVaultName);

setup(tomlDirectory);

Expand All @@ -55,7 +57,8 @@ void incorrectlyNamedAzureFileIsNotLoaded(@TempDir Path tomlDirectory) {
tomlDirectory.resolve("ffffffffffffffffffffffffffffffffffffffff.toml"),
clientId,
clientSecret,
tenantId);
tenantId,
clientKeyVaultName);

setup(tomlDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.ethsigner.tests.multikeysigner;

import static org.assertj.core.api.AssertionsForClassTypes.fail;
import static tech.pegasys.ethsigner.tests.dsl.signer.TransactionSignerParamsSupplier.AZURE_KEY_NAME;
import static tech.pegasys.signers.hashicorp.dsl.certificates.CertificateHelpers.createFingerprintFile;

import tech.pegasys.ethsigner.tests.dsl.node.HashicorpSigningParams;
Expand Down Expand Up @@ -57,12 +58,13 @@ public void createAzureTomlFileAt(
final Path tomlPath,
final String clientId,
final String clientSecret,
final String tenantId) {
final String tenantId,
final String clientKeyVaultName) {
final String toml =
new TomlStringBuilder("signing")
.withQuotedString("type", "azure-signer")
.withQuotedString("key-vault-name", "ethsignertestkey")
.withQuotedString("key-name", "TestKey2")
.withQuotedString("key-vault-name", clientKeyVaultName)
.withQuotedString("key-name", AZURE_KEY_NAME)
.withQuotedString("key-version", "")
.withQuotedString("client-id", clientId)
.withQuotedString("client-secret", clientSecret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.ethsigner.tests.multikeysigner;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.ethsigner.tests.AcceptanceTestBase.AZURE_PUBLIC_KEY;
import static tech.pegasys.ethsigner.tests.multikeysigner.AzureBasedTomlLoadingAcceptanceTest.AZURE_ETHEREUM_ADDRESS;
import static tech.pegasys.ethsigner.tests.multikeysigner.FileBasedTomlLoadingAcceptanceTest.FILE_ETHEREUM_ADDRESS;
import static tech.pegasys.ethsigner.tests.multikeysigner.HashicorpBasedTomlLoadingAcceptanceTest.HASHICORP_ETHEREUM_ADDRESS;
Expand Down Expand Up @@ -55,10 +56,11 @@ static void preChecks() {
void multipleSignersAreCreatedAndExpectedAddressAreReported() throws URISyntaxException {

createAzureTomlFileAt(
tempDir.resolve(AzureBasedTomlLoadingAcceptanceTest.FILENAME + ".toml"),
tempDir.resolve(AZURE_PUBLIC_KEY + ".toml"),
AzureBasedTomlLoadingAcceptanceTest.clientId,
AzureBasedTomlLoadingAcceptanceTest.clientSecret,
AzureBasedTomlLoadingAcceptanceTest.tenantId);
AzureBasedTomlLoadingAcceptanceTest.tenantId,
AzureBasedTomlLoadingAcceptanceTest.clientKeyVaultName);
createFileBasedTomlFileAt(
tempDir.resolve(FileBasedTomlLoadingAcceptanceTest.FILENAME + ".toml"),
new File(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
package tech.pegasys.ethsigner.tests.multikeysigner.transactionsigning;

import static tech.pegasys.ethsigner.tests.AcceptanceTestBase.AZURE_GENESIS_ACCOUNT_ONE_PUBLIC_KEY;
import static tech.pegasys.ethsigner.tests.AcceptanceTestBase.AZURE_PUBLIC_KEY;

import java.nio.file.Path;

import org.junit.jupiter.api.Assumptions;
Expand All @@ -25,24 +28,23 @@ public class MultiKeyAzureTransactionSignerAcceptanceTest
static final String clientId = System.getenv("AZURE_CLIENT_ID");
static final String clientSecret = System.getenv("AZURE_CLIENT_SECRET");
static final String tenantId = System.getenv("AZURE_TENANT_ID");
static final String FILENAME = "8c250253147a091cfcb7e9425022bcd03a329ce6";
private static final String AZURE_GENESIS_ACCOUNT_ONE_PUBLIC_KEY =
"0x8c250253147a091cfcb7e9425022bcd03a329ce6";
static final String clientKeyVaultName = System.getenv("AZURE_KEY_VAULT_NAME");

@BeforeAll
public static void checkAzureCredentials() {
Assumptions.assumeTrue(
clientId != null && clientSecret != null && tenantId != null,
clientId != null && clientSecret != null && tenantId != null && clientKeyVaultName != null,
"Ensure Azure client id, client secret and tenant_id env variables are set");
}

@Test
public void azureLoadedFromMultiKeyCanSignValueTransferTransaction(@TempDir Path tomlDirectory) {
createAzureTomlFileAt(
tomlDirectory.resolve("arbitrary_prefix" + FILENAME + ".toml"),
tomlDirectory.resolve("arbitrary_prefix" + AZURE_PUBLIC_KEY + ".toml"),
clientId,
clientSecret,
tenantId);
tenantId,
clientKeyVaultName);

setup(tomlDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.ethsigner.tests.signing;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.ethsigner.tests.AcceptanceTestBase.AZURE_GENESIS_ACCOUNT_ONE_PUBLIC_KEY;
import static tech.pegasys.ethsigner.tests.dsl.Gas.GAS_PRICE;
import static tech.pegasys.ethsigner.tests.dsl.Gas.INTRINSIC_GAS;

Expand All @@ -36,8 +37,6 @@
public class ValueTransferWithAzureAcceptanceTest {

private static final String RECIPIENT = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00";
private static final String AZURE_GENESIS_ACCOUNT_ONE_PUBLIC_KEY =
"0x8c250253147a091cfcb7e9425022bcd03a329ce6";

private static Node ethNode;
private static Signer ethSigner;
Expand All @@ -50,7 +49,8 @@ public static void setUpBase() {
Assumptions.assumeTrue(
System.getenv("AZURE_CLIENT_ID") != null
&& System.getenv("AZURE_CLIENT_SECRET") != null
&& System.getenv("AZURE_TENANT_ID") != null,
&& System.getenv("AZURE_TENANT_ID") != null
&& System.getenv("AZURE_KEY_VAULT_NAME") != null,
"Ensure Azure client id, client secret and tenantId env variables are set");

final BesuNodeConfig besuNodeConfig = BesuNodeConfigBuilder.aBesuNodeConfig().build();
Expand All @@ -59,7 +59,9 @@ public static void setUpBase() {
ethNode.awaitStartupCompletion();

final SignerConfiguration signerConfig =
new SignerConfigurationBuilder().withAzureKeyVault("ethsignertestkey").build();
new SignerConfigurationBuilder()
.withAzureKeyVault(System.getenv("AZURE_KEY_VAULT_NAME"))
.build();

ethSigner = new Signer(signerConfig, besuNodeConfig.getHostName(), ethNode.ports());
ethSigner.start();
Expand Down
4 changes: 4 additions & 0 deletions acceptance-tests/src/test/resources/eth_hash_2018.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"8c250253147a091cfcb7e9425022bcd03a329ce6" : {
"comment": "azure public key",
"balance": "90000000000000000000000"
},
"3d93035f56685fd609415654beccfcaf166ea382" : {
"comment": "azure public key",
"balance": "90000000000000000000000"
}
},
"number": "0x0",
Expand Down

0 comments on commit d2f5443

Please sign in to comment.