Skip to content

Commit

Permalink
Ensure HTTPS enabled when required for internal communication
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jul 19, 2021
1 parent 8b6f0a3 commit 71152be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class InternalCommunicationConfig
private String keyStorePassword;
private String trustStorePath;
private String trustStorePassword;
private boolean httpServerHttpsEnabled;

@NotNull
public Optional<String> getSharedSecret()
Expand Down Expand Up @@ -135,4 +136,22 @@ public boolean isRequiredSharedSecretSet()
{
return !isHttpsRequired() || getSharedSecret().isPresent();
}

public boolean isHttpServerHttpsEnabled()
{
return httpServerHttpsEnabled;
}

@Config("http-server.https.enabled")
public InternalCommunicationConfig setHttpServerHttpsEnabled(boolean httpServerHttpsEnabled)
{
this.httpServerHttpsEnabled = httpServerHttpsEnabled;
return this;
}

@AssertTrue(message = "HTTPS must be enabled when HTTPS is required for internal communications. Set http-server.https.enabled=true")
public boolean isHttpsEnabledWhenRequired()
{
return !isHttpsRequired() || isHttpServerHttpsEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void testDefaults()
.setKeyStorePath(null)
.setKeyStorePassword(null)
.setTrustStorePath(null)
.setTrustStorePassword(null));
.setTrustStorePassword(null)
.setHttpServerHttpsEnabled(false));
}

@Test
Expand All @@ -55,6 +56,7 @@ public void testExplicitPropertyMappings()
.put("internal-communication.https.keystore.key", "key-key")
.put("internal-communication.https.truststore.path", truststoreFile.toString())
.put("internal-communication.https.truststore.key", "trust-key")
.put("http-server.https.enabled", "true")
.build();

InternalCommunicationConfig expected = new InternalCommunicationConfig()
Expand All @@ -64,7 +66,8 @@ public void testExplicitPropertyMappings()
.setKeyStorePath(keystoreFile.toString())
.setKeyStorePassword("key-key")
.setTrustStorePath(truststoreFile.toString())
.setTrustStorePassword("trust-key");
.setTrustStorePassword("trust-key")
.setHttpServerHttpsEnabled(true);

assertFullMapping(properties, expected);
}
Expand Down

0 comments on commit 71152be

Please sign in to comment.