1414
1515import io .specto .hoverfly .junit .core .Hoverfly ;
1616import io .specto .hoverfly .junit .core .HoverflyConfig ;
17- import org .slf4j .Logger ;
18- import org .slf4j .LoggerFactory ;
19-
2017import java .net .InetSocketAddress ;
2118import java .util .Arrays ;
2219import java .util .LinkedList ;
2320import java .util .List ;
21+ import org .slf4j .Logger ;
22+ import org .slf4j .LoggerFactory ;
2423
2524/**
2625 * Config builder interface for settings specific to {@link Hoverfly} managed internally
@@ -40,6 +39,7 @@ public class LocalHoverflyConfig extends HoverflyConfig {
4039 private String clientCertPath ;
4140 private String clientKeyPath ;
4241 private String clientAuthDestination ;
42+ private String clientCaCertPath ;
4343
4444 /**
4545 * Sets the certificate file to override the default Hoverfly's CA cert
@@ -177,14 +177,26 @@ public HoverflyConfig binaryLocation(String binaryLocation) {
177177 public LocalHoverflyConfig clientAuth (String clientCertPath , String clientKeyPath , String ... destinations ) {
178178 this .clientCertPath = clientCertPath ;
179179 this .clientKeyPath = clientKeyPath ;
180- if (destinations .length == 0 ) {
181- this .clientAuthDestination = "." ;
182- } else {
183- this .clientAuthDestination = String .join ("|" , destinations );
180+ if (destinations != null ) {
181+ if (destinations .length == 0 ) {
182+ this .clientAuthDestination = "." ;
183+ } else {
184+ this .clientAuthDestination = String .join ("|" , destinations );
185+ }
184186 }
185187 return this ;
186188 }
187189
190+ /**
191+ * Set client CA certificate for mutual TLS authentication
192+ * @param clientCaCertPath CA certificate file in classpath. Must be any PEM encoded certificate, with .crt or .pem extensions
193+ * @return the {@link LocalHoverflyConfig} for further customizations
194+ */
195+ public LocalHoverflyConfig clientAuthCaCertPath (String clientCaCertPath ) {
196+ this .clientCaCertPath = clientCaCertPath ;
197+ return this ;
198+ }
199+
188200 @ Override
189201 public HoverflyConfiguration build () {
190202 HoverflyConfiguration configs = new HoverflyConfiguration (proxyPort , adminPort , proxyLocalHost , destination ,
@@ -200,6 +212,7 @@ public HoverflyConfiguration build() {
200212 configs .setClientCertPath (clientCertPath );
201213 configs .setClientKeyPath (clientKeyPath );
202214 configs .setClientAuthDestination (clientAuthDestination );
215+ configs .setClientCaCertPath (clientCaCertPath );
203216 HoverflyConfigValidator validator = new HoverflyConfigValidator ();
204217 return validator .validate (configs );
205218 }
0 commit comments