Skip to content

Commit

Permalink
Fix and add AT
Browse files Browse the repository at this point in the history
  • Loading branch information
usmansaleem committed Jan 14, 2025
1 parent 98946d8 commit dc13031
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SignerConfiguration {

private final boolean signingExtEnabled;
private Optional<Pair<Path, Path>> commitBoostParameters;
private final Optional<Boolean> reloadKeepStaleKeys;

public SignerConfiguration(
final String hostname,
Expand Down Expand Up @@ -131,7 +132,8 @@ public SignerConfiguration(
final ChainIdProvider chainIdProvider,
final Optional<KeystoresParameters> v3KeystoresBulkloadParameters,
final boolean signingExtEnabled,
final Optional<Pair<Path, Path>> commitBoostParameters) {
final Optional<Pair<Path, Path>> commitBoostParameters,
final Optional<Boolean> reloadKeepStaleKeys) {
this.hostname = hostname;
this.logLevel = logLevel;
this.httpRpcPort = httpRpcPort;
Expand Down Expand Up @@ -179,6 +181,7 @@ public SignerConfiguration(
this.v3KeystoresBulkloadParameters = v3KeystoresBulkloadParameters;
this.signingExtEnabled = signingExtEnabled;
this.commitBoostParameters = commitBoostParameters;
this.reloadKeepStaleKeys = reloadKeepStaleKeys;
}

public String hostname() {
Expand Down Expand Up @@ -376,4 +379,8 @@ public boolean isSigningExtEnabled() {
public Optional<Pair<Path, Path>> getCommitBoostParameters() {
return commitBoostParameters;
}

public Optional<Boolean> getReloadKeepStaleKeys() {
return reloadKeepStaleKeys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class SignerConfigurationBuilder {

private boolean signingExtEnabled;
private Pair<Path, Path> commitBoostParameters;
private Optional<Boolean> reloadKeepStaleKeys = Optional.empty();

public SignerConfigurationBuilder withLogLevel(final Level logLevel) {
this.logLevel = logLevel;
Expand Down Expand Up @@ -339,6 +340,11 @@ public SignerConfigurationBuilder withCommitBoostParameters(
return this;
}

public SignerConfigurationBuilder withReloadKeepStaleKeys(final boolean reloadKeepStaleKeys) {
this.reloadKeepStaleKeys = Optional.of(reloadKeepStaleKeys);
return this;
}

public SignerConfiguration build() {
if (mode == null) {
throw new IllegalArgumentException("Mode cannot be null");
Expand Down Expand Up @@ -390,6 +396,7 @@ public SignerConfiguration build() {
chainIdProvider,
Optional.ofNullable(v3KeystoresBulkloadParameters),
signingExtEnabled,
Optional.ofNullable(commitBoostParameters));
Optional.ofNullable(commitBoostParameters),
reloadKeepStaleKeys);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public List<String> createCmdLineParams() {

yamlConfig.append(createServerTlsArgs());

signerConfig
.getReloadKeepStaleKeys()
.ifPresent(
reloadKeepStaleKeys ->
yamlConfig.append(
String.format(
YAML_BOOLEAN_FMT, "reload-keep-stale-keys", reloadKeepStaleKeys)));

params.add(signerConfig.getMode()); // sub-command .. it can't go to config file

if (signerConfig.getMode().equals("eth2")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public List<String> createCmdLineParams() {

params.addAll(createServerTlsArgs());

signerConfig
.getReloadKeepStaleKeys()
.ifPresent(
reloadKeepStaleKeys -> params.add("--reload-keep-stale-keys=" + reloadKeepStaleKeys));

params.add(signerConfig.getMode());

if (signerConfig.getMode().equals("eth2")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void healthCheckReportsKeysLoadedAfterReloadInEth2Mode() {

@ParameterizedTest
@EnumSource(value = KeyType.class)
public void removedConfigFilePublicKeyIsRemovedAfterReload(final KeyType keyType) {
public void publicKeysAreRemovedAfterReloadDefault(final KeyType keyType) {
final String[] prvKeys = privateKeys(keyType);
final String[] keys = createKeys(keyType, true, prvKeys);

Expand All @@ -161,7 +161,36 @@ public void removedConfigFilePublicKeyIsRemovedAfterReload(final KeyType keyType
// reload API call
signer.callReload().then().statusCode(200);

validateApiResponse(signer.callApiPublicKeys(keyType), contains(keys[0]));
// reload is async ... assert that the key is removed
Awaitility.await()
.atMost(5, SECONDS)
.until(
() -> signer.callApiPublicKeys(keyType).jsonPath().<List<String>>get("."),
containsInAnyOrder(keys[0]));
}

@ParameterizedTest
@EnumSource(value = KeyType.class)
public void publicKeysNotRemovedAfterReloadWithKeepStaleKeysTrue(final KeyType keyType) {
final String[] prvKeys = privateKeys(keyType);
final String[] keys = createKeys(keyType, true, prvKeys);

initAndStartSignerWithReloadKeepStaleKeys(calculateMode(keyType));

validateApiResponse(signer.callApiPublicKeys(keyType), containsInAnyOrder(keys));

// remove one of the key config file
assertThat(testDirectory.resolve(keys[1] + ".yaml").toFile().delete()).isTrue();

// reload API call
signer.callReload().then().statusCode(200);

// reload is async ... assert that the keys are not removed
Awaitility.await()
.atMost(5, SECONDS)
.until(
() -> signer.callApiPublicKeys(keyType).jsonPath().<List<String>>get("."),
containsInAnyOrder(keys));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ protected void initAndStartSigner(final String mode) {
startSigner(builder.build());
}

protected void initAndStartSignerWithReloadKeepStaleKeys(final String mode) {
startSigner(
new SignerConfigurationBuilder()
.withKeyStoreDirectory(testDirectory)
.withMode(mode)
.withReloadKeepStaleKeys(true)
.build());
}

protected Response callApiPublicKeysWithoutOpenApiClientSideFilter(final KeyType keyType) {
return given().baseUri(signer.getUrl()).accept("").get(Signer.publicKeysPath(keyType));
}
Expand Down

0 comments on commit dc13031

Please sign in to comment.