Skip to content

Commit

Permalink
Use SignerType enum instead of string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-iov committed Aug 22, 2024
1 parent 662dc53 commit 72c4d7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import co.rsk.federate.signing.config.SignerType;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -303,7 +304,7 @@ void signerConfig_whenSignerConfigExists_shouldReturnSignerConfig() {
when(mockSignersConfig.getObject(existingKey)).thenReturn(mockConfigSignerObject);
when(mockConfigSignerObject.toConfig()).thenReturn(mockSignerConfig);
when(mockSignerConfig.hasPath("type")).thenReturn(true);
when(mockSignerConfig.getString("type")).thenReturn("hsm");
when(mockSignerConfig.getString("type")).thenReturn(SignerType.HSM.getType());

SignerConfig result = powpegNodeSystemProperties.signerConfig(existingKey);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/co/rsk/federate/config/SignerConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.typesafe.config.ConfigValueFactory.fromAnyRef;

import co.rsk.federate.signing.config.SignerType;
import java.math.BigInteger;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
Expand All @@ -25,7 +26,7 @@ public SignerConfigBuilder withValue(String path, Object value) {
}

public SignerConfigBuilder withHsmSigner(String keyId) {
this.config = this.config.withValue("type", fromAnyRef("hsm"));
this.config = this.config.withValue("type", fromAnyRef(SignerType.HSM.getType()));
this.config = this.config.withValue("host", fromAnyRef("127.0.0.1"));
this.config = this.config.withValue("port", fromAnyRef(9999));
this.config = this.config.withValue("keyId", fromAnyRef(keyId));
Expand All @@ -48,7 +49,7 @@ public SignerConfigBuilder withHsmBookkeepingInfo(BigInteger difficultyTarget, l
}

public SignerConfigBuilder withKeyFileSigner(String path) {
this.config = this.config.withValue("type", fromAnyRef("keyFile"));
this.config = this.config.withValue("type", fromAnyRef(SignerType.KEYFILE.getType()));
this.config = this.config.withValue("path", fromAnyRef(path));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import co.rsk.federate.signing.config.SignerConfig;
import co.rsk.federate.rpc.JsonRpcClientProvider;
import co.rsk.federate.rpc.SocketBasedJsonRpcClientProvider;
import co.rsk.federate.signing.config.SignerType;
import co.rsk.federate.signing.hsm.SignerException;
import co.rsk.federate.signing.hsm.client.HSMClientProtocol;
import co.rsk.federate.signing.hsm.client.HSMSigningClientProvider;
Expand All @@ -49,7 +50,7 @@ void createFactory() {

@Test
void buildFromConfigKeyFile() throws SignerException {
Config configMock = mockConfig("keyFile");
Config configMock = mockConfig(SignerType.KEYFILE.getType());
when(configMock.getString("path")).thenReturn("a-random-path");
SignerConfig signerConfig = new SignerConfig("a-random-id", configMock);
ECDSASigner signer = factory.buildFromConfig(signerConfig);
Expand All @@ -61,7 +62,7 @@ void buildFromConfigKeyFile() throws SignerException {

@Test
void buildFromConfigHSM() throws SignerException {
Config configMock = mockConfig("hsm");
Config configMock = mockConfig(SignerType.HSM.getType());
when(configMock.hasPath("host")).thenReturn(true);
when(configMock.getString("host")).thenReturn("remotehost");
when(configMock.hasPath("port")).thenReturn(true);
Expand Down

0 comments on commit 72c4d7f

Please sign in to comment.