-
Notifications
You must be signed in to change notification settings - Fork 3
Backport to branch(3) : Fix certificate and secret key version check and messages #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,10 +589,12 @@ public void constructor_HmacAuthEnabledButNoSecretKeyGiven_ShouldCreateConfigPro | |
throws IOException { | ||
// Arrange | ||
Properties props = new Properties(); | ||
props.put(ClientConfig.ENTITY_ID, SOME_ENTITY_ID); | ||
props.put(ClientConfig.CERT_VERSION, "0"); | ||
props.put(ClientConfig.CERT_HOLDER_ID, SOME_CERT_HOLDER_ID); | ||
props.put(ClientConfig.CERT_PEM, SOME_CERT_PEM); | ||
props.put(ClientConfig.PRIVATE_KEY_PEM, SOME_PRIVATE_KEY_PEM); | ||
props.put(ClientConfig.ENTITY_ID, SOME_ENTITY_ID); | ||
props.put(ClientConfig.DS_CERT_VERSION, SOME_CERT_VERSION); | ||
props.put(ClientConfig.DS_CERT_PEM, SOME_CERT_PEM + "New"); | ||
props.put(ClientConfig.DS_PRIVATE_KEY_PEM, SOME_PRIVATE_KEY_PEM + "New"); | ||
|
||
|
@@ -601,6 +603,8 @@ public void constructor_HmacAuthEnabledButNoSecretKeyGiven_ShouldCreateConfigPro | |
|
||
// Assert | ||
assertThat(config.getDigitalSignatureIdentityConfig().getEntityId()).isEqualTo(SOME_ENTITY_ID); | ||
assertThat(config.getDigitalSignatureIdentityConfig().getCertVersion()) | ||
.isEqualTo(Integer.parseInt(SOME_CERT_VERSION)); | ||
assertThat(config.getDigitalSignatureIdentityConfig().getCert()) | ||
.isEqualTo(SOME_CERT_PEM + "New"); | ||
assertThat(config.getDigitalSignatureIdentityConfig().getPrivateKey()) | ||
|
@@ -740,4 +744,59 @@ public void constructor_DifferentClientConfigGiven_ShouldReturnNonEqualConfigs() | |
assertThat(config1.getLedgerTargetConfig()).isNotEqualTo(config2.getLedgerTargetConfig()); | ||
assertThat(config1.getAuditorTargetConfig()).isNotEqualTo(config2.getAuditorTargetConfig()); | ||
} | ||
|
||
@Test | ||
public void constructor_CertVersionZeroGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
Properties props = new Properties(); | ||
props.put(ClientConfig.ENTITY_ID, SOME_CERT_HOLDER_ID); | ||
props.put(ClientConfig.DS_CERT_VERSION, "0"); | ||
props.put(ClientConfig.DS_CERT_PEM, SOME_CERT_PEM); | ||
props.put(ClientConfig.DS_PRIVATE_KEY_PEM, SOME_PRIVATE_KEY_PEM); | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> new ClientConfig(props)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
public void constructor_DeprecatedCertVersionZeroGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
Properties props = new Properties(); | ||
props.put(ClientConfig.CERT_HOLDER_ID, SOME_CERT_HOLDER_ID); | ||
props.put(ClientConfig.CERT_VERSION, "0"); | ||
props.put(ClientConfig.CERT_PEM, SOME_CERT_PEM); | ||
props.put(ClientConfig.PRIVATE_KEY_PEM, SOME_PRIVATE_KEY_PEM); | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> new ClientConfig(props)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
public void | ||
constructor_NewWrongCertVersionAndDeprecatedCorrectCertVersionGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
Properties props = new Properties(); | ||
props.put(ClientConfig.ENTITY_ID, SOME_CERT_HOLDER_ID); | ||
props.put(ClientConfig.DS_CERT_VERSION, "0"); | ||
props.put(ClientConfig.DS_CERT_PEM, SOME_CERT_PEM); | ||
props.put(ClientConfig.DS_PRIVATE_KEY_PEM, SOME_PRIVATE_KEY_PEM); | ||
props.put(ClientConfig.CERT_HOLDER_ID, SOME_CERT_HOLDER_ID); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is redundant. |
||
props.put(ClientConfig.CERT_VERSION, SOME_CERT_VERSION); | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> new ClientConfig(props)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
public void constructor_SecretVersionZeroGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
Properties props = new Properties(); | ||
props.put(ClientConfig.ENTITY_ID, SOME_ENTITY_ID); | ||
props.put(ClientConfig.AUTHENTICATION_METHOD, AuthenticationMethod.HMAC.getMethod()); | ||
props.put(ClientConfig.HMAC_SECRET_KEY, SOME_SECRET_KEY); | ||
props.put(ClientConfig.HMAC_SECRET_KEY_VERSION, "0"); | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> new ClientConfig(props)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property
ClientConfig.CERT_HOLDER_ID
is redundant here becauseClientConfig.ENTITY_ID
is set on line 596. The configuration loading logic gives precedence toENTITY_ID
, soCERT_HOLDER_ID
will be ignored for determining the entity ID. Removing this line will make the test cleaner.